"use client"; import { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Lock, Eye, EyeOff } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; interface PasswordGateProps { onUnlock: (password: string) => void | Promise; errorMessage?: string; } export function PasswordGate({ onUnlock, errorMessage }: PasswordGateProps) { const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [localError, setLocalError] = useState(""); const [submitting, setSubmitting] = useState(false); const handleUnlock = async () => { if (!password.trim()) { setLocalError("Enter the password to continue."); return; } setSubmitting(true); setLocalError(""); try { await onUnlock(password); } finally { setSubmitting(false); } }; return (

Password required

This snippet is password-protected. Enter the password to view it.

{ setPassword(e.target.value); setLocalError(""); }} onKeyDown={(e) => e.key === "Enter" && handleUnlock()} className="pr-10 h-11 bg-muted/50 border-border/50 focus:border-amber-500/50" />
{(localError || errorMessage) && ( {localError || errorMessage} )}
); }