import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './styles.css';

// 讀取隨網站部署的內容（若有），讓訪客第一次開啟就看到站長的設定
async function loadPublished() {
  try {
    const ctrl = new AbortController();
    const t = setTimeout(() => ctrl.abort(), 6000);
    const r = await fetch('site-data/site.json', { cache: 'no-cache', signal: ctrl.signal });
    clearTimeout(t);
    if (!r.ok) return null;
    const j = await r.json();
    return j && j.format === 'voyage-desk-site' && j.state ? j : null;
  } catch {
    return null;
  }
}

loadPublished().then((published) => {
  createRoot(document.getElementById('root')).render(<App published={published} />);
});
