
// src/main.js
import { initStorage } from './storage/index.js';
import { showSetupPage, hideSetupPage } from './setup.js';
import { setConfig } from './state.js';
import { startLauncher } from './starter.js';
import { initSafeArea } from './safearea.js';

document.addEventListener('DOMContentLoaded', async () => {
  initSafeArea();

  const Storage = await initStorage();
  const cfg = await Storage.loadConfig();

  if (!cfg) {
    await showSetupPage(Storage);
  } else {
    setConfig({ url: cfg.url, user: cfg.user, password: cfg.password });
    hideSetupPage();
    await startLauncher(Storage);
  }

  // 6 click per aprire la setup page
  let tapCount = 0;
  let tapTimer = null;
  document.addEventListener('click', async () => {
    tapCount++;
    if (tapTimer) clearTimeout(tapTimer);
    tapTimer = setTimeout(() => { tapCount = 0; }, 600);
    if (tapCount >= 6) {
      tapCount = 0;
      await showSetupPage(Storage);
    }
  });
});

