interface SecretInputProps {
  secret: string
  secretVisible: boolean
  secretError: string | null
  disabled: boolean
  onChange: (value: string) => void
  onToggleVisible: () => void
}

export default function SecretInput({
  secret,
  secretVisible,
  secretError,
  disabled,
  onChange,
  onToggleVisible,
}: SecretInputProps) {
  return (
    <div className="space-y-1.5">
      <label className="block text-sm font-medium text-gray-300">Cle d&apos;acces</label>
      <div className="relative">
        <input
          type={secretVisible ? 'text' : 'password'}
          value={secret}
          onChange={(e) => onChange(e.target.value)}
          placeholder="Entrez la cle secrete..."
          disabled={disabled}
          className={`w-full bg-black-800 border rounded-xl px-4 py-2.5 pr-12
                     text-gray-100 placeholder-gray-500 text-sm
                     focus:outline-none focus:ring-2 focus:border-white/50
                     disabled:opacity-50 disabled:cursor-not-allowed transition
                     ${secretError
                       ? 'border-red-500/70 focus:ring-red-500/50'
                       : 'border-white/30 focus:ring-white/50'
                     }`}
        />
        <button
          type="button"
          onClick={onToggleVisible}
          aria-label={secretVisible ? 'Masquer la cle' : 'Afficher la cle'}
          className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300 transition"
          tabIndex={-1}
        >
          {secretVisible ? (
            <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
              <path strokeLinecap="round" strokeLinejoin="round" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21" />
            </svg>
          ) : (
            <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
              <path strokeLinecap="round" strokeLinejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
              <path strokeLinecap="round" strokeLinejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
            </svg>
          )}
        </button>
      </div>
      {secretError && (
        <p className="text-xs text-red-400 mt-1">{secretError}</p>
      )}
    </div>
  )
}
