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

import '../../../../api/login_api_client.dart';
import '../../../../controllers/providers/api/status_drop_down/pentry/pentry_visit_status_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 PentryVisitsStatusMenu extends StatelessWidget {
  final Function(Lookup?)? onSelect;
  final Lookup? initialValue;

  const PentryVisitsStatusMenu({
    Key? key,
    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<PentryVisitStatusProvider>(context);
    return LoadingManager(
      isLoading: menuProvider.isLoading,
      isFailedLoading: menuProvider.items == null,
      stateCode: menuProvider.stateCode,
      onRefresh: () async {
        menuProvider.reset();
        await menuProvider.getData(
          user: UserApiClient().user,
          host: settingProvider.host,
        );
      },
      child: SingleStatusMenu(
        initialStatus: initialValue,
        statuses: menuProvider.items,
        onSelect: onSelect,
      ),
    );
  }
}
