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_report_reasons_provider.dart';
import '../../../../controllers/providers/settings/setting_provider.dart';
import '../../../../controllers/providers/user_provider.dart';
import '../../../../models/lookup.dart';
import '../../loaders/loading_manager.dart';
import '../single_status_menu.dart';

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

  const ServiceReportReasonsMenu({
    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);
    ServiceReportReasonsProvider menuProvider = Provider.of<ServiceReportReasonsProvider>(context);
    return LoadingManager(
      isLoading: menuProvider.isLoading,
      isFailedLoading: menuProvider.reasons == null,
      stateCode: menuProvider.stateCode,
      onRefresh: () async {
        menuProvider.reset();
        await menuProvider.getTypes(
          user: UserApiClient().user,
          host: settingProvider.host,
        );
      },
      child: SingleStatusMenu(
        initialStatus: initialValue,
        statuses: menuProvider.reasons,
        onSelect: onSelect,
      ),
    );
  }
}
