import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/service_request_latest/service_request_detail_provider.dart';
import 'package:test_sa/service_request_latest/views/forms/asset_retired/verify_asset_detail.dart';
import 'package:test_sa/views/widgets/requests/request_status.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 Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(14),
          color: AppColor.white10,
        ),
        padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 14.toScreenHeight),
        margin: EdgeInsets.only(top: 10.toScreenHeight),
        child: 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),
                  ),
                  5.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).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(
              '${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),
            ),
          ],
        ),
      );
    });
  }
}
