'use client';

import { QuestionType, QuestionParameters } from '@/types/quiz';
import { questionTypeConfigs, defaultQuestionTypeConfig } from '@/config/questionTypes';
import ParameterInput from './ParameterInput';

interface QuestionParameterFormProps {
  questionType: QuestionType;
  parameters: QuestionParameters;
  onParametersChange: (parameters: QuestionParameters) => void;
}

export default function QuestionParameterForm({
  questionType,
  parameters,
  onParametersChange,
}: QuestionParameterFormProps) {
  const updateParameter = (key: string, value: string | number | boolean | string[]) => {
    onParametersChange({ ...parameters, [key]: value });
  };

  // Get configuration for this question type, fallback to default
  const config = questionTypeConfigs[questionType.id] || defaultQuestionTypeConfig;

  return (
    <div className="space-y-4">
      {config.parameters.map((paramConfig) => (
        <ParameterInput
          key={paramConfig.key}
          config={paramConfig}
          value={parameters[paramConfig.key]}
          onChange={(value) => updateParameter(paramConfig.key, value)}
        />
      ))}
    </div>
  );
}