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/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/demo_module/demo_detail_view_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 DemoRequestItemView extends StatelessWidget {
  final Data? requestData;
  final RequestsDetails? requestDetails;
  final bool showShadow;

  const DemoRequestItemView({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.demoRequestStatusTextColor(context, requestData?.statusValue ?? 0),
                backgroundColor: AppColor.demoRequestStatus(context, requestData?.statusValue ?? 0),
              ),
              1.width.expanded,
              InfoDateWidget(requestData!.transactionDate ?? ""),
            ],
          ),
          // 8.height,
          InfoHeaderWidget(requestData?.typeTransaction ?? 'Demo Request'),
          InfoTextWidget(label: context.translation.requestNo, value: requestData?.requestNo ?? '-'),
          InfoTextWidget(label: context.translation.requestType, value: requestData?.requestTypeName, showArrow: true),
          // infoWidget(label: 'No of Sites'.addTranslation, value: requestData?.numberOfSites != null ? requestData?.numberOfSites.toString() : '-', context: context),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
        Navigator.of(context).push(MaterialPageRoute(builder: (_) => DemoDetailViewPage(demoId: requestData!.id!, moduleId: requestData!.transactionNo!)));
      });
    }
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      spacing: 1,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            StatusLabel(
              label: requestDetails!.status!,
              textColor: AppColor.demoRequestStatusTextColor(context, requestDetails?.statusValue ?? 0),
              backgroundColor: AppColor.demoRequestStatus(context, requestDetails?.statusValue ?? 0),
            ),
            1.width.expanded,
            InfoDateWidget(requestDetails!.date ?? ""),
          ],
        ),
        // 8.height,
        InfoHeaderWidget(requestDetails?.nameOfType ?? 'Demo Request'),
        // infoWidget(label: context.translation.requestType, value: requestDetails!.requestType, context: context),
        InfoTextWidget(label: context.translation.requestNo, value: requestDetails!.requestNo),
        InfoTextWidget(label: context.translation.site, value: requestDetails!.site, showArrow: true),
      ],
    ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
      Navigator.of(context).push(MaterialPageRoute(builder: (_) => DemoDetailViewPage(demoId: requestDetails!.id!, moduleId: requestDetails!.transactionType!)));
    });
  }
}
