'use client';

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

interface FormFieldProps {
  label: string;
  name: string;
  type?: 'text' | 'email' | 'password' | 'tel' | 'number' | 'date';
  value: string | number;
  onChange: (e: ChangeEvent<HTMLInputElement>) => void;
  onBlur?: (e: ChangeEvent<HTMLInputElement>) => void;
  error?: string;
  touched?: boolean;
  placeholder?: string;
  required?: boolean;
  disabled?: boolean;
  className?: string;
  autoComplete?: string;
}

/**
 * Composant de champ de formulaire réutilisable
 */
export default function FormField({
  label,
  name,
  type = 'text',
  value,
  onChange,
  onBlur,
  error,
  touched,
  placeholder,
  required = false,
  disabled = false,
  className = '',
  autoComplete,
}: FormFieldProps) {
  return (
    <BaseFormField
      label={label}
      name={name}
      required={required}
      error={error}
      touched={touched}
      className={className}
    >
      <input
        id={name}
        name={name}
        type={type}
        value={value}
        onChange={onChange}
        onBlur={onBlur}
        placeholder={placeholder}
        disabled={disabled}
        required={required}
        autoComplete={autoComplete}
        className={getInputClasses(!!touched && !!error)}
      />
    </BaseFormField>
  );
}
