import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';

class UniversalSwitch extends StatelessWidget {
  const UniversalSwitch({
    super.key,
    required this.allOn,
  });

  final bool allOn;

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ACsBloc, AcsState>(
      builder: (context, state) {
        // bool? status = category.devicesStatus;
        return Row(
          children: <Widget>[
            Expanded(
              child: InkWell(
                onTap: () {
                  BlocProvider.of<ACsBloc>(context).add(const ChangeAllSwitch(value: true));
                },
                child: Container(
                  height: 60,
                  decoration: BoxDecoration(
                    color: allOn ? ColorsManager.primaryColor : Colors.white,
                    borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(15),
                      bottomLeft: Radius.circular(15),
                    ),
                  ),
                  child: Center(
                    child: BodyMedium(
                      text: StringsManager.on,
                      fontColor: allOn ? Colors.white : null,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              child: InkWell(
                onTap: () {
                  BlocProvider.of<ACsBloc>(context).add(const ChangeAllSwitch(value: false));
                },
                child: Container(
                  height: 60,
                  decoration: BoxDecoration(
                    color: allOn ? Colors.white : ColorsManager.primaryColor,
                    borderRadius: const BorderRadius.only(
                      topRight: Radius.circular(15),
                      bottomRight: Radius.circular(15),
                    ),
                  ),
                  child: Center(
                    child: BodyMedium(
                      text: StringsManager.off,
                      fontColor: allOn ? null : Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ),
          ],
        );
      },
    );
  }
}
