import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/models/new_models/assistant_employee.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';

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

  const 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: SingleItemDropDownMenu<AssistantEmployees, NullableLoadingProvider>(
        context: context,
        title: title,
        staticData: menuProvider.assistantEmployees ?? [],
        showShadow: false,
        showAsBottomSheet: true,
        loading: menuProvider.isLoading,
        initialValue: initialValue,
        enabled: enable,
        onSelect: (employee) async {
          if (employee != null) {
            onSelect(employee);
          }
        },
      ),
    );
  }
}
