"use client" import { useState } from "react" import { Eye, EyeOff } from "lucide-react" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { evaluatePasswordStrength, passwordsMatch, type PasswordStrengthLevel, } from "@/lib/auth/password-strength" import { cn } from "@/lib/utils" type PasswordFieldBlockProps = { id: string label: string value: string error?: string required?: boolean autoComplete: "new-password" | "current-password" onChange: (value: string) => void /** Show strength meter (signup password). */ showStrength?: boolean /** Compare with primary password (signup confirmation). */ compareWith?: string } const STRENGTH_SEGMENTS: PasswordStrengthLevel[] = [ "weak", "fair", "good", "strong", ] const STRENGTH_ACTIVE: Record, string> = { weak: "bg-destructive", fair: "bg-amber-500", good: "bg-emerald-500", strong: "bg-emerald-600", } export function PasswordFieldBlock({ id, label, value, error, required, autoComplete, onChange, showStrength = false, compareWith, }: PasswordFieldBlockProps) { const [visible, setVisible] = useState(false) const strength = evaluatePasswordStrength(value) const match = compareWith !== undefined ? passwordsMatch(compareWith, value) : null const activeSegments = strength.level === "empty" ? 0 : strength.level === "weak" ? 1 : strength.level === "fair" ? 2 : strength.level === "good" ? 3 : 4 return (
onChange(event.target.value)} className="h-10 rounded-lg pr-10" />
{showStrength && value ? (
{STRENGTH_SEGMENTS.map((level, index) => ( ))}

Robustesse :{" "} {strength.label}

) : null} {match !== null ? (

{match ? "Les mots de passe correspondent." : "Les mots de passe ne correspondent pas."}

) : null} {error ? (

{error}

) : null}
) }