///todo deleted
// import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart';
// import 'package:provider/provider.dart';
// import 'package:test_sa/extensions/context_extension.dart';
// import 'package:test_sa/models/lookup.dart';
// import 'package:test_sa/models/service_request/search_work_order.dart';
// import 'package:test_sa/models/service_request/supplier_details.dart';
// import 'package:test_sa/views/widgets/app_text_form_field.dart';
// import 'package:test_sa/views/widgets/buttons/app_button.dart';
// import 'package:test_sa/views/widgets/status/report/service_report_assistant_employee_menu.dart';
// import 'package:test_sa/views/widgets/status/report/service_report_maintenance_situation.dart';
// import 'package:test_sa/views/widgets/status/report/service_report_repair_location.dart';
// import 'package:test_sa/views/widgets/status/service_request/supplier_engineers_menu.dart';
//
// import '../../../controllers/providers/api/status_drop_down/report/service_report_maintenance_situation_provider.dart';
// import '../../../models/service_request/supp_engineer_work_orders.dart';
// import '../../widgets/timer/app_timer.dart';
// import '../../widgets/titles/app_sub_title.dart';
// import 'auto_generated_vendor_name.dart';
//
// class WorkOrderDetailsBottomSheet extends StatefulWidget {
//   final SearchWorkOrder subWorkOrder;
//   final num assetId;
//
//   const WorkOrderDetailsBottomSheet({this.subWorkOrder, this.assetId, Key? key}) : super(key: key);
//
//   @override
//   State<WorkOrderDetailsBottomSheet> createState() => _WorkOrderDetailsBottomSheetState();
// }
//
// class _WorkOrderDetailsBottomSheetState extends State<WorkOrderDetailsBottomSheet> {
//   final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
//   final SearchWorkOrder _workOrder = SearchWorkOrder();
//   bool _showVendorFields = false;
//   SuppEngineerWorkOrders engineer;
//
//   @override
//   void initState() {
//     super.initState();
//     _workOrder.copyFrom(widget.subWorkOrder);
//     if (checkVendorFieldsVisibility(_workOrder.calllastSituation)) {
//       if (_workOrder.suppEngineerWorkOrders?.isNotEmpty ?? false) {
//         engineer = _workOrder.suppEngineerWorkOrders?.last;
//         engineer?.id = engineer?.supplierContactId;
//       }
//       _workOrder.supplier ??= SupplierDetails(id: _workOrder?.supplier?.id);
//     }
//     if (context.mounted) {
//       Provider.of<ServiceReportMaintenanceSituationProvider>(context, listen: false).reset();
//     }
//   }
//
//   bool checkVendorFieldsVisibility(Lookup callsLastSituation) {
//     bool result = (_workOrder.supplier?.suppliername?.isNotEmpty ?? false) ||
//         (callsLastSituation?.name?.toLowerCase()?.contains("under repair-vendor") ?? false) ||
//         (callsLastSituation?.name?.toLowerCase()?.contains("waiting for vendor") ?? false);
//     _showVendorFields = result;
//     return result;
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     final size = MediaQuery.of(context).size;
//
//     return Padding(
//       padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
//       child: ClipRRect(
//         borderRadius: const BorderRadius.only(
//           topLeft: Radius.circular(15),
//           topRight: Radius.circular(15),
//         ),
//         clipBehavior: Clip.antiAliasWithSaveLayer,
//         child: Container(
//           color: Colors.white,
//           height: size.height * 0.9,
//           padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
//           child: Form(
//             key: _formKey,
//             child: Column(
//               crossAxisAlignment: CrossAxisAlignment.start,
//               children: [
//                 const ASubTitle("WO Details"),
//                 const SizedBox(height: 8),
//                 Expanded(
//                   child: Padding(
//                     padding: const EdgeInsets.all(8.0),
//                     child: SingleChildScrollView(
//                       child: Column(
//                         crossAxisAlignment: CrossAxisAlignment.start,
//                         children: [
//                           const SizedBox(height: 8),
//                           ATextFormField(enable: false, hintText: "Assigned Employee: ${_workOrder.assignedEmployee?.name}"),
//                           const SizedBox(height: 8),
//                           const ASubTitle("Assistant Employee"),
//                           const SizedBox(height: 4),
//                           ServiceReportAssistantEmployeeMenu(
//                             assetId: widget.assetId,
//                             initialValue: (_workOrder.assistantEmployees?.isNotEmpty ?? false) ? _workOrder.assistantEmployees?.first : null,
//                             onSelect: (assistantsEmployee) {
//                               if (assistantsEmployee == null) {
//                                 _workOrder.assistantEmployees = [];
//                               } else {
//                                 _workOrder.assistantEmployees = [assistantsEmployee];
//                               }
//                             },
//                           ),
//                           const SizedBox(height: 8),
//                           ASubTitle(context.translation.workingHours),
//                           const SizedBox(height: 8),
//                           Row(
//                             children: [
//                               Expanded(
//                                 child: AppTimer(
//                                   timer: _workOrder.timer,
//                                   onChange: (timer) async {
//                                     _workOrder.timer = timer;
//                                     _workOrder.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0");
//                                     return true;
//                                   },
//                                 ),
//                               ),
//                             ],
//                           ),
//                           const SizedBox(height: 16),
//                           ATextFormField(
//                             labelText: "Travel Hours",
//                             initialValue: _workOrder.travelingHours?.toString(),
//                             textInputType: TextInputType.number,
//                             onSaved: (value) {
//                               _workOrder.travelingHours = num.tryParse(value);
//                             },
//                           ),
//                           const SizedBox(height: 8),
//                           ATextFormField(
//                             labelText: "Travel Expense",
//                             initialValue: _workOrder.travelingExpenses?.toString(),
//                             textInputType: TextInputType.number,
//                             onSaved: (value) {
//                               _workOrder.travelingExpenses = num.tryParse(value);
//                             },
//                           ),
//                           const SizedBox(height: 8),
//                           ASubTitle(context.translation.callLastSituation),
//                           const SizedBox(height: 4),
//                           ServiceReportMaintenanceSituation(
//                             initialValue: _workOrder.calllastSituation,
//                             onSelect: (status) {
//                               if (checkVendorFieldsVisibility(status)) {
//                                 _workOrder.supplier ??= SupplierDetails(id: _workOrder?.supplier?.id);
//                                 engineer = null;
//                               }
//                               if (status?.value == 12 || _workOrder.calllastSituation?.value == 12) {
//                                 _workOrder.calllastSituation = status;
//                                 _workOrder.mrNumber = null;
//                                 setState(() {});
//                               } else {
//                                 _workOrder.calllastSituation = status;
//                               }
//                               setState(() {});
//                             },
//                             woId: widget.subWorkOrder?.parentWOId?.toString(),
//                           ),
//                           if (_workOrder.calllastSituation.value == 12) const ASubTitle(" You have to add parts", color: Colors.amber, padding: EdgeInsets.all(2), font: 11),
//                           if (_workOrder.calllastSituation.value == 12) const SizedBox(height: 8),
//                           if (_workOrder.calllastSituation.value == 12)
//                             ATextFormField(
//                               labelText: "MR number",
//                               initialValue: _workOrder.mrNumber,
//                               onSaved: (value) {
//                                 _workOrder.mrNumber = value;
//                               },
//                             ),
//                           if (_showVendorFields) const SizedBox(height: 8),
//                           if (_showVendorFields)
//                             AutoGeneratedVendorName(
//                               initialValue: _workOrder.supplier?.suppliername,
//                               onSearch: (supplier) {
//                                 _workOrder.supplier.id = supplier.id;
//                                 _workOrder.supplier.suppliername = supplier.suppliername;
//                                 _workOrder.supplier.suppPersons = supplier.suppPersons;
//                                 setState(() {});
//                               },
//                             ),
//                           if (_showVendorFields) const SizedBox(height: 8),
//                           if (_showVendorFields)
//                             SupplierEngineersMenu(
//                               initialValue: engineer,
//                               engineers: _workOrder?.supplier?.suppPersons,
//                               onSelect: (engineer) {
//                                 if (engineer != null) {
//                                   this.engineer = engineer;
//                                 }
//                               },
//                             ),
//                           const SizedBox(height: 8),
//                           const ASubTitle("Repair Location"),
//                           const SizedBox(height: 4),
//                           ServiceReportRepairLocation(
//                             initialValue: _workOrder.repairLocation,
//                             onSelect: (status) {
//                               _workOrder.repairLocation = status;
//                             },
//                           ),
//                           const SizedBox(height: 8),
//                           ATextFormField(
//                             labelText: "Technical Comments",
//                             initialValue: _workOrder.comment,
//                             textInputType: TextInputType.multiline,
//                             onSaved: (value) {
//                               _workOrder.comment = value;
//                             },
//                           ),
//                           const SizedBox(height: 24),
//                         ],
//                       ),
//                     ),
//                   ),
//                 ),
//                 AButton(
//                   text: context.translation.submit,
//                   onPressed: () async {
//                     if (_workOrder?.workingHours == null) {
//                       await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started");
//                       return;
//                     }
//                     if (_showVendorFields && (_workOrder.supplier.suppliername == null || _workOrder.supplier.suppliername.isEmpty)) {
//                       await Fluttertoast.showToast(msg: "Vendor Name Field is Required");
//                       return;
//                     }
//                     if (_showVendorFields && _workOrder.suppEngineerWorkOrders == null) {
//                       await Fluttertoast.showToast(msg: "Vendor Engineer Field is Required");
//                       return;
//                     }
//                     _workOrder.suppEngineerWorkOrders ?? [];
//                     if (engineer != null) _workOrder.suppEngineerWorkOrders.add(engineer..id = 0);
//                     if (_workOrder.calllastSituation == null) {
//                       await Fluttertoast.showToast(msg: "Call Last Situation Field is Required");
//                       return;
//                     }
//                     _formKey.currentState.save();
//                     widget.subWorkOrder.copyFrom(_workOrder);
//                     Navigator.pop(context);
//                   },
//                 ),
//               ],
//             ),
//           ),
//         ),
//       ),
//     );
//   }
// }
