import React, { useEffect, useCallback } from 'react'; import { useUIStore } from '../../stores/uiStore'; interface ModalProps { isOpen: boolean; onClose: () => void; title?: string; children: React.ReactNode; maxWidth?: string; size?: 'settings'; /** Mobile display style: 'fullscreen' fills the screen, 'sheet' anchors to bottom, 'default' stays centered */ mobileStyle?: 'fullscreen' | 'sheet' | 'default'; } export function Modal({ isOpen, onClose, title, children, maxWidth = 'max-w-md', size, mobileStyle = 'default' }: ModalProps) { const isMobile = useUIStore((s) => s.isMobile); const handleKeyDown = useCallback((e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } }, [onClose]); useEffect(() => { if (isOpen) { document.addEventListener('keydown', handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown); } }, [isOpen, handleKeyDown]); if (!isOpen) return null; // Mobile fullscreen style if (isMobile && mobileStyle === 'fullscreen') { return (