"use client"; import { useState, useRef, useEffect, type ReactNode } from "react"; const CORRECT = "2440"; interface Props { children: ReactNode; } export default function PinGate({ children }: Props) { const [unlocked, setUnlocked] = useState(false); const [digits, setDigits] = useState(["", "", "", ""]); const [shake, setShake] = useState(false); const [hint, setHint] = useState(""); const refs = [ useRef(null), useRef(null), useRef(null), useRef(null), ]; useEffect(() => { if (typeof window !== "undefined") { try { if (sessionStorage.getItem("bos_unlocked") === "1") setUnlocked(true); } catch { /* storage blocked */ } } }, []); useEffect(() => { if (!unlocked) setTimeout(() => refs[0].current?.focus(), 80); }, [unlocked]); function handleDigit(i: number, val: string) { const d = val.replace(/\D/g, "").slice(-1); const next = [...digits]; next[i] = d; setDigits(next); if (d && i < 3) refs[i + 1].current?.focus(); if (next.every(x => x !== "")) { const entered = next.join(""); if (entered === CORRECT) { try { sessionStorage.setItem("bos_unlocked", "1"); } catch { /* */ } setUnlocked(true); } else { setShake(true); setHint("Incorrect code."); setTimeout(() => { setShake(false); setHint(""); setDigits(["", "", "", ""]); refs[0].current?.focus(); }, 700); } } } function handleKeyDown(i: number, e: React.KeyboardEvent) { if (e.key === "Backspace" && !digits[i] && i > 0) { refs[i - 1].current?.focus(); const next = [...digits]; next[i - 1] = ""; setDigits(next); } } if (unlocked) return <>{children}; return (
{/* Gold grid */}
{/* Shield / BOS mark */}
Beryl Operating System
{/* Card */}
Restricted Access

Enter your 4-digit BOS code to continue.

{/* PIN inputs */}
{digits.map((d, i) => ( handleDigit(i, e.target.value)} onKeyDown={e => handleKeyDown(i, e)} style={{ width: 52, height: 60, textAlign: "center", fontSize: 24, fontFamily: "'Cinzel',serif", background: "rgba(255,255,255,.05)", border: `1px solid ${shake ? "rgba(220,60,60,.6)" : "rgba(200,169,81,.25)"}`, borderRadius: 8, color: "#f5e070", transition: "border-color .15s, box-shadow .15s", caretColor: "transparent", }} /> ))}
{hint && (
{hint}
)}
Authorized personnel only.
© 2026 Beryl AI Labs
); }