import 'package:flutter/material.dart';
import 'package:food_health/api/dto/food_scan_dto.dart';
import 'package:food_health/config/theme/custom_colors.dart';
import 'package:remixicon/remixicon.dart';

class ResultChip extends StatelessWidget {
  final FoodScanDto detail;

  const ResultChip({super.key, required this.detail});

  @override
  Widget build(BuildContext context) {
    Color currentColor = Colors.transparent; //设置主体颜色
    IconData iconData = Icons.check; //图标
    String title = "";
    String desc = "";

    if (detail.foodType == 1) {
      currentColor = Theme.of(context).colorScheme.success;
      iconData = RemixIcons.shield_check_line;
      title = "Safe to Eat";
      desc = "This food appears safe for your health profile";
    } else if (detail.foodType == 2) {
      currentColor = Theme.of(context).colorScheme.warning;
      iconData = RemixIcons.error_warning_fill;
      title = "Proceed with Caution";
      desc = "This food may have some concerns for your health profile";
    } else if (detail.foodType == 3) {
      currentColor = Theme.of(context).colorScheme.danger;
      iconData = RemixIcons.close_circle_line;
      title = "Avoid This Food";
      desc = "This food is not recommended for your health profile";
    }
    return Container(
      padding: EdgeInsets.all(15),
      decoration: BoxDecoration(
        color: currentColor.withValues(alpha: 0.1),
        borderRadius: BorderRadius.circular(10),
        border: Border.all(color: currentColor, width: 1),
      ),
      child: Column(
        spacing: 20,
        children: [
          Container(
            width: 70,
            height: 70,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: currentColor,
            ),
            child: Icon(
              iconData,
              color: Colors.white,
            ),
          ),
          Text(
            title,
            style: Theme.of(context).textTheme.titleLarge,
            textAlign: TextAlign.center,
          ),
          Text(
            desc,
            style: TextStyle(color: currentColor, fontSize: 14),
            textAlign: TextAlign.center,
          ),
          SizedBox(
            width: 150,
            height: 150,
            child: Image.network(
              detail.imageUrl!,
              fit: BoxFit.cover,
              errorBuilder: (context, error, stackTrace) {
                return Container(
                  decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceContainer),
                  child: Icon(RemixIcons.error_warning_fill),
                );
              },
            ),
          ),
          Text(
            detail.foodName ?? "",
            style: Theme.of(context).textTheme.titleSmall,
            textAlign: TextAlign.center,
          ),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 20),
            child: Text(
              detail.foodDesc ?? "",
              textAlign: TextAlign.center,
            ),
          ),
        ],
      ),
    );
  }
}
