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/shared/batch_control/factory_reset.dart';
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';

import 'package:syncrow_web/pages/device_managment/water_leak/bloc/water_leak_bloc.dart';
import 'package:syncrow_web/pages/device_managment/water_leak/bloc/water_leak_event.dart';
import 'package:syncrow_web/pages/device_managment/water_leak/bloc/water_leak_state.dart';
import 'package:syncrow_web/pages/device_managment/water_leak/model/water_leak_status_model.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';

class WaterLeakBatchControlView extends StatelessWidget with HelperResponsiveLayout {
  final List<String> deviceIds;

  const WaterLeakBatchControlView({Key? key, required this.deviceIds}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) =>
          WaterLeakBloc(deviceIds.first)..add(FetchWaterLeakBatchStatusEvent(deviceIds)),
      child: BlocBuilder<WaterLeakBloc, WaterLeakState>(
        builder: (context, state) {
          if (state is WaterLeakLoadingState) {
            return const Center(child: CircularProgressIndicator());
          } else if (state is WaterLeakBatchStatusLoadedState) {
            return _buildStatusControls(context, state.status);
          } else if (state is WaterLeakErrorState) {
            return Center(child: Text('Error: ${state.message}'));
          } else {
            return const Center(child: CircularProgressIndicator());
          }
        },
      ),
    );
  }

  Widget _buildStatusControls(BuildContext context, WaterLeakStatusModel status) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // SizedBox(
        //     width: 170,
        //     height: 140,
        //     child: FirmwareUpdateWidget(deviceId: deviceIds.first, version: 2)),
        // const SizedBox(
        //   width: 12,
        // ),
        SizedBox(
          width: 170,
          height: 140,
          child: FactoryResetWidget(
            callFactoryReset: () {
              context.read<WaterLeakBloc>().add(WaterLeakFactoryResetEvent(
                  deviceId: deviceIds.first,
                  factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
            },
          ),
        ),
      ],
    );
  }
}
