'use client';

import React, { ChangeEvent } from 'react';
import BaseFormField, { getInputClasses } from './BaseFormField';

interface SelectOption {
  value: string | number;
  label: string;
}

interface FormSelectProps {
  label: string;
  name: string;
  value: string | number;
  onChange: (e: ChangeEvent<HTMLSelectElement>) => void;
  onBlur?: (e: ChangeEvent<HTMLSelectElement>) => void;
  options: SelectOption[];
  error?: string;
  touched?: boolean;
  placeholder?: string;
  required?: boolean;
  disabled?: boolean;
  className?: string;
}

/**
 * Composant de select de formulaire réutilisable
 */
export default function FormSelect({
  label,
  name,
  value,
  onChange,
  onBlur,
  options,
  error,
  touched,
  placeholder,
  required = false,
  disabled = false,
  className = '',
}: FormSelectProps) {
  return (
    <BaseFormField
      label={label}
      name={name}
      required={required}
      error={error}
      touched={touched}
      className={className}
    >
      <select
        id={name}
        name={name}
        value={value}
        onChange={onChange}
        onBlur={onBlur}
        disabled={disabled}
        required={required}
        className={getInputClasses(!!touched && !!error)}
      >
        {placeholder && (
          <option value="" disabled>
            {placeholder}
          </option>
        )}
        {options.map((option) => (
          <option key={option.value} value={option.value}>
            {option.label}
          </option>
        ))}
      </select>
    </BaseFormField>
  );
}
