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 Lookup initialValue;
  final Function(Lookup) onSelect;

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

  @override
  Widget build(BuildContext context) {
    SettingProvider _settingProvider = Provider.of<SettingProvider>(context);
    UserProvider _userProvider = Provider.of<UserProvider>(context);
    ServiceReportRepairLocationProvider _menuProvider = Provider.of<ServiceReportRepairLocationProvider>(context);
    return LoadingManager(
        isLoading: _menuProvider.isLoading,
        isFailedLoading: _menuProvider.reasons == null,
        stateCode: _menuProvider.stateCode,
        onRefresh: () async {
          _menuProvider.reset();
          await _menuProvider.getTypes(
            user: _userProvider.user,
            host: _settingProvider.host,
          );
        },
        child: SingleStatusMenu(
          initialStatus: initialValue,
          statuses: _menuProvider.reasons,
          onSelect: onSelect,
        ));
  }
}
