import type { InputHTMLAttributes } from 'react';
import { Champ, CLASSES_CHAMP, type ChampCommun } from './Champ';
import { cx } from './cx';

export interface InputProps
  extends
    ChampCommun,
    Omit<InputHTMLAttributes<HTMLInputElement>, 'aria-describedby' | 'aria-invalid'> {}

export function Input({
  id,
  label,
  hint,
  error,
  requiredLabel,
  required,
  className,
  ...props
}: InputProps) {
  return (
    <Champ
      id={id}
      label={label}
      hint={hint}
      error={error}
      required={required}
      requiredLabel={requiredLabel}
    >
      {(attributs) => (
        <input
          {...props}
          {...attributs}
          required={required}
          className={cx(CLASSES_CHAMP, className)}
        />
      )}
    </Champ>
  );
}
