import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/common/const/const.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';
import 'package:taafee_mobile/common/widgets/text.dart';
import 'package:taafee_mobile/features/card/data_layer/model/card_model.dart';
import 'package:taafee_mobile/features/card/presentation_layer/widgets/card_location.dart';
import 'package:taafee_mobile/features/home/business_logic_layer/home_controller.dart';

import '../../../../core/routing/routing_manager.dart';
import 'card_header.dart';

class FirstCardWidget extends StatelessWidget {
  final CardModel cardModel;
  final HomeController homeController = Get.find<HomeController>();
  FirstCardWidget(this.cardModel, {super.key});
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(
          horizontal: Responsive.isTablet() ? 2 : 20, vertical: 10),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(4),
      ),
      width: Get.width,
      height: 195,
      child: Column(
        children: [
          Column(
            children: [
              CardHeaderWidget(
                cardModel: cardModel,
              ),
              Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(4),
                ),
                width: Get.width,
                height: 160,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      margin: const EdgeInsets.symmetric(vertical: 10),
                      width: Get.width * .8,
                      height: 90,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8),
                        image: cardModel.cardImages.isNotEmpty
                            ? DecorationImage(
                                image: CachedNetworkImageProvider(
                                  Domain.domain +
                                      cardModel.cardImages[0].url.substring(6),
                                ),
                                fit: BoxFit.cover)
                            : null,
                      ),
                    ).center(),
                    Row(
                      children: [
                        SvgPicture.asset(
                          "assets/icons/love-svgrepo-com 2.svg",
                        ),
                        MediumTextWidget("${cardModel.user.firstName}"
                            " ${cardModel.user.lastName}"),
                      ],
                    ).paddingSymmetric(horizontal: 14),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        CardLocationWidget(
                          cardModel: cardModel,
                        ).paddingSymmetric(
                          horizontal: 10,
                        ),
                        Row(
                          children: [
                            SvgPicture.asset("assets/icons/phone.svg"),
                            RegularTextWidget(" ${cardModel.phoneNumber}"),
                          ],
                        ).paddingSymmetric(horizontal: 18),
                      ],
                    ),
                    // const CardInformation(),
                    // const CardLocationWidget(),
                    // Divider(
                    //   color: AppColors.dividerColor,
                    //   thickness: 1,
                    // ).paddingSymmetric(horizontal: 18),
                    // const CardServiceWidget(),
                  ],
                ),
              ),
            ],
          ).onTap(() {
            homeController.setCardAppointment(cardModel.id);
            RoutingManager.to(RouteName.cardDetails, arguments: cardModel);
          }),
        ],
      ),
    );
  }
}
