import { useEffect, useRef } from 'react' import { FolderOpen, Wrench, X } from 'lucide-react' import { AccountSettings } from './AccountSettings' import { LauncherUpdateSettings } from './LauncherUpdateSettings' import type { useAccount } from '../hooks/useAccount' import type { useSettings } from '../hooks/useSettings' import type { useLauncherUpdate } from '../hooks/useLauncherUpdate' import type { JavaInstallation, NativeHost } from '../types/launcher' interface SettingsDrawerProps { open: boolean locked: boolean host: NativeHost | null java: JavaInstallation | null | undefined preferences: ReturnType session: ReturnType updater: ReturnType onClose: () => void } export function SettingsDrawer({ open, locked, host, java, preferences, session, updater, onClose }: SettingsDrawerProps) { const { settings, loaded, saving, error } = preferences const closeButton = useRef(null) useEffect(() => { if (!open) return const previous = document.activeElement closeButton.current?.focus() const onKey = (event: KeyboardEvent) => { if (event.key === 'Escape') onClose() if (event.key !== 'Tab') return const elements = closeButton.current?.closest('aside')?.querySelectorAll('button:not(:disabled), input:not(:disabled), select:not(:disabled), summary') const first = elements?.[0] const last = elements?.[elements.length - 1] if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last?.focus() } else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first?.focus() } } document.addEventListener('keydown', onKey) return () => { document.removeEventListener('keydown', onKey) if (previous instanceof HTMLElement) previous.focus() } }, [open, onClose]) return ( <>
) }