"use client"; import { useState, useTransition } from "react"; import { Save } from "lucide-react"; import { saveSettings } from "@/app/admin/settings/actions"; import type { Settings } from "@/lib/settings"; // ── Small primitives ────────────────────────────────────────────────────────── const inputStyle = { border: "2px solid var(--border)", background: "var(--background)", outline: "none", width: "100%", padding: "0.5rem 0.75rem", fontSize: "0.875rem", fontFamily: "inherit", } as React.CSSProperties; const focusHandlers = { onFocus: (e: React.FocusEvent) => (e.currentTarget.style.borderColor = "var(--foreground)"), onBlur: (e: React.FocusEvent) => (e.currentTarget.style.borderColor = "var(--border)"), }; function Section({ title, hint, children, }: { title: string; hint?: string; children: React.ReactNode; }) { return (

{title}

{hint && (

{hint}

)}
{children}
); } function Field({ label, hint, children, }: { label: string; hint?: string; children: React.ReactNode; }) { return (
{hint && (

{hint}

)} {children}
); } function Toggle({ label, hint, checked, onChange, }: { label: string; hint?: string; checked: boolean; onChange: (v: boolean) => void; }) { return (

{label}

{hint && (

{hint}

)}
); } function SelectField({ label, hint, value, onChange, options, }: { label: string; hint?: string; value: string; onChange: (v: string) => void; options: { value: string; label: string }[]; }) { return ( ); } // ── Main form ───────────────────────────────────────────────────────────────── export function SettingsForm({ initial }: { initial: Settings }) { const [s, setS] = useState(initial); const [saved, setSaved] = useState(false); const [pending, startTransition] = useTransition(); function set(key: keyof Settings, value: string) { setS((prev) => ({ ...prev, [key]: value })); } function bool(key: keyof Settings) { return s[key] === "true"; } function handleSave() { startTransition(async () => { await saveSettings(s); setSaved(true); setTimeout(() => setSaved(false), 2000); }); } return (
{/* Save button */}
{/* ── 1. Основное ── */}
set("schoolName", e.target.value)} style={inputStyle} {...focusHandlers} />