// SPDX-License-Identifier: AGPL-3.0-or-later // Copyright (C) 2026 Karim Gabriele Varano import { useEffect, useState } from 'react' import { onMessage, notifyReady } from './lib/rhinoBridge' import { BarToggle, BAR_H } from './components/BarControls' function send(type, payload = {}) { if (!window.RHINO_MODE) { console.log('[LayoutDialog] →', type, payload); return } document.title = 'RHINOMSG::' + JSON.stringify({ type, payload }) } const PAPER_SIZES = ['A4', 'A3', 'A2', 'A1', 'A0', 'Letter'] const pillInput = { height: BAR_H, background: 'var(--bg-input)', border: '1px solid var(--border)', borderRadius: 999, color: 'var(--text-primary)', fontSize: 11, fontFamily: 'var(--font)', padding: '0 10px', outline: 'none', boxSizing: 'border-box', } export default function LayoutDialogApp() { const initial = (typeof window !== 'undefined' && window.PANEL_PARAMS) || {} const [mode, setMode] = useState(initial.mode || 'new') const [layout, setLayout] = useState(initial.layout || null) const [name, setName] = useState('') const [format, setFormat] = useState('A3') const [landscape, setLandscape] = useState(true) const [cw, setCw] = useState('420') const [ch, setCh] = useState('297') useEffect(() => { onMessage('LAYOUT_DIALOG_STATE', (p) => { if (p.mode) setMode(p.mode) if (p.layout) { setLayout(p.layout) if (p.mode === 'edit') { setFormat('custom') setCw(String(Math.round(p.layout.width || 420))) setCh(String(Math.round(p.layout.height || 297))) } } }) notifyReady() const blockContext = (ev) => ev.preventDefault() document.addEventListener('contextmenu', blockContext) return () => document.removeEventListener('contextmenu', blockContext) }, []) const editing = mode === 'edit' const submit = () => { const payload = { name: name.trim(), format, landscape } if (format === 'custom') { const w = parseFloat(cw), h = parseFloat(ch) if (!(w > 0) || !(h > 0)) { alert('Bitte gültige Größe eingeben.'); return } payload.customWidth = w payload.customHeight = h } send('SAVE', payload) } return (