/* global React */ const { useState, useRef, useEffect } = React; const HEADER_DOMAINS = [ { id: 'inner', label: 'Inner World', color: 'var(--axis-inner)' }, { id: 'physical', label: 'Physical', color: 'var(--axis-physical)' }, { id: 'creative', label: 'Creative', color: 'var(--axis-creative)' }, { id: 'interpersonal', label: 'Interpersonal', color: 'var(--axis-interpersonal)' }, { id: 'adventure', label: 'Adventure', color: 'var(--axis-adventure)' }, { id: 'admin', label: 'Life Admin', color: 'var(--axis-life-admin)' }, ]; const NEW_ENTRY_OPTIONS = [ { id: 'action', label: 'Action' }, { id: 'practice', label: 'Practice' }, { id: 'log', label: 'Daily Log' }, ]; /* ── Shared drawer hook ──────────────────────────────────────────────────── */ function useDrawer(drawerRef, onClose) { useEffect(() => { const onMouse = (e) => { if (drawerRef.current && !drawerRef.current.contains(e.target)) onClose(); }; const onKey = (e) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('mousedown', onMouse); document.addEventListener('keydown', onKey); return () => { document.removeEventListener('mousedown', onMouse); document.removeEventListener('keydown', onKey); }; }, [onClose]); } /* ── ActionDrawer ────────────────────────────────────────────────────────── */ const ActionDrawer = ({ onClose }) => { const [title, setTitle] = useState(''); const [desc, setDesc] = useState(''); const [saving, setSaving] = useState(false); const drawerRef = useRef(null); const titleRef = useRef(null); useDrawer(drawerRef, onClose); useEffect(() => { titleRef.current?.focus(); }, []); const handleSubmit = () => { if (!title.trim() || saving) return; setSaving(true); fetch('/api/actions', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ai_refined_title: title.trim(), ai_refined_description: desc.trim() || null, origin_snippet: title.trim(), domain: 'admin', score: 0.55, horizon_state: 'focus_zone', }), }) .then(() => { window.dispatchEvent(new CustomEvent('soulitics:board-refresh')); setSaving(false); onClose(); }) .catch(() => setSaving(false)); }; return ( <>