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/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/new_models/dashboard_detail.dart';
import 'package:test_sa/models/new_models/gas_refill_model.dart';
import 'package:test_sa/modules/tm_module/gas_refill/gas_refill_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 GasRefillItemView extends StatelessWidget {
  final Data? requestData;
  final RequestsDetails? requestDetails;
  final bool showShadow;

  const GasRefillItemView({Key? key, this.requestDetails, this.requestData, 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: [
              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.gasRefillRequest),
          InfoTextWidget(label: context.translation.requestNo, value: requestData!.requestNo, showArrow: true),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        Navigator.of(context).push(
          MaterialPageRoute(
            builder: (_) => GasRefillDetailsPage(
              priority: requestData!.priorityName,
              date: requestData!.transactionDate!,
              moduleId: requestData!.transactionNo!,
              model: GasRefillModel(id: requestData!.id),
            ),
          ),
        );
      });
    }

    if (requestDetails != null) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        spacing: 1,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              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.gasRefillRequest),
          InfoTextWidget(label: context.translation.gasType, value: requestDetails!.gasType),
          InfoTextWidget(label: context.translation.site, value: requestDetails!.site?.cleanupWhitespace.capitalizeFirstOfEach),
          InfoTextWidget(label: context.translation.requestNo, value: requestDetails!.requestNo, showArrow: true),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        Navigator.of(context).push(
          MaterialPageRoute(
            builder: (_) => GasRefillDetailsPage(
              priority: requestDetails!.priority!,
              date: requestDetails!.date,
              moduleId: requestDetails!.transactionType!,
              model: GasRefillModel(id: requestDetails!.id),
            ),
          ),
        );
      });
    }

    return const SizedBox();
  }
}
