import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.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/cm_module/service_request_detail_provider.dart';
import 'package:test_sa/modules/cm_module/views/forms/asset_retired/verify_asset_detail.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';
import 'package:test_sa/extensions/string_extensions.dart';

class AssetDetailCard extends StatelessWidget {
  const AssetDetailCard({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Consumer<ServiceRequestDetailProvider>(builder: (context, ServiceRequestDetailProvider requestDetailProvider, snapshot) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
            Row(
              children: [
                StatusLabel(
                  label: requestDetailProvider.engineerUpdateWorkOrderHelperModel?.equipmentStatus?.name,
                  id: requestDetailProvider.engineerUpdateWorkOrderHelperModel!.equipmentStatus!.id ?? 0,
                  radius: 4,
                  textColor: AppColor.white10,
                  backgroundColor: AppColor.getEquipmentStatusColor(context, requestDetailProvider.engineerUpdateWorkOrderHelperModel!.equipmentStatus!.id ?? 0),
                ),
                if (requestDetailProvider.engineerUpdateWorkOrderHelperModel?.cmFrameId != null) ...[
                  6.width,
                  StatusLabel(
                    label: requestDetailProvider.engineerUpdateWorkOrderHelperModel?.cmFrameId?.name,
                    id: requestDetailProvider.engineerUpdateWorkOrderHelperModel?.cmFrameId?.id ?? 0,
                    radius: 4,
                    textColor: AppColor.getActivityTypeTextColor(requestDetailProvider.engineerUpdateWorkOrderHelperModel!.cmFrameId?.name ?? ''),
                    backgroundColor: AppColor.getActivityTypeBgColor(requestDetailProvider.engineerUpdateWorkOrderHelperModel!.cmFrameId?.name ?? ''),
                  ),
                ],
                6.width,
                StatusLabel(
                  label: requestDetailProvider.engineerUpdateWorkOrderHelperModel?.serviceType?.name,
                  id: requestDetailProvider.engineerUpdateWorkOrderHelperModel?.serviceType?.id ?? 0,
                  radius: 4,
                  textColor: AppColor.getActivityTypeTextColor(requestDetailProvider.engineerUpdateWorkOrderHelperModel!.serviceType?.name ?? ''),
                  backgroundColor: AppColor.getActivityTypeBgColor(requestDetailProvider.engineerUpdateWorkOrderHelperModel!.serviceType?.name ?? ''),
                ),
              ],
            ),
            //hide if status is closed or complete .
            if (!requestDetailProvider.isReadOnlyRequest)
              "edit_icon".toSvgAsset(height: 21, width: 21, color: context.isDark ? AppColor.primary10 : null).onPress(() async {
                requestDetailProvider.refreshTimer = false;
                await Navigator.push(context, MaterialPageRoute(builder: (context) => VerifyAssetDetails(isEdit: true)));
                requestDetailProvider.refreshTimer = true;
              }),
          ]),
          6.height,
          Text(
            "Work Order Details",
            style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
          ),
          Text(
            '${context.translation.returnToService}:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.returnToService?.toAssetDetailsFormat ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            'EDD:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.edd?.toAssetDetailsFormat ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            '${context.translation.loanAvailability}:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.loanAvailability?.name ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            '${context.translation.failureReason}:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.failureReason?.name ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            '${context.translation.faultDescription}:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.faultDescription?.name ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          Text(
            '${context.translation.solutions}:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.solution ?? '-'}',
            style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
          ),
          if (Provider.of<SettingProvider>(context, listen: false).isUserFMS) ...[
            Text(
              'Description of Finding:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.descriptionOfFinding ?? '-'}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
            ),
            Text(
              'Action Taken:  ${requestDetailProvider.engineerUpdateWorkOrderHelperModel?.actionTaken ?? '-'}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
            ),
          ]
        ],
      ).toShadowContainer(
        context,
      );
    });
  }
}
