import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/api_routes/urls.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/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/enums/user_types.dart';
import 'package:test_sa/models/enums/work_order_next_step.dart';
import 'package:test_sa/models/helper_data_models/workorder/work_order_helper_models.dart';
import 'package:test_sa/models/new_models/work_order_detail_model.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
import 'package:test_sa/service_request_latest/request_detail_provider.dart';
import 'package:test_sa/service_request_latest/views/components/action_button/footer_action_button.dart';
import 'package:test_sa/service_request_latest/views/components/initial_visit_card.dart';
import 'package:test_sa/service_request_latest/views/components/timer_widget.dart';
import 'package:test_sa/service_request_latest/views/forms/asset_retired/asset_retired.dart';
import 'package:test_sa/views/widgets/images/files_list.dart';
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';
import 'package:test_sa/views/widgets/sound/sound_player.dart';

class WorkOrderDetailView extends StatelessWidget {
  WorkOrderDetailView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    UserProvider _userProvider = Provider.of<UserProvider>(context, listen: false);
    return Consumer<RequestDetailProvider>(builder: (pContext, requestProvider, _) {

      return requestProvider.isLoading
          ? const CircularProgressIndicator(color: AppColor.primary10).center
          : requestProvider.currentWorkOrder == null
              ? const NoDataFound()
              : Stack(
                  children: [
                    Column(
                      children: [
                        SingleChildScrollView(
                          padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              workOrderDetailCard(context, requestProvider.currentWorkOrder!.data!, _userProvider),
                              initialVisitCard(requestDetailProvider: requestProvider, userProvider: _userProvider),
                              20.height,
                            ],
                          ),
                        ).expanded,
                        FooterActionButton.requestDetailsFooterWidget(
                            workOrderNextStepStatus: requestProvider.currentWorkOrder!.data!.nextStep!.workOrderNextStepEnum!,
                            activities: requestProvider.currentWorkOrder!.data?.activities ?? [],
                            userProvider: _userProvider,
                            context: context),
                      ],
                    ),
                    if (requestProvider.timer!=null&&requestProvider.timer!.isActive)...[
                      const TimerWidget(),
                    ]
                  ],
                );
    });
  }

  Widget workOrderDetailCard(BuildContext context, WorkOrderData workOrder, UserProvider userProvider) {

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        StatusLabel(
                          label: workOrder.priority?.name,
                          id: workOrder.priority!.id!,
                          radius: 4,
                          textColor: AppColor.getPriorityStatusTextColor(context, workOrder.priority!.id!),
                          backgroundColor: AppColor.getPriorityStatusColor(context, workOrder.priority!.id!),
                        ),
                        8.width,
                        StatusLabel(
                          radius: 4,
                          label: workOrder.status!.name,
                          textColor: AppColor.getHistoryLogStatusTextColorByName(workOrder.status!.name!),
                          backgroundColor: AppColor.getHistoryLogStatusColorByName(workOrder.status!.name!),
                        ),
                        1.width.expanded,
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            if (userProvider.user!.type == UsersTypes.normal_user)
                              context.translation.code.toSvgAsset(width: 48).onPress(() {
                                // Navigator.push(context, MaterialPageRoute(builder: (context) => UpdateServiceRequestPage(serviceRequest: serviceRequest)));
                              }),
                            if (userProvider.user!.type == UsersTypes.engineer) 16.height,
                            Text(
                              workOrder.requestedDate!.toString().toServiceRequestCardFormat,
                              textAlign: TextAlign.end,
                              style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
                            ),
                          ],
                        )
                      ],
                    ),
                    Text(
                      context.translation.assetDetails,
                      style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
                    ),
                    8.height,
                    Text(
                      '${context.translation.assetName}: ${workOrder.assetNdModel!.name?.cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),

                    // 8.height,
                    Text(
                      '${context.translation.assetNumber}:  ${workOrder.asset!.assetNumber}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    // Text(
                    //   '${context.translation.equipmentStatus}: ${workOrder.defectType?.name}', // todo ask ahmed
                    //   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
                    // ),
                    Text(
                      '${context.translation.manufacture}: ${workOrder.manufacturer?.name?.cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    Text(
                      '${context.translation.model}: ${workOrder.model?.name!.cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    Text(
                      '${context.translation.site}: ${workOrder.site?.siteName?.cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    Text(
                      '${context.translation.building}: ${workOrder.building?.name?.cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    Text(
                      '${context.translation.floor}: ${workOrder.floor?.name?.cleanupWhitespace?.capitalizeFirstOfEach ?? ""}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    Text(
                      '${context.translation.department}: ${workOrder.department?.name?.cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                    Text(
                      '${context.translation.room}: ${(workOrder.room?.toString() ?? "").cleanupWhitespace?.capitalizeFirstOfEach}',
                      style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    ),
                  ],
                ).expanded,
              ],
            ),
            8.height,
            const Divider().defaultStyle(context),

            //... request details starts here....
            Text(
              context.translation.requestDetail,
              style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
            ),
            8.height,
            Text(
              '${context.translation.requestType}: ${workOrder.typeofRequest?.name}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
            ),
            Text(
              '${context.translation.requestNo}: ${workOrder.workOrderNo}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
            ),
            Text(
              '${context.translation.requesterName}: ${workOrder.workOrderCreatedBy?.userName ?? "-"}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
            ),
            Text(
              '${context.translation.date}: ${workOrder.requestedDate!.toString().toServiceRequestDetailsFormat}',
              style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
            ),

            8.height,
            if ((workOrder.comments ?? "").isNotEmpty) ...[
              const Divider().defaultStyle(context),
              8.height,
              Text(
                workOrder.comments!,
                style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
              ),
            ],
            if (workOrder.workOrderAttachments.isNotEmpty ?? false) ...[
              8.height,
              const Divider().defaultStyle(context),
              FilesList(images: workOrder.workOrderAttachments.map((toElement) => URLs.getFileUrl(toElement.name!)!).toList()),
            ],
            if (workOrder.voiceNote?.isNotEmpty ?? false) ...[
              const Divider().defaultStyle(context),
              16.height,
              ASoundPlayer(audio: URLs.getFileUrl(workOrder.voiceNote!)!),
              8.height,
            ],
          ],
        ).paddingOnly(start: 16, end: 16, top: 16, bottom: 8),
        // (userProvider.user!.type == UsersTypes.normal_user
        //         ? Container(
        //             height: 50,
        //             padding: const EdgeInsets.only(left: 16, right: 16),
        //             alignment: Alignment.center,
        //             width: double.infinity,
        //             decoration: ShapeDecoration(
        //               color: context.isDark ? AppColor.neutral50 : AppColor.neutral30,
        //               shape: const RoundedRectangleBorder(
        //                 borderRadius: BorderRadius.only(
        //                   bottomLeft: Radius.circular(20),
        //                   bottomRight: Radius.circular(20),
        //                 ),
        //               ),
        //             ),
        //             child: Row(
        //               children: [
        //                 Text(
        //                   '${context.translation.commentHere}...',
        //                   style: AppTextStyles.heading6.copyWith(
        //                     color: (context.isDark ? AppColor.neutral30 : AppColor.neutral50).withOpacity(.6),
        //                   ),
        //                 ).expanded,
        //                 "comment_send".toSvgAsset(width: 24, color: context.isDark ? AppColor.primary50 : AppColor.primary70),
        //               ],
        //             ),
        //           )
        //         : Column(
        //             mainAxisSize: MainAxisSize.min,
        //             crossAxisAlignment: CrossAxisAlignment.start,
        //             children: [
        //               const Divider().defaultStyle(context),
        //               16.height,
        //               Row(
        //                 mainAxisSize: MainAxisSize.min,
        //                 children: [
        //                   Text(
        //                     context.translation.viewComments,
        //                     style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
        //                   ),
        //                   4.width,
        //                   Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14)
        //                 ],
        //               ),
        //             ],
        //           ).paddingOnly(bottom: 16, start: 16, end: 16))
        //     .onPress(() {
        //   // showModalBottomSheet(
        //   //   context: context,
        //   //   useSafeArea: true,
        //   //   isScrollControlled: true,
        //   //   useRootNavigator: true,
        //   //   backgroundColor: Colors.transparent,
        //   //   builder: (context) => CommentsBottomSheet(requestId: serviceRequest.id!),
        //   // );
        // }),
        //set condition for show asset detail button...
        if (workOrder.nextStep!.workOrderNextStepEnum == WorkOrderNextStepEnum.verifyAssetDetail ||
            workOrder.nextStep!.workOrderNextStepEnum == WorkOrderNextStepEnum.activity && userProvider.user?.type == UsersTypes.engineer) ...[
          assetRetiredButton(context: context),
        ]
      ],
    ).toShadowContainer(context, padding: 0);
  }

  Widget assetRetiredButton({required BuildContext context}) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.toScreenHeight, vertical: 12.toScreenWidth),
      child: AppFilledButton(
          label: context.translation.assetToBeRetired,
          maxWidth: true,
          buttonColor: Colors.white54,
          textColor: AppColor.red30,
          showBorder: true,
          onPressed: () async {
            Navigator.push(context, MaterialPageRoute(builder: (context) => const AssetRetired()));
          }),
    );
  }

  Widget initialVisitCard({required RequestDetailProvider requestDetailProvider, required UserProvider userProvider}) {
    if (requestDetailProvider.currentWorkOrder!.data!.needAVisitDateTime != null &&
        userProvider.user?.type == UsersTypes.engineer &&
        requestDetailProvider.currentWorkOrder?.data?.nextStep!.workOrderNextStepEnum == WorkOrderNextStepEnum.eArrived) {
      requestDetailProvider.needVisitHelperModel = NeedVisitHelperModel(
        workOrderId: requestDetailProvider.currentWorkOrder?.data?.requestId,
        visitDate: requestDetailProvider.currentWorkOrder?.data?.needAVisitDateTime,
        comment: requestDetailProvider.currentWorkOrder?.data?.needAVisitComment,
      );
      // requestDetailProvider.updateNeedVisitHelperModel(requestDetailProvider.needVisitHelperModel);
      return const InitialVisitCard();
    } else {
      return const SizedBox();
    }
  }

  void showToast({required UserProvider userProvider, required WorkOrderNextStepEnum nextStep, required BuildContext context}) {
    if (userProvider.user?.type == UsersTypes.engineer) {
      if (nextStep == WorkOrderNextStepEnum.nTakeAction) {
        const SizedBox().flushBar(context: context, title: context.translation.youMarkedThisIssueAsFixedWaitingForTheRequesterToConfirm, message: '');
      }
    }
  }
}

// class RequestDetailView extends StatefulWidget {
//   static const String id = "/call-details";
//   ServiceRequest serviceRequest;
//   bool fromTabView = false;
//
//   RequestDetailView({Key? key, required this.serviceRequest, this.fromTabView = false}) : super(key: key);
//
//   @override
//   State<RequestDetailView> createState() => _RequestDetailViewState();
// }
//
// class _RequestDetailViewState extends State<RequestDetailView> {
//   @override
//   void initState() {
//     super.initState();
//   }
//
//   void getServiceRequest({@required dynamic requestId}) {
//     // setState(() {});
//     WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) async {
//       Provider.of<CommentsProvider>(context, listen: false).reset();
//       ServiceRequestsProvider serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context, listen: false);
//       serviceRequestsProvider.currentSelectedRequest = await serviceRequestsProvider.getServiceRequestObjectById(requestId: requestId);
//       // setState(() {});
//     });
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     UserProvider _userProvider = Provider.of<UserProvider>(context, listen: false);
//
//     return !widget.fromTabView
//         ? Scaffold(
//             appBar: DefaultAppBar(title: context.translation.serviceDetails),
//             body: Padding(
//               padding: EdgeInsets.only(top: 12.toScreenHeight),
//               child: Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestsProvider, child) {
//                 return requestDetailCard(serviceRequestsProvider: serviceRequestsProvider, userProvider: _userProvider);
//               }),
//             ),
//           )
//         : Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestsProvider, child) {
//             return requestDetailCard(serviceRequestsProvider: serviceRequestsProvider, userProvider: _userProvider);
//           });
//   }
//
//   Widget requestDetailCard({required ServiceRequestsProvider serviceRequestsProvider, required UserProvider userProvider}) {
//     return SafeArea(
//       child: serviceRequestsProvider.isDetialLoading
//           ? const ALoading().center
//           : serviceRequestsProvider.currentSelectedRequest == null
//               ? Text(
//                   context.translation.noDataFound,
//                   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                 ).center
//               : Stack(
//                   children: [
//                     SingleChildScrollView(
//                       padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
//                       child: Column(
//                         mainAxisSize: MainAxisSize.min,
//                         crossAxisAlignment: CrossAxisAlignment.start,
//                         children: [
//                           informationCard(serviceRequestsProvider.currentSelectedRequest!, userProvider),
//
//                           40.height,
//                           // skipForLater(serviceRequestsProvider.currentSelectedRequest),
//                           //  20.height,
//                           const InitialVisitCard(),
//                           20.height,
//                         ],
//                       ),
//                     ),
//                     FooterActionButton.requestDetailsFooterWidget(status: 7, context: context),

//                   ],
//                 ),
//     );
//   }
//
//   Widget informationCard(ServiceRequest serviceRequest, UserProvider userProvider) {
//     return Column(
//       crossAxisAlignment: CrossAxisAlignment.start,
//       children: [
//         Column(
//           mainAxisSize: MainAxisSize.min,
//           crossAxisAlignment: CrossAxisAlignment.start,
//           children: [
//             Row(
//               crossAxisAlignment: CrossAxisAlignment.start,
//               children: [
//                 Column(
//                   crossAxisAlignment: CrossAxisAlignment.start,
//                   children: [
//                     Row(
//                       mainAxisSize: MainAxisSize.min,
//                       children: [
//                         StatusLabel(
//                           label: serviceRequest.priority?.name,
//                           id: serviceRequest.priority!.id!,
//                           radius: 4,
//                           textColor: AppColor.getPriorityStatusTextColor(context, serviceRequest.priority!.id!),
//                           backgroundColor: AppColor.getPriorityStatusColor(context, serviceRequest.priority!.id!),
//                         ),
//                         8.width,
//                         StatusLabel(
//                           radius: 4,
//                           label: serviceRequest.statusLabel,
//                           textColor: AppColor.getRequestStatusTextColor(context, serviceRequest.statusValue!),
//                           backgroundColor: AppColor.getRequestStatusColor(context, serviceRequest.statusValue!),
//                         ),
//                         1.width.expanded,
//                         Column(
//                           crossAxisAlignment: CrossAxisAlignment.end,
//                           children: [
//                             if (userProvider.user!.type == UsersTypes.normal_user)
//                               context.translation.code.toSvgAsset(width: 48).onPress(() {
//                                 Navigator.push(context, MaterialPageRoute(builder: (context) => UpdateServiceRequestPage(serviceRequest: serviceRequest)));
//                               }),
//                             if (userProvider.user!.type == UsersTypes.engineer) 16.height,
//                             Text(
//                               serviceRequest.date!.toServiceRequestCardFormat,
//                               textAlign: TextAlign.end,
//                               style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
//                             ),
//                           ],
//                         )
//                       ],
//                     ),
//                     Text(
//                       context.translation.assetDetails,
//                       style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
//                     ),
//                     8.height,
//                     '${context.translation.assetName}: ${serviceRequest.deviceEnName?.cleanupWhitespace?.capitalizeFirstOfEach}'.bodyText(context),
//                     // 8.height,
//                     Text(
//                       '${context.translation.assetNumber}:  ${serviceRequest.device?.assetNumber}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//
//                     Text(
//                       '${context.translation.equipmentStatus}: ${serviceRequest.defectType?.name}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.manufacture}: ${serviceRequest.device?.modelDefinition?.manufacturerName?.cleanupWhitespace?.capitalizeFirstOfEach}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.model}: ${serviceRequest.device?.modelDefinition?.modelName?.cleanupWhitespace?.capitalizeFirstOfEach}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.site}: ${serviceRequest.device?.site?.custName?.cleanupWhitespace?.capitalizeFirstOfEach}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.building}: ${serviceRequest.device?.building?.name?.cleanupWhitespace?.capitalizeFirstOfEach}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.floor}: ${serviceRequest.device?.floor?.name?.cleanupWhitespace?.capitalizeFirstOfEach ?? ""}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.department}: ${serviceRequest.device?.department?.departmentName?.cleanupWhitespace?.capitalizeFirstOfEach}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                     Text(
//                       '${context.translation.room}: ${(serviceRequest.device?.room?.name ?? "").cleanupWhitespace?.capitalizeFirstOfEach}',
//                       style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//                     ),
//                   ],
//                 ).expanded,
//               ],
//             ),
//             8.height,
//             const Divider().defaultStyle(context),
//
//             //... request details starts here....
//             Text(
//               context.translation.requestDetail,
//               style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
//             ),
//             8.height,
//             Text(
//               '${context.translation.requestType}: ${serviceRequest.type?.name}',
//               style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//             ),
//             Text(
//               '${context.translation.requestNo}: ${serviceRequest.requestCode}',
//               style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//             ),
//             Text(
//               '${context.translation.requesterName}: ${serviceRequest.callCreatedBy?.name ?? "-"}',
//               style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//             ),
//
//             8.height,
//             if ((serviceRequest.callComments ?? "").isNotEmpty) ...[
//               const Divider().defaultStyle(context),
//               8.height,
//               Text(
//                 serviceRequest.callComments!,
//                 style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
//               ),
//             ],
//             if (serviceRequest.devicePhotos?.isNotEmpty ?? false) ...[
//               8.height,
//               const Divider().defaultStyle(context),
//               FilesList(images: serviceRequest.devicePhotos!),
//             ],
//             if (serviceRequest.audio?.isNotEmpty ?? false) ...[
//               const Divider().defaultStyle(context),
//               16.height,
//               ASoundPlayer(audio: serviceRequest.audio!),
//               8.height,
//             ],
//           ],
//         ).paddingOnly(start: 16, end: 16, top: 16, bottom: 8),
//         (userProvider.user!.type == UsersTypes.normal_user
//                 ? Container(
//                     height: 50,
//                     padding: const EdgeInsets.only(left: 16, right: 16),
//                     alignment: Alignment.center,
//                     width: double.infinity,
//                     decoration: ShapeDecoration(
//                       color: context.isDark ? AppColor.neutral50 : AppColor.neutral30,
//                       shape: const RoundedRectangleBorder(
//                         borderRadius: BorderRadius.only(
//                           bottomLeft: Radius.circular(20),
//                           bottomRight: Radius.circular(20),
//                         ),
//                       ),
//                     ),
//                     child: Row(
//                       children: [
//                         Text(
//                           '${context.translation.commentHere}...',
//                           style: AppTextStyles.heading6.copyWith(
//                             color: (context.isDark ? AppColor.neutral30 : AppColor.neutral50).withOpacity(.6),
//                           ),
//                         ).expanded,
//                         "comment_send".toSvgAsset(width: 24, color: context.isDark ? AppColor.primary50 : AppColor.primary70),
//                       ],
//                     ),
//                   )
//                 : Column(
//                     mainAxisSize: MainAxisSize.min,
//                     crossAxisAlignment: CrossAxisAlignment.start,
//                     children: [
//                       const Divider().defaultStyle(context),
//                       16.height,
//                       Row(
//                         mainAxisSize: MainAxisSize.min,
//                         children: [
//                           Text(
//                             context.translation.viewComments,
//                             style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
//                           ),
//                           4.width,
//                           Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14)
//                         ],
//                       ),
//                     ],
//                   ).paddingOnly(bottom: 16, start: 16, end: 16))
//             .onPress(() {
//           showModalBottomSheet(
//             context: context,
//             useSafeArea: true,
//             isScrollControlled: true,
//             useRootNavigator: true,
//             backgroundColor: Colors.transparent,
//             builder: (context) => CommentsBottomSheet(requestId: serviceRequest.id!),
//           );
//         }),
//         //set condition for show asset detail button...
//         if (true) ...[
//           assetRetiredButton(serviceRequest: serviceRequest),
//         ]
//       ],
//     ).toShadowContainer(context, padding: 0);
//   }
//
//   Widget assetRetiredButton({required ServiceRequest serviceRequest}) {
//     return Padding(
//       padding: EdgeInsets.symmetric(horizontal: 16.toScreenHeight, vertical: 12.toScreenWidth),
//       child: AppFilledButton(
//           label: context.translation.assetToBeRetired,
//           maxWidth: true,
//           buttonColor: Colors.white54,
//           textColor: AppColor.red30,
//           showBorder: true,
//           onPressed: () async {
//             // Navigator.push(context, MaterialPageRoute(builder: (context) =>  AssetRetired()));
//             Navigator.push(context, MaterialPageRoute(builder: (context) => CreateNewRequest()));
//           }),
//     );
//   }
//
//   Widget skipForLater(ServiceRequest serviceRequest) {
//     return Center(
//       child: InkWell(
//         onTap: () async {
//           try {
//             //use a common list
//             AllRequestsProvider allRequestProvider = Provider.of<AllRequestsProvider>(context, listen: false);
//             int index = allRequestProvider.requestDetailList!.requestsDetails!.indexWhere((element) => element.id.toString() == serviceRequest.id);
//             if (index != -1 && index != allRequestProvider.requestDetailList!.requestsDetails!.length) {
//               getServiceRequest(requestId: allRequestProvider.requestDetailList!.requestsDetails![index + 1].id.toString());
//             }
//           } catch (e) {
//             print(e);
//           }
//         },
//         child: Text(
//           context.translation.skipForLater,
//           style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, decoration: TextDecoration.underline, fontSize: 16),
//         ),
//       ),
//     );
//   }
// }
