import { render, h, Fragment } from 'preact';
import { useState } from 'preact/hooks';
import htm from 'htm';
const html = htm.bind(h);
// --- 1. STYLES (Keep the "ugly" strings out of your logic) ---
const styles = {
terminal: "padding: 20px; background: #000; color: #0f0; font-family: 'Courier New', monospace; min-height: 100vh;",
inputField: "background: #000; color: #0f0; border: 1px solid #0f0; font-family: monospace; outline: none; padding: 5px; width: 200px;",
btn: "background: #0f0; color: #000; border: none; padding: 10px 30px; font-weight: bold; cursor: pointer; margin-top: 10px;"
};
// --- 2. SUB-COMPONENTS (Modular parts) ---
const Header = () => html`
<h1 style="text-decoration: underline; margin-top: 0;">FREEBSD TS-CONSOLE</h1>
`;
const DisplayValue = ({ count }) => html`
<p style="font-size: 2rem; margin: 10px 0;">VALUE: [ ${count} ]</p>
`;
const TerminalInput = ({ text, onInput }) => html`
<div style="margin-bottom: 20px;">
<label>> COMMAND: </label>
<input
type="text"
value=${text}
onInput=${(e) => onInput(e.target.value)}
style=${styles.inputField}
autoFocus
/>
<p style="color: #0a0; font-size: 0.8rem;">LAST_INPUT: ${text || 'NONE'}</p>
</div>
`;
// --- 3. MAIN APP (Clean and readable) ---
export function App() {
const [count, setCount] = useState(0);
const [text, setText] = useState("");
return html`
<section style=${styles.terminal}>
<${Header} />
<${DisplayValue} count=${count} />
<${TerminalInput} text=${text} onInput=${setText} />
<button style=${styles.btn} onClick=${() => setCount(count + 1)}>
INC_COUNTER
</button>
</section>
`;
}
render(html`<${App} />`, document.getElementById('app')!);