// import 'dart:convert';
// import 'dart:io';
//
// import 'package:flutter/material.dart';
// import 'package:provider/provider.dart';
// import 'package:test_sa/controllers/providers/api/service_requests_provider.dart';
// import 'package:test_sa/controllers/providers/api/user_provider.dart';
// import 'package:test_sa/extensions/context_extension.dart';
// import 'package:test_sa/extensions/int_extensions.dart';
// import 'package:test_sa/extensions/text_extensions.dart';
// import 'package:test_sa/extensions/widget_extensions.dart';
// import 'package:test_sa/models/service_request/service_request.dart';
// import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
//
// import '../../../../models/lookup.dart';
// import '../../../../new_views/app_style/app_color.dart';
// import '../../../../new_views/common_widgets/app_filled_button.dart';
// import '../../../../new_views/common_widgets/app_lazy_loading.dart';
// import '../../../../new_views/common_widgets/app_text_form_field.dart';
// import '../../../../new_views/common_widgets/single_item_drop_down_menu.dart';
// import '../../../../providers/service_request_providers/equipment_status_provider.dart';
// import '../../../../providers/service_request_providers/priority_provider.dart';
// import '../../../../providers/service_request_providers/requested_through_provider.dart';
// import '../../../../providers/service_request_providers/type_of_request_provider.dart';
// import '../../../widgets/equipment/pick_asset.dart';
// import '../../../widgets/images/multi_image_picker.dart';
// import '../../../widgets/sound/record_sound.dart';
//
// class UpdateServiceRequestPage extends StatefulWidget {
//   static const String id = "/update_service_request_page";
//   final ServiceRequest? serviceRequest;
//
//   const UpdateServiceRequestPage({Key? key,  this.serviceRequest}) : super(key: key);
//
//   @override
//   State<UpdateServiceRequestPage> createState() => _UpdateServiceRequestPageState();
// }
//
// class _UpdateServiceRequestPageState extends State<UpdateServiceRequestPage> {
//   final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
//   late TextEditingController _commentController;
//   List<File> _deviceImages = [];
//   late UserProvider _userProvider;
//// //todo @delete
//   @override
//   void initState() {
//     super.initState();
//     _deviceImages = widget.serviceRequest?.devicePhotos?.map((e) => File(e)).toList() ?? [];
//     _commentController = TextEditingController(text: widget.serviceRequest?.callComments ?? "");
//   }
//
//   @override
//   void dispose() {
//     _commentController.dispose();
//     super.dispose();
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     _userProvider = Provider.of<UserProvider>(context, listen: false);
//     return Scaffold(
//       appBar: DefaultAppBar(title: context.translation.updateServiceRequest),
//       body: SafeArea(
//         child: Form(
//           key: _formKey,
//           child: Column(
//             children: [
//               SingleChildScrollView(
//                 child: Column(
//                   crossAxisAlignment: CrossAxisAlignment.start,
//                   children: [
//                     PickAsset(
//                       editable: false,
//                       device: widget.serviceRequest?.device,
//                       onPickAsset: (asset) {
//                         widget.serviceRequest!.device = asset;
//                         setState(() {});
//                       },
//                     ),
//                     8.height,
//                     SingleItemDropDownMenu<Lookup, PriorityProvider>(
//                       context: context,
//                       title: context.translation.priority,
//                       initialValue: widget.serviceRequest?.priority,
//                       onSelect: (value) {
//                         widget.serviceRequest!.priority = value;
//                       },
//                     ),
//                     8.height,
//                     SingleItemDropDownMenu<Lookup, EquipmentStatusProvider>(
//                       context: context,
//                       title: context.translation.equipmentStatus,
//                       initialValue: widget.serviceRequest?.defectType,
//                       onSelect: (value) {
//                         widget.serviceRequest!.defectType = value;
//                       },
//                     ),
//                     8.height,
//                     Consumer<RequestedThroughProvider>(builder: (context, snapshot, _) {
//                       return SingleItemDropDownMenu<Lookup, RequestedThroughProvider>(
//                         context: context,
//                         enabled: false,
//                         title: context.translation.source,
//                         initialValue: snapshot.items.firstWhere((element) => element.value == 3, orElse:  null),
//                       );
//                     }),
//                     8.height,
//                     SingleItemDropDownMenu<Lookup, TypeOfRequestProvider>(
//                       context: context,
//                       title: context.translation.requestType,
//                       initialValue: widget.serviceRequest?.type,
//                       onSelect: (value) {
//                         widget.serviceRequest!.type = value;
//                       },
//                     ),
//                     8.height,
//                     MultiFilesPicker(label: context.translation.attachImage, files: _deviceImages),
//                     ((widget.serviceRequest!.devicePhotos?.isNotEmpty ?? false) ? 16 : 8).height,
//                     Align(
//                       alignment: AlignmentDirectional.centerStart,
//                       child: context.translation.callComments.heading5(context),
//                     ),
//                     8.height,
//                     AppTextFormField(
//                       controller: _commentController,
//                       labelText: context.translation.problemDesc,
//                       initialValue: widget.serviceRequest!.callComments,
//                       suffixIcon: "warning".toSvgAsset(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, width: 24).paddingOnly(end: 16),
//                       onSaved: (text) {
//                         widget.serviceRequest!.callComments = text;
//                       },
//                     ),
//                     8.height,
//                     RecordSound(
//                       onRecord: (audio) {
//                         widget.serviceRequest!.audio = audio;
//                       },
//                       enabled: widget.serviceRequest == null ? true : false,
//                     ),
//                     16.height,
//                   ],
//                 ),
//               ).expanded,
//               AppFilledButton(onPressed: _submit, label: context.translation.updateRequest),
//             ],
//           ),
//         ).paddingOnly(start: 16, end: 16, bottom: 24, top: 16),
//       ),
//     );
//   }
//
//   Future<void> _submit() async {
//     widget.serviceRequest?.requestedThrough = Provider.of<RequestedThroughProvider>(context, listen: false).items.firstWhere((element) => element.value == 3, orElse:  null);
//     if (_formKey.currentState!.validate() && await widget.serviceRequest!.validateNewRequest(context)) {
//       _formKey.currentState!.save();
//       widget.serviceRequest!.devicePhotos = _deviceImages.map((e) => _isLocalUrl(e.path) ? "${e.path.split("/").last}|${base64Encode(e.readAsBytesSync())}" : e.path).toList();
//       if (widget.serviceRequest!.audio != null) {
//         if (_isLocalUrl(widget.serviceRequest!.audio!)) {
//           final File file = File(widget.serviceRequest!.audio!);
//           widget.serviceRequest!.audio = "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}";
//         }
//       }
//       showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
//       await Provider.of<ServiceRequestsProvider>(context, listen: false).updateRequest(user: _userProvider.user!, request: widget.serviceRequest!);
//       Navigator.of(context).pop();
//     }
//   }
//
//   bool _isLocalUrl(String url) {
//     if (url.isEmpty != false) return false;
//     return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\');
//   }
// }
