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/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_header.dart';
import 'package:taafee_mobile/features/home/business_logic_layer/home_controller.dart';

import '../../../../common/const/const.dart';
import '../../../../core/routing/routing_manager.dart';

class SecondCardWidget extends StatelessWidget {
  final CardModel cardModel;
  final HomeController homeController = Get.find<HomeController>();
  SecondCardWidget(this.cardModel, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(
          horizontal: Responsive.isTablet() ? 2 : 20, vertical: 10),
      width: Get.width,
      height: 140,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(4),
        color: Colors.white,
      ),
      child: SizedBox(
        height: 120,
        child: Column(
          children: [
            CardHeaderWidget(
              cardModel: cardModel,
            ).paddingOnly(bottom: 5),
            Row(
              children: [
                Container(
                  height: 95,
                  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,
                  ),
                ).expanded(5),
                SizedBox(
                  height: 75,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          SvgPicture.asset(
                                  "assets/icons/love-svgrepo-com 2.svg")
                              .paddingOnly(left: 2, right: 5),
                          MediumTextWidget("${cardModel.user.firstName}"
                              " ${cardModel.user.lastName}")
                        ],
                      ),
                      Row(
                        children: [
                          SvgPicture.asset("assets/icons/phone.svg")
                              .paddingSymmetric(horizontal: 5),
                          SizedBox(
                            width: Responsive.isTablet()
                                ? Get.width * 0.14
                                : Get.width * 0.25,
                            child: MediumTextWidget(
                              cardModel.phoneNumber,
                              overflow: TextOverflow.ellipsis,
                            ),
                          )
                        ],
                      ),
                      Row(
                        children: [
                          SvgPicture.asset("assets/icons/location.svg")
                              .paddingSymmetric(horizontal: 5),
                          MediumTextWidget(cardModel.cityModel.name)
                        ],
                      ),
                    ],
                  ).paddingSymmetric(horizontal: 10),
                ).expanded(5)
              ],
            ).paddingSymmetric(horizontal: 5),
          ],
        ).onTap(() {
          homeController.setCardAppointment(cardModel.id);
          RoutingManager.to(RouteName.cardDetails, arguments: cardModel);
        }),
      ),
    );
  }
}
