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/widget_extensions.dart';
import 'package:test_sa/models/all_requests_and_count_model.dart';
import 'package:test_sa/models/device/asset_transfer.dart';
import 'package:test_sa/models/new_models/dashboard_detail.dart';
import 'package:test_sa/views/pages/device_transfer/device_transfer_details.dart';

import '../../../../views/widgets/requests/request_status.dart';
import '../../../app_style/app_color.dart';

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

  const AssetItemView({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 (request.status != null)
              //   StatusLabel(
              //     label: request.status ?? "",
              //     textColor: AppColor.getRequestStatusTextColorByName(context, request.status),
              //     backgroundColor: AppColor.getRequestStatusColorByName(context, request.status),
              //   ),
              1.width.expanded,
              Text(requestData!.transactionDate?.toServiceRequestCardFormat ?? "",
                  textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)),
            ],
          ),
          8.height,
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              (requestData?.typeTransaction ?? context.translation.deviceTransferRequest).heading5(context),
              // "${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),
              '${context.translation.requestNo}: ${requestData!.requestNo}'.bodyText(context),
            ],
          ),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                context.translation.viewDetails,
                style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
              ),
              4.width,
              Icon(
                Icons.arrow_forward,
                color: AppColor.blueStatus(context),
                size: 14,
              )
            ],
          ),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        Navigator.of(context).push(MaterialPageRoute(builder: (_) => DeviceTransferDetails(model: AssetTransfer(id: requestData!.id!))));
      });
    }

    if (requestDetails != null) {
      return Column(
        // mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        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 (request.status != null)
              //   StatusLabel(
              //     label: request.status ?? "",
              //     textColor: AppColor.getRequestStatusTextColorByName(context, request.status),
              //     backgroundColor: AppColor.getRequestStatusColorByName(context, request.status),
              //   ),
              1.width.expanded,
              Text(requestDetails!.date?.toServiceRequestCardFormat ?? "",
                  textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)),
            ],
          ),
          8.height,
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              (requestDetails?.nameOfType ?? context.translation.deviceTransferRequest).heading5(context),
              "${context.translation.from} : ${requestDetails!.siteTransferFrom?.cleanupWhitespace?.capitalizeFirstOfEach}".bodyText(context),
              "${context.translation.to} : ${requestDetails!.siteTransferTo?.cleanupWhitespace?.capitalizeFirstOfEach}".bodyText(context),
              requestDetails!.status!.replaceAll("=", ":").bodyText(context),
              '${context.translation.requestNo}: ${requestDetails!.requestNo}'.bodyText(context),
            ],
          ),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                context.translation.viewDetails,
                style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
              ),
              4.width,
              Icon(
                Icons.arrow_forward,
                color: AppColor.blueStatus(context),
                size: 14,
              )
            ],
          ),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        Navigator.of(context).push(MaterialPageRoute(builder: (_) => DeviceTransferDetails(model: AssetTransfer(id: requestDetails!.id!))));
      });
    }

    return SizedBox();
  }
}
