"use client"; import Image from "next/image"; import Link from "next/link"; import Script from "next/script"; import { useTranslations } from "next-intl"; import { useActionState, useState } from "react"; import { register } from "@/actions/register"; interface RegisterFormProps { hotelName: string; captcha: { provider: string; siteKey?: string }; error?: string; nonce?: string; } function passwordStrength(pw: string): { score: number; label: string; color: string; } { let score = 0; if (pw.length >= 8) score += 1; if (pw.length >= 12) score += 1; if (/[a-z]/.test(pw) && /[A-Z]/.test(pw)) score += 1; if (/\d/.test(pw)) score += 1; if (/[^a-zA-Z0-9]/.test(pw)) score += 1; if (score <= 1) return { score, label: "Weak", color: "#ef4444" }; if (score <= 2) return { score, label: "Fair", color: "#f59e0b" }; if (score <= 3) return { score, label: "Good", color: "#22c55e" }; return { score: 5, label: "Strong", color: "#16a34a" }; } export function RegisterForm({ hotelName, captcha, error, nonce, }: RegisterFormProps) { const t = useTranslations("pages.register"); const showCaptcha = captcha.provider !== "none" && !!captcha.siteKey; const [serverError, formAction, isPending] = useActionState(register, null); const [termsAccepted, setTermsAccepted] = useState(false); const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [showConfirm, setShowConfirm] = useState(false); const strength = passwordStrength(password); return (
{showCaptcha && captcha.provider === "turnstile" ? (