---
import Base from './Base.astro';
import Nav from '../components/Nav.astro';
import Footer from '../components/Footer.astro';
import GuidesSidebar from '../components/GuidesSidebar.astro';
import GuideNav from '../components/GuideNav.astro';
import { guidesNav } from '../data/guidesNav';

interface Props {
  title: string;
  description: string;
  subtitle: string;
  readTime: string;
}

const { title, description, subtitle, readTime } = Astro.props;
const currentPath = Astro.url.pathname;

function normalize(path: string): string {
  return path.replace(/\/index\.html$/, '/').replace(/\.html$/, '/').replace(/\/$/, '') || '/';
}

const currentIndex = guidesNav.findIndex((item) => normalize(currentPath) === normalize(item.href));

const prev = currentIndex > 0 ? guidesNav[currentIndex - 1] : undefined;
const next = currentIndex < guidesNav.length - 1 ? guidesNav[currentIndex + 1] : undefined;
---

<Base
  title={`${title} - Agent of Empires`}
  description={description}
>
  <Nav />
  <div class="docs-layout">
    <GuidesSidebar />
    <main class="docs-content">
      <header class="mb-12 guide-header-banner pb-8">
        <div class="flex items-center gap-3 mb-4">
          <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-accent-600/10 text-accent-500 border border-accent-600/20">Guide</span>
          <span class="text-gray-500 text-sm">{readTime}</span>
        </div>
        <h1 class="text-4xl md:text-5xl font-bold text-white mb-6 leading-tight font-display">{title}</h1>
        <p class="text-lg text-gray-400 leading-relaxed">{subtitle}</p>
      </header>

      <div class="prose-content">
        <slot />
      </div>

      <GuideNav
        prev={prev ? { label: prev.title, href: prev.href } : undefined}
        next={next ? { label: next.title, href: next.href } : undefined}
      />
    </main>
  </div>
  <Footer />
</Base>
