import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/routines/models/ceiling_presence_sensor_functions.dart';
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialog_function_list_tile.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/helpers/routine_tap_function_helper.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class CpsFunctionsList extends StatelessWidget {
  const CpsFunctionsList({
    required this.cpsFunctions,
    required this.device,
    required this.selectedFunctionData,
    required this.dialogType,
    super.key,
  });

  final List<CpsFunctions> cpsFunctions;
  final AllDevicesModel? device;
  final DeviceFunctionData? selectedFunctionData;
  final String dialogType;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 360,
      child: ListView.separated(
        shrinkWrap: false,
        itemCount: cpsFunctions.length,
        separatorBuilder: (context, index) => const Padding(
          padding: EdgeInsets.symmetric(horizontal: 40.0),
          child: Divider(color: ColorsManager.dividerColor),
        ),
        itemBuilder: (context, index) {
          final function = cpsFunctions[index];
          return RoutineDialogFunctionListTile(
              iconPath: function.icon,
              operationName: function.operationName,
              onTap: () {
                RoutineTapFunctionHelper.onTapFunction(
                  context,
                  step: function.step,
                  functionCode: function.code,
                  functionOperationName: function.operationName,
                  functionValueDescription:
                      selectedFunctionData?.valueDescription,
                  deviceUuid: device?.uuid,
                  codesToAddIntoFunctionsWithDefaultValue: [
                    'static_max_dis',
                    'presence_reference',
                    'moving_reference',
                    'perceptual_boundary',
                    'moving_boundary',
                    'moving_rigger_time',
                    'moving_static_time',
                    'none_body_time',
                    'moving_max_dis',
                    'moving_range',
                    'presence_range',
                    if (dialogType == "IF") 'sensitivity',
                  ],
                );
              });
        },
      ),
    );
  }
}
