import React from "react";
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown";
import InputRange from "../../../ui/inputs/InputRange";
import { AnalysisPresetsType } from "../../../../types/analysis";

interface InputRendererProps {
  keyName: string;
  presets: AnalysisPresetsType[keyof AnalysisPresetsType];
  inputValues: Record<string, string>; // <-- Add this line
  onInputChange: (label: string, value: string) => void;
}

const RenderAnalysisInputs: React.FC<InputRendererProps> = ({ keyName, presets, inputValues, onInputChange }) => {

  return (
    <div key={`main-${keyName}`} className="analysis-inputs">
      {presets.map((preset, index) => {
        if (preset.type === "default") {
          return (
            <InputWithDropDown
              key={index}
              label={preset.inputs.label}
              value={preset.inputs.defaultValue?.toString() || inputValues[preset.inputs.label] || ""}
              activeOption={preset.inputs.activeOption}
              onChange={(newValue) => onInputChange(preset.inputs.label, newValue)}
            />
          );
        }
        if (preset.type === "range") {
          return (
            <InputRange
              key={index}
              label={preset.inputs.label}
              min={0}
              max={8}
              value={Number(preset.inputs.defaultValue) || Number(inputValues[preset.inputs.label]) || 5}
            />
          );
        }
        return null;
      })}
    </div>
  );
};

export default RenderAnalysisInputs;
