import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/models/new_models/assistant_employee.dart';
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
import 'package:test_sa/views/widgets/status/assistant_employee_menu.dart';

import '../../../../controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart';

class ServiceReportAssistantEmployeeMenu extends StatelessWidget {
  final Function(AssistantEmployees?) onSelect;
  final AssistantEmployees? initialValue; // Now nullable
  Color? backgroundColor;
  final String title;
  final num ?assetId;
  final bool enable;

  ServiceReportAssistantEmployeeMenu({Key? key, required this.onSelect, required this.title, required this.initialValue,  this.assetId, this.backgroundColor, this.enable = true})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final menuProvider = Provider.of<ServiceReportAssistantsEmployeeProvider>(context);
    return LoadingManager(
      isLoading: menuProvider.isLoading,
      isFailedLoading: menuProvider.assistantEmployees == null,
      stateCode: menuProvider.stateCode,
      onRefresh: () async {
        await menuProvider.getAssistantEmployees(assetId:assetId);
      },
      child: AssistantEmployeeMenu(
        initialStatus: initialValue,
        title: title,
        showAsBottomSheet: true,
        hideShadow: true,
        statuses: menuProvider.assistantEmployees ?? [],
        backgroundColor: backgroundColor,
        // Provide an empty list if null
        onSelect: onSelect,
        // Pass onSelect directly
        enable: enable,
      ),
    );
  }
}

// import 'package:flutter/material.dart';
// import 'package:provider/provider.dart';
// import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
// import 'package:test_sa/providers/loading_list_notifier.dart';
// import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
//
// import '../../../../controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart';
// import '../../../../models/new_models/assistant_employee.dart';
//
// class ServiceReportAssistantEmployeeMenu extends StatefulWidget {
//   final Function(AssistantEmployees) onSelect;
//   final AssistantEmployees initialValue;
//   final String title;
//   final num assetId;
//   final bool enabled;
//
//   const ServiceReportAssistantEmployeeMenu({Key? key, this.enabled = true, required this.onSelect, required this.assetId, this.title, this.initialValue}) : super(key: key);
//
//   @override
//   State<ServiceReportAssistantEmployeeMenu> createState() => _ServiceReportAssistantEmployeeMenuState();
// }
//
// class _ServiceReportAssistantEmployeeMenuState extends State<ServiceReportAssistantEmployeeMenu> {
//   AssistantEmployees _initialValue;
//
//   @override
//   void initState() {
//     _initialValue = widget.initialValue;
//     super.initState();
//   }
//
//   @override
//   void didUpdateWidget(covariant ServiceReportAssistantEmployeeMenu oldWidget) {
//     if (widget.initialValue != oldWidget.initialValue) {
//       _initialValue = widget.initialValue;
//       setState(() {});
//     }
//     super.didUpdateWidget(oldWidget);
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     ServiceReportAssistantsEmployeeProvider menuProvider = Provider.of<ServiceReportAssistantsEmployeeProvider>(context);
//     return LoadingManager(
//       isLoading: menuProvider.isLoading,
//       isFailedLoading: menuProvider.assistantEmployees == null,
//       stateCode: menuProvider.stateCode,
//       onRefresh: () async {
//         await menuProvider.getAssistantEmployees(widget.assetId);
//       },
//       child: SingleItemDropDownMenu<AssistantEmployees, NullableLoadingProvider>(
//         title: widget.title,
//         context: context,
//         enabled: widget.enabled,
//         initialValue: _initialValue,
//         staticData: menuProvider.assistantEmployees,
//         onSelect: widget.onSelect,
//       ),
//       // child: AssistantEmployeeMenu(
//       //   title: title,
//       //   initialStatus: initialValue,
//       //   statuses: menuProvider.assistantEmployees,
//       //   onSelect: onSelect,
//       // ),
//     );
//   }
// }
