import 'dart:developer';

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/string_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/all_requests_and_count_model.dart';
import 'package:test_sa/models/new_models/dashboard_detail.dart';
import 'package:test_sa/modules/medical_gas_inspection/medical_gas_inspection_detail_page.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/widgets/item_views/info_date_widget.dart';
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';

class MedicalGasInspectionItemView extends StatelessWidget {
  final Data? requestData;
  final RequestsDetails? requestDetails;
  final bool showShadow;

  const MedicalGasInspectionItemView({Key? key, this.requestData, this.requestDetails, this.showShadow = true}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (requestData != null) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              if (requestData!.priorityName != null) ...[
                StatusLabel(
                  label: requestData!.priorityName!,
                  textColor: AppColor.getRequestStatusTextColorByName(context, requestData!.priorityName!),
                  backgroundColor: AppColor.getRequestStatusColorByName(context, requestData!.priorityName!),
                ),
                8.width,
              ],
              StatusLabel(
                label: requestData!.statusName!,
                textColor: AppColor.getHistoryLogStatusTextColorByName(context, requestData!.statusName!),
                backgroundColor: AppColor.getHistoryLogStatusColorByName(context, requestData!.statusName!),
              ),
              1.width.expanded,
              InfoDateWidget(requestData!.transactionDate ?? ""),
            ],
          ),
          InfoHeaderWidget(requestData?.typeTransaction ?? 'Medical Gas Request'),
          InfoTextWidget(label: 'Request Number'.addTranslation, value: requestData?.requestNo ?? '-'),
          InfoTextWidget(label: 'Request Type'.addTranslation, value: requestData?.requestType ?? '-', showArrow: true),
          // infoWidget(label: 'Site'.addTranslation, value: requestData?.si ?? '-', context: context),
          // infoWidget(label: 'Gas Type'.addTranslation, value: requestDetails?.gasType ?? '-', context: context),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (_) => MedicalGasInspectionDetailPage(
                  inspectionId: requestData!.id!,
                  prority: requestData?.priorityName,
                )));
      });
    }
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      spacing: 1,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            if (requestDetails!.priority != null) ...[
              StatusLabel(
                label: requestDetails!.priority!,
                textColor: AppColor.getRequestStatusTextColorByName(context, requestDetails!.priority!),
                backgroundColor: AppColor.getRequestStatusColorByName(context, requestDetails!.priority!),
              ),
              8.width,
            ],
            StatusLabel(
              label: requestDetails!.status!,
              textColor: AppColor.getHistoryLogStatusTextColorByName(context, requestDetails!.status!),
              backgroundColor: AppColor.getHistoryLogStatusColorByName(context, requestDetails!.status!),
            ),
            1.width.expanded,
            InfoDateWidget(requestDetails!.date ?? ""),
          ],
        ),
        InfoHeaderWidget(requestDetails?.nameOfType ?? 'Medical Gas Request'),
        InfoTextWidget(label: 'Request Number'.addTranslation, value: requestDetails?.requestNo ?? '-'),
        InfoTextWidget(label: 'Request Type'.addTranslation, value: requestDetails?.requestType ?? '-'),
        InfoTextWidget(label: 'Site'.addTranslation, value: requestDetails?.site ?? '-', showArrow: true),
      ],
    ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
      Navigator.of(context).push(MaterialPageRoute(
          builder: (_) => MedicalGasInspectionDetailPage(
                inspectionId: requestDetails!.id!,
                prority: requestDetails?.priority,
              )));
    });
  }
}
