import React, { useEffect, useState } from 'react'; import { HiLockClosed, HiMiniLockOpen } from 'react-icons/hi2'; import { clsx } from 'clsx'; import { getConsoleEmitter } from '../../console/ConsoleEmitter'; import { ConsoleEventType } from '../../console/context'; import { Button, NonIdealState } from '../../daisy'; import { useAuthStore } from './AuthStore'; import { getAuthAction } from './getAuthAction'; export const AuthLockOverlay = () => { const { unlock } = getAuthAction(); const [locked, setLock] = useState(false); const expired = useAuthStore((s) => { return s.status === 'Expired'; }); const [hidden, setHidden] = useState(!expired); const [pin, setPin] = useState(''); useEffect(() => { if (locked) { setPin(Math.random().toString().slice(-4)); setHidden(false); } }, [locked]); const emitter = getConsoleEmitter(); useEffect(() => { return emitter.on(ConsoleEventType.Lock, () => { setLock(true); }); }, [emitter]); if (hidden || expired) { return null; } return ( ); };