import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
import 'package:syncrow_web/pages/device_managment/gateway/bloc/gate_way_bloc.dart';
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';

class GatewayBatchControlView extends StatelessWidget with HelperResponsiveLayout {
  const GatewayBatchControlView({super.key, required this.gatewayIds});

  final List<String> gatewayIds;

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => GateWayBloc()..add(GatWayById(gatewayIds.first)),
      child: BlocBuilder<GateWayBloc, GateWayState>(
        builder: (context, state) {
          if (state is GatewayLoadingState) {
            return const Center(child: CircularProgressIndicator());
          } else if (state is UpdateGatewayState) {
            return Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                // SizedBox(
                //     width: 170,
                //     height: 140,
                //     child: FirmwareUpdateWidget(deviceId: gatewayIds.first, version: 2)),
                // const SizedBox(
                //   width: 12,
                // ),
                SizedBox(
                  width: 170,
                  height: 140,
                  child: FactoryResetWidget(
                    callFactoryReset: () {
                      context.read<GateWayBloc>().add(
                            GateWayFactoryReset(
                              deviceId: gatewayIds.first,
                              factoryReset: FactoryResetModel(devicesUuid: gatewayIds),
                            ),
                          );
                    },
                  ),
                ),
              ],
            );
          } else {
            return const Center(child: Text('Error fetching status'));
          }
        },
      ),
    );
  }
}
