import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/emergency_services/emergency_services_view_model.dart';
import 'package:hmg_patient_app_new/features/emergency_services/models/resp_model/RRTServiceData.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/emergency_services/history/widget/RequestStatus.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:provider/provider.dart';
import 'dart:ui' as ui;

import '../../../../core/utils/utils.dart';


class RRTItem extends StatelessWidget {
  final GetCMCAllOrdersResponseModel order;

  const RRTItem({super.key, required this.order});

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
        color: AppColors.whiteColor,
        hasShadow: true,
        customBorder: BorderRadius.all(
          Radius.circular(20.h),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        spacing: 8.h,
        children: [
          RequestStatus(status: order.statusId ?? 0),
          "Req ID: ${order.iD}".toText16(color: AppColors.textColor, isBold: true, isEnglishOnly: true),
          Row(
            spacing: 4.w,
            children: [
              chip(Utils.getDayMonthYearDateFormatted(DateUtil.parseISODate(order.created)), AppAssets.calendar, AppColors.blackBgColor),
              chip(LocaleKeys.rapidResponseTeam.tr(context: context), AppAssets.ic_rrt_vehicle, AppColors.blackBgColor),
            ],
          ),
          SizedBox(height: 4.h),
          if (order.statusId == 1 || order.statusId == 2)
            CustomButton(
              text: LocaleKeys.cancelRequest.tr(context: context),
              onPressed: () async {
                openCancelOrderBottomSheet(context);
              },
              backgroundColor: AppColors.primaryRedColor,
              borderColor: AppColors.primaryRedColor,
              textColor: Colors.white,
              icon: AppAssets.cancel,
              iconSize: 20.h,
              height: 40.h,
            ),
        ],
      ).paddingAll(16.h),
    ).paddingOnly(bottom: 16.h);
  }

  chip(String title, String iconString, Color iconColor) {
    return Directionality(
      textDirection: ui.TextDirection.ltr,
      child: AppCustomChipWidget(
        labelText: title,
        icon: iconString,
        iconColor: iconColor,
        iconSize: 12.h,
        isEnglishOnly: true,
      ),
    );
  }

  openCancelOrderBottomSheet(BuildContext context) {
    context.read<EmergencyServicesViewModel>().cancelRRTOrder(order.iD);
  }
}
