import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../../api/login_api_client.dart';
import '../../../../controllers/providers/api/status_drop_down/report/service_types_provider.dart';
import '../../../../controllers/providers/settings/setting_provider.dart';
import '../../../../models/lookup.dart';
import '../../loaders/loading_manager.dart';
import '../single_status_menu.dart';

class ServiceStatusMenu extends StatelessWidget {
  final Function(Lookup?)? onSelect;
  final Lookup? initialValue;

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

  @override
  Widget build(BuildContext context) {
    SettingProvider settingProvider = Provider.of<SettingProvider>(context);
    ServiceStatusProvider menuProvider = Provider.of<ServiceStatusProvider>(context);
    return LoadingManager(
      isLoading: menuProvider.isLoading,
      isFailedLoading: menuProvider.statuses == null,
      stateCode: menuProvider.stateCode,
      onRefresh: () async {
        menuProvider.reset();
        await menuProvider.getTypes(
          user: UserApiClient().user,
          host: settingProvider.host,
        );
      },
      child: SingleStatusMenu(
        initialStatus: initialValue,
        statuses: menuProvider.statuses,
        onSelect: onSelect,
      ),
    );
  }
}
