part of 'dialog.dart';

class OutletDialog extends StatefulWidget {
  const OutletDialog({super.key});

  @override
  State<OutletDialog> createState() => _OutletDialogState();
}

class _OutletDialogState extends State<OutletDialog> {
  @override
  void initState() {
    super.initState();
    context.read<OutletLoaderBloc>().add(
      const OutletLoaderEvent.fetched(isRefresh: true),
    );
  }

  @override
  Widget build(BuildContext context) {
    return CustomModalDialog(
      title: 'Outlet',
      subtitle: 'Silahkan pilih outlet',
      minWidth: context.deviceWidth * 0.4,
      contentPadding: const EdgeInsets.symmetric(
        horizontal: 16.0,
        vertical: 24.0,
      ),
      child: BlocBuilder<OutletLoaderBloc, OutletLoaderState>(
        builder: (context, state) {
          if (state.isFetching) {
            return const LoaderWithText();
          }

          return Column(
            children: [
              ...List.generate(
                state.outlets.length,
                (index) => GestureDetector(
                  onTap: () {
                    // selectOutlet(outlets[index]);
                  },
                  child: OutletCard(
                    outlet: state.outlets[index],
                    isSelected: false,
                  ),
                ),
              ),
              const SpaceHeight(24),
              const AppElevatedButton.filled(
                onPressed: null,
                label: 'Terapkan',
              ),
            ],
          );
        },
      ),
    );
  }
}
