// Main app. Wires everything together.

const {
  buildLots, computeLotState, LotProgressBar,
  Hero, TopBar, WhyAI, Clients, VideoGallery, Testimonials, Schedule, Instructor, Guarantee, Certificate, FAQ, FinalCTA, Footer,
  TweaksPanel,
} = window;

// Tweakable defaults — wrapped in EDITMODE markers so host can persist.
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "simulatedDate": "",
  "eventDates": "23 e 24 de maio",
  "accent": "#f6f4ef",
  "accentPreset": "white",
  "titleFont": "Space Grotesk",
  "crystal": "1",
  "lots": [
    { "ini": "2026-04-20T01:00:00", "fim": "2026-04-23T23:59:00", "preco": 19, "url": "https://pay.kiwify.com.br/MLkFs6A" },
    { "ini": "2026-04-24T00:00:00", "fim": "2026-04-28T23:59:00", "preco": 21, "url": "https://pay.kiwify.com.br/8ZMumPb" },
    { "ini": "2026-04-29T00:00:00", "fim": "2026-04-30T23:59:00", "preco": 25, "url": "https://pay.kiwify.com.br/oKpoCxQ" },
    { "ini": "2026-05-01T00:00:00", "fim": "2026-05-05T23:59:00", "preco": 29, "url": "https://pay.kiwify.com.br/QNQa9Oh" },
    { "ini": "2026-05-06T00:00:00", "fim": "2026-05-07T23:59:00", "preco": 31, "url": "https://pay.kiwify.com.br/pBCTMSI" },
    { "ini": "2026-05-08T00:00:00", "fim": "2026-05-12T23:59:00", "preco": 34, "url": "https://pay.kiwify.com.br/oj1Sp5Z" },
    { "ini": "2026-05-13T00:00:00", "fim": "2026-05-14T23:59:00", "preco": 37, "url": "https://pay.kiwify.com.br/9pUTEEK" },
    { "ini": "2026-05-15T00:00:00", "fim": "2026-05-19T23:59:00", "preco": 39, "url": "https://pay.kiwify.com.br/1qtx468" },
    { "ini": "2026-05-20T00:00:00", "fim": "2026-05-22T23:59:00", "preco": 45, "url": "https://pay.kiwify.com.br/vGg79H5" }
  ]
}/*EDITMODE-END*/;

// Video URLs (from the reference site — they're the product owner's own videos)
const MEDIA = {
  heroVideo: 'assets/hero.mp4',
  ambientLoop: 'https://ofilmboss.com/wp-content/uploads/2025/12/Volvo-Base-Com-Cor-Davinci-V6-Completo.mp4',
  instructorVideo: 'https://ofilmboss.com/wp-content/uploads/2025/06/11bedcdf-7839-44ef-9178-ac28667a218e.mp4',
  videos: [
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Warrio-6061-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Sport-Tv-4K-V5-1.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Two-2D-5948-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Dj-Boy-5995-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-A-Stylized-5953-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251209-Image-To-Video-The-Boy-Fr-237-0-1.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Yellow-6026-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Volvo-Base-Com-Cor-Davinci-V6-Completo.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Ia-Boss-Apple-24H-Video-Pronto.mp4',
  ],
  cornerLoops: [
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Warrio-6061-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Dj-Boy-5995-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251208-Image-To-Video-The-Yellow-6026-0.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/Kling-20251209-Image-To-Video-The-Boy-Fr-237-0-1.mp4',
  ],
  studentVideos: [
    'https://ofilmboss.com/wp-content/uploads/2025/12/01-Animacao-Completa.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/02-Pimenta-V2.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/03-Chaves.mp4',
    'https://ofilmboss.com/wp-content/uploads/2025/12/04-Chocotone-V3.mp4',
  ],
  testimonialShots: [
    'https://ofilmboss.com/wp-content/uploads/2025/06/6d6410d4-b0c7-4bdb-8e54-478e6ecfce76.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/81f3be90-2213-468b-9543-3a51b2677f49.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/a5e16d6b-9da9-45cc-b023-8b84f8299dc4.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/d8a17514-f167-4416-98a6-fc7a68f431aa.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/b5632eb0-7cd7-463c-82a6-7d7920651c10.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/eb53d3d1-4a41-4de3-bb75-888599a06454.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/f1b84ce4-b325-435d-af8e-ed49616928a3.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/e20fdd15-8098-4de0-a08a-248cb973f4ce.png',
    'https://ofilmboss.com/wp-content/uploads/2025/06/da3bc07e-ebfe-4d3a-8b9b-ba23d5a94c4d.png',
  ],
};

function App() {
  const [config, setConfig] = React.useState(TWEAK_DEFAULTS);

  // Live clock — ticks once per second
  const [now, setNow] = React.useState(() => Date.now());
  React.useEffect(() => {
    const id = setInterval(() => setNow(Date.now()), 1000);
    return () => clearInterval(id);
  }, []);

  // If simulatedDate is set, use midday BRT of that date for "now"
  const effectiveNow = React.useMemo(() => {
    if (config.simulatedDate) {
      const [y, m, d] = config.simulatedDate.split('-').map(Number);
      // noon BRT = 15:00 UTC
      return Date.UTC(y, m - 1, d, 15, 0, 0, 0);
    }
    return now;
  }, [config.simulatedDate, now]);

  // Apply accent to CSS var
  React.useEffect(() => {
    document.documentElement.style.setProperty('--accent', config.accent);
    document.documentElement.style.setProperty(
      '--accent-dim',
      config.accent.startsWith('oklch')
        ? config.accent.replace(')', ' / 0.15)')
        : config.accent + '26'
    );
  }, [config.accent]);

  const schedule = React.useMemo(
    () => buildLots(config.lots),
    [config.lots]
  );

  // Apply title font
  React.useEffect(() => {
    document.documentElement.style.setProperty(
      '--font-display',
      `'${config.titleFont}', system-ui, sans-serif`
    );
  }, [config.titleFont]);

  const mergedConfig = { ...config, ...MEDIA };

  return (
    <>
      <Hero
        schedule={schedule}
        now={effectiveNow}
        checkoutUrl={config.checkoutUrl}
        config={mergedConfig}
      />
      <WhyAI config={mergedConfig} />
      <Clients />
      <VideoGallery config={mergedConfig} checkoutUrl={config.checkoutUrl} schedule={schedule} now={effectiveNow} />
      <Testimonials config={mergedConfig} />
      <Schedule config={mergedConfig} />
      <Instructor config={mergedConfig} />
      <Guarantee />
      <Certificate />
      <FAQ />
      <FinalCTA
        schedule={schedule}
        now={effectiveNow}
        checkoutUrl={config.checkoutUrl}
        config={mergedConfig}
      />
      <Footer />
      <TweaksPanel config={config} setConfig={setConfig} tweakDefaults={TWEAK_DEFAULTS} />
    </>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
