import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/employee/nurse_provider.dart';
import 'package:test_sa/models/employee.dart';
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
import 'package:test_sa/views/widgets/status/nurse_employee_menu.dart';

class NurseMenu extends StatelessWidget {
  final Function(Employee?) onSelect; // Now accepts nullable Employee
  final Employee? initialValue; // Now nullable

  final String title; // Now nullable
  final bool enable;
  final int? siteId; // Now nullable

  const NurseMenu({Key? key, required this.onSelect, required this.title, this.initialValue, this.enable = true, this.siteId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final menuProvider = Provider.of<NurseProvider>(context, listen: false);
    if (siteId != null) {
      menuProvider.siteId = siteId!;
    }
    return LoadingManager(
      isLoading: menuProvider.isLoading,
      isFailedLoading: menuProvider.nursesList == null,
      stateCode: menuProvider.stateCode,
      onRefresh: menuProvider.getData,
      // Directly pass the getData method
      child: NurseEmployeeMenu(
        initialValue: initialValue,
        title: title,
        list: menuProvider.nursesList ?? [],
        // Provide an empty list if null
        onSelect: onSelect,
        // Pass the onSelect function directly
        enable: enable,
      ),
    );
  }
}
