import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_repair_location_provider.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
import 'package:test_sa/views/widgets/status/single_status_menu.dart';

class ServiceReportRepairLocation extends StatelessWidget {
  final String? label; // Nullable
  final Lookup? initialValue; // Nullable
  final Function(Lookup?)? onSelect; // Nullable function, accepts nullable Lookup

  const ServiceReportRepairLocation({Key? key, this.label, this.onSelect, this.initialValue}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final settingProvider = Provider.of<SettingProvider>(context);
    final userProvider = Provider.of<UserProvider>(context);
    final menuProvider = Provider.of<ServiceReportRepairLocationProvider>(context);
    return LoadingManager(
        isLoading: menuProvider.isLoading,
        isFailedLoading: menuProvider.reasons == null,
        stateCode: menuProvider.stateCode,
        onRefresh: () async {
          menuProvider.reset();
          await menuProvider.getTypes();
        },
        child: SingleStatusMenu(
          title: label,
          initialStatus: initialValue,
          statuses: menuProvider.reasons,
          onSelect: onSelect,
        ));
  }
}