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/text_extensions.dart';
import 'package:test_sa/extensions/text_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/device/device_transfer.dart';
import 'package:test_sa/models/new_models/dashboard_detail.dart';
import 'package:test_sa/modules/tm_module/device_transfer/device_transfer_details.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 '../../../../views/widgets/requests/request_status.dart';
import '../../../app_style/app_color.dart';

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

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

  @override
  Widget build(BuildContext context) {
    if (requestData != null) {
      return Column(
        // mainAxisAlignment: MainAxisAlignment.spaceBetween,
        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,
              if (requestData?.statusName != null)
                StatusLabel(
                  label: requestData?.statusName ?? "",
                  textColor: AppColor.getRequestStatusTextColorByName(context, requestData?.statusName),
                  backgroundColor: AppColor.getRequestStatusColorByName(context, requestData?.statusName),
                ),
              1.width.expanded,
              InfoDateWidget(requestData!.transactionDate ?? ""),
            ],
          ),
          InfoHeaderWidget(requestData?.typeTransaction ?? context.translation.deviceTransferRequest),
          // "${context.translation.from} : ${request.siteTransferFrom?.cleanupWhitespace.capitalizeFirstOfEach}".bodyText(context), // todo ask ahmed
          // "${context.translation.to} : ${request.siteTransferTo?.cleanupWhitespace.capitalizeFirstOfEach}".bodyText(context),// todo ask ahmed
          // requestData!.statusName!.replaceAll("=", ":").bodyText(context),
          InfoTextWidget(label: context.translation.requestNo, value: requestData!.requestNo, showArrow: true),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        Navigator.of(context).push(MaterialPageRoute(builder: (_) => DeviceTransferDetails(model: DeviceTransfer(id: requestData!.id!), moduleId: requestData!.transactionNo!)));
      });
    }

    if (requestDetails != null) {
      return Column(
        // mainAxisAlignment: MainAxisAlignment.spaceBetween,
        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,
              if (requestDetails?.status != null)
                StatusLabel(
                  label: requestDetails?.status ?? "",
                  textColor: AppColor.getRequestStatusTextColorByName(context, requestDetails?.status),
                  backgroundColor: AppColor.getRequestStatusColorByName(context, requestDetails?.status),
                ),
              1.width.expanded,
              InfoDateWidget(requestDetails!.date ?? ""),
            ],
          ),
          InfoHeaderWidget(requestDetails?.nameOfType ?? context.translation.deviceTransferRequest),
          InfoTextWidget(label: context.translation.trNumber, value: requestDetails!.requestNo),
          InfoTextWidget(label: context.translation.from, value: requestDetails!.siteTransferFrom?.cleanupWhitespace.capitalizeFirstOfEach),
          InfoTextWidget(label: context.translation.to, value: requestDetails!.siteTransferTo?.cleanupWhitespace.capitalizeFirstOfEach, showArrow: true),
          // requestDetails!.status!.replaceAll("=", ":").bodyText(context),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (_) => DeviceTransferDetails(
                  model: DeviceTransfer(id: requestDetails!.id!),
                  moduleId: requestDetails!.transactionType!,
                )));
      });
    }

    return const SizedBox();
  }
}
