// Ortak arayüz parçaları: pencere (modal), onay/soru diyalogları, bildirimler, tema. import { X } from 'lucide-react'; import { type ReactNode, createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'; export function Modal({ title, onClose, children, wide }: { title: string; onClose: () => void; children: ReactNode; wide?: boolean }) { useEffect(() => { const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose(); window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [onClose]); return (
e.target === e.currentTarget && onClose()}>

{title}

{children}
); } interface PromptOptions { title: string; label?: string; initial?: string; placeholder?: string; confirmText?: string; } interface ConfirmOptions { title: string; message: string; confirmText?: string; danger?: boolean; } type Toast = { id: number; text: string; kind: 'error' | 'info' }; interface UiContext { prompt: (o: PromptOptions) => Promise; confirm: (o: ConfirmOptions) => Promise; toast: (text: string, kind?: 'error' | 'info') => void; /** Bir hatayı kullanıcıya bildirim olarak gösterir. */ fail: (err: unknown) => void; } const Ctx = createContext(null!); export const useUi = () => useContext(Ctx); type Dialog = | { kind: 'prompt'; options: PromptOptions; resolve: (v: string | null) => void } | { kind: 'confirm'; options: ConfirmOptions; resolve: (v: boolean) => void }; export function UiProvider({ children }: { children: ReactNode }) { const [dialog, setDialog] = useState(null); const [toasts, setToasts] = useState([]); const [value, setValue] = useState(''); const nextId = useRef(1); const prompt = useCallback((options: PromptOptions) => { setValue(options.initial ?? ''); return new Promise((resolve) => setDialog({ kind: 'prompt', options, resolve })); }, []); const confirm = useCallback( (options: ConfirmOptions) => new Promise((resolve) => setDialog({ kind: 'confirm', options, resolve })), [], ); const toast = useCallback((text: string, kind: 'error' | 'info' = 'info') => { const id = nextId.current++; setToasts((t) => [...t, { id, text, kind }]); setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), kind === 'error' ? 7000 : 3500); }, []); const fail = useCallback((err: unknown) => toast(err instanceof Error ? err.message : String(err), 'error'), [toast]); const close = (result: string | boolean | null) => { if (!dialog) return; (dialog.resolve as (v: unknown) => void)(result); setDialog(null); }; return ( {children} {dialog?.kind === 'prompt' && ( close(null)}>
{ e.preventDefault(); if (value.trim()) close(value.trim()); }}> {dialog.options.label && } setValue(e.target.value)} />
)} {dialog?.kind === 'confirm' && ( close(false)}>

{dialog.options.message}

)}
{toasts.map((t) =>
{t.text}
)}
); } // ---- Tema ---- export type Theme = 'light' | 'dark'; function readTheme(): Theme { try { const saved = localStorage.getItem('thoth:tema'); if (saved === 'light' || saved === 'dark') return saved; } catch { // depolama kapalı olabilir } return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; } export function useTheme(): [Theme, () => void] { const [theme, setTheme] = useState(readTheme); useEffect(() => { document.documentElement.dataset.theme = theme; }, [theme]); const toggle = () => setTheme((t) => { const next = t === 'dark' ? 'light' : 'dark'; try { localStorage.setItem('thoth:tema', next); } catch { // depolama kapalı olabilir } return next; }); return [theme, toggle]; } /** localStorage'da saklanan basit bir tercih. */ export function useStored(key: string, initial: T): [T, (v: T) => void] { const [value, setValue] = useState(() => { try { const raw = localStorage.getItem(key); return raw == null ? initial : (JSON.parse(raw) as T); } catch { return initial; } }); const set = (v: T) => { setValue(v); try { localStorage.setItem(key, JSON.stringify(v)); } catch { // depolama kapalı olabilir } }; return [value, set]; } /** * Thoth işareti: MitrÆnlil uygulama ikonu ailesindedir (yuvarlak köşeli zemin, kalın harf, sağ üstte "AI" rozeti). * Kırmızı zemin + beyaz harf; rozet küçük boyutlarda okunmadığı için 30 pikselin altında gösterilmez. */ export function Logo({ size = 28 }: { size?: number }) { const badge = size >= 30; return ( ); } /** MitrÆnlil iletişim adresi. */ export function Contact({ className = 'contact' }: { className?: string }) { return İletişim: bilgi@mitranlil.tr; } /** Kurumsal imza: "bir MitrÆnlil ürünü" (Æ kırmızı). */ export function BrandBy({ className = 'brand-by' }: { className?: string }) { return bir MitrÆnlil ürünü; }