---
import { getCollection, render } from 'astro:content';
import type { Locale } from '../i18n';
import { t } from '../i18n';

interface Props {
  locale: Locale;
}

const { locale } = Astro.props;
const strings = t(locale);

const all = await getCollection('landing', ({ id }) => id.startsWith(`${locale}/`));
const bySection = Object.fromEntries(all.map((e) => [e.data.section, e]));

const heroEntry = bySection['hero'];
const aboutEntry = bySection['about'];
const archEntry = bySection['architecture'];
const ctaEntry = bySection['install-cta'];

const Hero = heroEntry ? (await render(heroEntry)).Content : null;
const About = aboutEntry ? (await render(aboutEntry)).Content : null;
const Arch = archEntry ? (await render(archEntry)).Content : null;
const Cta = ctaEntry ? (await render(ctaEntry)).Content : null;

// Only set during ISO builds — shows the exact image version.
const isoVersion = import.meta.env.ASTRO_ISO_VERSION || null;
const isoTagUrl = isoVersion
  ? `https://code.smilepowered.org/clawdie/clawdie-iso/releases/tag/v${isoVersion}`
  : null;
---

<header class="hero">
  <div class="header-inner">
    <div class="brand-mark"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Clawdie"><path d="M32 11 53 50H11L32 11Z" fill="none" stroke="currentColor" stroke-width="3" stroke-linejoin="round"/><path d="M21.5 30.5 L42.5 30.5 L32 50 Z" fill="none" stroke="currentColor" stroke-width="3" stroke-linejoin="round"/></svg></div>
    <div class="header-text">
      <h1>Clawdie<br /><span>{locale === 'sl' ? 'AI v vaših rokah' : 'AI you own'}</span></h1>
      <p class="tagline">{strings.meta.description}</p>
    </div>
  </div>
</header>

<div class="hero-statement">
  {Hero && <Hero />}
</div>

{
  About && (
    <section class="landing-section" id="about">
      <h2>{aboutEntry?.data.title}</h2>
      <About />
    </section>
  )
}

{
  Arch && (
    <section class="landing-section" id="architecture">
      <h2>{archEntry?.data.title}</h2>
      <Arch />
    </section>
  )
}

{
  Cta && (
    <section class="landing-section" id="install">
      <h2>{ctaEntry?.data.title}</h2>
      <Cta />
    </section>
  )
}

{
  isoVersion && (
    <footer class="iso-version-badge">
      <p>
        Clawdie ISO {isoVersion} —{' '}
        <a href={isoTagUrl}>release notes</a>
      </p>
    </footer>
  )
}
