import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/modules/asset_delivery_module/models/end_user_asset_details_model.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';

class EndUserAssetDetailCard extends StatelessWidget {
  EndUserAssetDetailsModel assetModel;
  bool isViewOnly;
  VoidCallback? editPress;

  EndUserAssetDetailCard({
    super.key,
    required this.isViewOnly,
    required this.assetModel,
    this.editPress,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            assetModel.status != null
                ? StatusLabel(
                    label: assetModel.status?.name,
                    radius: 4,
                    textColor: getAssetStatusColor(context: context, status: assetModel.status?.name ?? '', isBackground: false),
                    backgroundColor: getAssetStatusColor(context: context, status: assetModel.status?.name ?? ''),
                  )
                : const SizedBox(),
            if (!isViewOnly)
              'edit_icon'.toSvgAsset().onPress(() {
                if (editPress != null) {
                  editPress!();
                }
              }),
          ],
        ),
        8.height,
        if (assetModel.type == 'Accessory') ...[
          Text(
            'Type: ${assetModel.type ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Item Number: ${assetModel.itemNumber ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Received Quantity: ${assetModel.receivedQty ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Rejection Reason: ${assetModel.rejectionReason?.name ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Rejected Quantity: ${assetModel.rejectedQty ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Description: ${assetModel.description ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
        ] else ...[
          Text(
            'Type: ${assetModel.type ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Item Number: ${assetModel.itemNumber ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Asset Number: ${assetModel.assetNumber ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Serial No: ${assetModel.serialNo ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'Replaced Asset No: ${assetModel.replacedAssetNo ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          //TODO Need to confirm with @Ahmed need to hide this or not
          if (assetModel.status?.value == 2)
            Text(
              'Rejection Reason: ${assetModel.rejectionReason?.name ?? '-'}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
            ),
          Text(
            'Description: ${assetModel.description ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
        ],
      ],
    ).toShadowContainer(context, borderRadius: 20, padding: 12);
  }

  Color getAssetStatusColor({required BuildContext context, required String status, bool? isBackground = true}) {
    switch (status) {
      case 'Accept':
        return isBackground! ? AppColor.green70.withOpacity(0.4) : AppColor.green15;
      case 'Reject':
        return isBackground! ? AppColor.red30.withOpacity(0.4) : AppColor.red30;
      default:
        return Colors.blueGrey;
    }
  }
}
