import 'dart:developer';

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/new_models/dashboard_detail.dart';
import 'package:test_sa/modules/cleaner_module/pages/one_time_task_view.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 OneTimeTaskItemView extends StatelessWidget {
  final Data? requestData;
  final RequestsDetails? requestDetails;
  final bool showShadow;

  const OneTimeTaskItemView({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 ?? ""),
            ],
          ),
          8.height,
          InfoHeaderWidget(requestData?.typeTransaction ?? 'One Time Task'.addTranslation),
          InfoTextWidget(label: context.translation.taskNo, value: requestData!.requestNo),
          if (requestData?.siteName != null) InfoTextWidget(label: context.translation.site, value: requestData!.siteName),
          if (requestData!.buildingName != null) InfoTextWidget(label: context.translation.building, value: requestData!.buildingName),
          if (requestData!.departmentName != null) InfoTextWidget(label: context.translation.department, value: requestData!.departmentName),
          if (requestData!.floorName != null) InfoTextWidget(label: context.translation.floor, value: requestData!.floorName),
          InfoTextWidget(
            label: context.translation.room,
            value: requestData!.roomName,
            showArrow: true,
          ),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() {
        // Navigate to editable view for in-progress tasks
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => OneTimeTaskView(
              taskId: requestData!.id ?? 0,
              initialData: null,
            ),
          ),
        );
      });
    }
    if (requestDetails != null) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        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 ?? ""),
            ],
          ),
          8.height,
          InfoHeaderWidget(requestDetails?.nameOfType ?? 'One Time Task'.addTranslation),
          InfoTextWidget(label: context.translation.taskNo, value: requestDetails!.requestNo),
          if (requestDetails!.siteName != null) InfoTextWidget(label: context.translation.site, value: requestDetails!.siteName),
          if (requestDetails!.buildingName != null) InfoTextWidget(label: context.translation.building, value: requestDetails!.buildingName),
          if (requestDetails!.departmentName != null) InfoTextWidget(label: context.translation.department, value: requestDetails!.departmentName),
          if (requestDetails!.floorName != null) InfoTextWidget(label: context.translation.floor, value: requestDetails!.floorName),
          InfoTextWidget(
            label: context.translation.room,
            value: requestDetails!.roomName,
            showArrow: true,
          ),
        ],
      ).toShadowContainer(context, withShadow: showShadow).onPress(() async {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => OneTimeTaskView(
              taskId: requestDetails!.id ?? 0,
              initialData: null,
            ),
          ),
        );
      });
    }
    return const SizedBox();
  }
}
