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/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/asset_inventory_module/pages/asset_inventory_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 InventorySessionItemView extends StatelessWidget {
  final Data? requestData;
  final RequestsDetails? requestDetails;
  final bool showShadow;

  const InventorySessionItemView({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: [
              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.taskRequest),
          InfoTextWidget(label: 'Session Type'.addTranslation, value: requestData?.sessionType),
          InfoTextWidget(label: 'No of Assets'.addTranslation, value: requestData?.numberOfAssets != null ? requestData?.numberOfAssets.toString() : '-'),
          InfoTextWidget(label: 'No of Sites'.addTranslation, value: requestData?.numberOfSites != null ? requestData?.numberOfSites.toString() : '-', showArrow: true),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
        Navigator.of(context).push(MaterialPageRoute(builder: (_) => AssetInventoryPage(sessionId: requestData!.id!, moduleId: requestData!.transactionNo!)));
      });
    }
    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.taskRequest),
        InfoTextWidget(label: 'Session Type'.addTranslation, value: requestDetails?.sessionType),
        InfoTextWidget(label: 'No of Assets'.addTranslation, value: requestDetails?.numberOfAssets != null ? requestDetails?.numberOfAssets.toString() : '-'),
        InfoTextWidget(label: 'No of Sites'.addTranslation, value: requestDetails?.numberOfSites != null ? requestDetails?.numberOfSites.toString() : '-', showArrow: true),
      ],
    ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
      Navigator.of(context).push(MaterialPageRoute(builder: (_) => AssetInventoryPage(sessionId: requestDetails!.id!, moduleId: requestDetails!.transactionType!)));
    });
  }
}
