import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import 'package:get/get.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';
import 'package:taafee_mobile/features/auth/business_logic_layer/auth_controller.dart';
import 'package:taafee_mobile/features/card/data_layer/model/card_model.dart';
import 'package:taafee_mobile/features/home/business_logic_layer/home_controller.dart';

import '../../../../common/const/const.dart';
import '../../../../common/widgets/text.dart';
import '../../../../core/routing/routing_manager.dart';
import 'favorite.dart';

class CardHeaderWidget extends StatelessWidget {
  final CardModel cardModel;
  final double? width;
  final bool isShowEditIcon;
  final bool isFavoriteCardWidget;
  final bool isFromDetailsScreen;
  final HomeController homeController = Get.find<HomeController>();
  final AuthController authController = Get.find<AuthController>();

  CardHeaderWidget(
      {super.key,
      this.width,
      this.isShowEditIcon = false,
      this.isFromDetailsScreen = false,
      this.isFavoriteCardWidget = false,
      required this.cardModel});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: AppColors.primeColor,
        borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(4),
          topRight: Radius.circular(4),
        ),
      ),
      width: Get.width,
      height: 35,
      child: SizedBox(
        width: (isFavoriteCardWidget)
            ? (Responsive.isTablet() ? (Get.width * 0.2) : Get.width * 0.35)
            : null,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            SizedBox(
              width: (isFavoriteCardWidget)
                  ? (Responsive.isTablet()
                      ? (Get.width * 0.2)
                      : Get.width * 0.24)
                  : null,
              child: BoldTextWidget(
                cardModel.name,
                fontSize: 12,
                color: Colors.white,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            Row(
              children: [
                FavoriteWidget(
                  cardModel: cardModel,
                  isFavoriteCardWidget: isFavoriteCardWidget,
                  isFromDetailsScreen: isFromDetailsScreen,
                ),
                const SizedBox(
                  width: 8.5,
                ),
                if (homeController.user.value!.email == cardModel.user.email)
                  SizedBox(
                      width: 18,
                      height: 18,
                      child: SvgPicture.asset(
                        "assets/icons/edit.svg",
                        colorFilter: const ColorFilter.mode(
                            Colors.white, BlendMode.srcIn),
                      )).onTap(() {
                    RoutingManager.to(RouteName.addCard, arguments: cardModel);
                  }),
              ],
            ),
          ],
        ).paddingSymmetric(horizontal: 12),
      ),
    );
  }
}
