import 'package:flutter/material.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/lights/light_brightness.dart';
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';

class LightsList extends StatelessWidget {
  const LightsList({
    super.key,
    required this.lights,
  });

  final List<DeviceModel> lights;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      padding: const EdgeInsets.all(0),
      itemCount: lights.length,
      itemBuilder: (context, index) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                BodySmall(text: lights[index].name ?? ""),
                IconButton(
                  onPressed: () {
                    DevicesCubit.getInstance().selectDevice(lights[index]);
                  },
                  icon: const Icon(
                    Icons.arrow_forward_ios,
                  ),
                  style: ButtonStyle(
                    padding: MaterialStateProperty.all(
                      const EdgeInsets.all(0),
                    ),
                    iconSize: MaterialStateProperty.all(15),
                    alignment: Alignment.bottomRight,
                  ),
                ),
              ],
            ),
            const SizedBox(height: 5),
            DevicesDefaultSwitch(
              off: 'OFF',
              on: 'ON',
              switchValue: false,
              action: () {},
            ),
            const SizedBox(height: 10),
            LightBrightness(light: lights[index]),
          ],
        );
      },
    );
  }
}
