import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/routines/models/flush/flush_operational_value.dart';

class FlushOperationalValuesList extends StatelessWidget {
  final List<FlushOperationalValue> values;
  final dynamic selectedValue;
  final AllDevicesModel? device;
  final String operationName;
  final String selectCode;
  final ValueChanged<FlushOperationalValue> onSelect;
  const FlushOperationalValuesList({
    required this.values,
    required this.selectedValue,
    required this.device,
    required this.operationName,
    required this.selectCode,
    required this.onSelect,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      padding: const EdgeInsets.all(20),
      itemCount: values.length,
      itemBuilder: (context, index) => _buildValueItem(context, values[index]),
    );
  }

  Widget _buildValueItem(BuildContext context, FlushOperationalValue value) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          SvgPicture.asset(value.icon, width: 25, height: 25),
          Expanded(child: _buildValueDescription(value)),
          _buildValueRadio(context, value),
        ],
      ),
    );
  }

  Widget _buildValueDescription(FlushOperationalValue value) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      child: Text(value.description),
    );
  }

  Widget _buildValueRadio(context, FlushOperationalValue value) {
    return Radio<dynamic>(
        value: value.value,
        groupValue: selectedValue,
        onChanged: (_) => onSelect(value));
  }
}
