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/power_clamp/bloc/smart_power_bloc.dart';
import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_event.dart';
import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_state.dart';
import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_batch_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/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) =>
          SmartPowerBloc(deviceId: deviceIds.first)..add(SmartPowerFetchBatchEvent(deviceIds)),
      child: BlocBuilder<SmartPowerBloc, SmartPowerState>(
        builder: (context, state) {
          if (state is SmartPowerLoading) {
            return const Center(child: CircularProgressIndicator());
          } else if (state is SmartPowerLoadBatchControll) {
            return _buildStatusControls(context, state.status);
          } else if (state is SmartPowerError) {
            return Center(child: Text('Error: ${state.message}'));
          } else {
            return const Center(child: CircularProgressIndicator());
          }
        },
      ),
    );
  }

  Widget _buildStatusControls(BuildContext context, PowerClampBatchModel 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<SmartPowerBloc>().add(SmartPowerFactoryReset(
                  deviceId: deviceIds.first,
                  factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
            },
          ),
        ),
      ],
    );
  }
}
