'use client' import { useRef } from 'react' import Image from 'next/image' import { ArrowDownTrayIcon, ArrowUpTrayIcon } from '@heroicons/react/24/outline' import { AppConfig } from '@/types/config' interface HeaderProps { startTime: string | null lastUpdated: string | null onExportConfig: () => AppConfig onImportConfig: (config: AppConfig) => void } export default function Header({ startTime, lastUpdated, onExportConfig, onImportConfig }: HeaderProps) { const fileInputRef = useRef(null) const handleExport = () => { const config = onExportConfig() const blob = new Blob([JSON.stringify(config, null, 2)], { type: 'application/json' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = 'mta-sign-config.json' a.click() URL.revokeObjectURL(url) } const handleImport = (event: React.ChangeEvent) => { const file = event.target.files?.[0] if (!file) return const reader = new FileReader() reader.onload = (e) => { try { const config = JSON.parse(e.target?.result as string) as AppConfig onImportConfig(config) } catch (err) { console.error('Failed to parse config file:', err) alert('Invalid config file') } } reader.readAsText(file) // Reset input so same file can be imported again if (fileInputRef.current) { fileInputRef.current.value = '' } } return ( ) }