---
const currentPath = Astro.url.pathname;
const base = import.meta.env.BASE_URL.replace(/\/?$/, '/');

const navLinks = [
  { label: 'Posts', href: base },
];

function isActive(href: string): boolean {
  return currentPath === href || currentPath.startsWith(base + 'posts/');
}
---

<nav aria-label="Site navigation">
  <div class="nav-inner">
    <a href={base} class="site-name">Crash Test Dev</a>
    <div class="nav-links">
      {navLinks.map((link) => (
        <a
          href={link.href}
          class:list={['nav-link', { active: isActive(link.href) }]}
          aria-current={isActive(link.href) ? 'page' : undefined}
        >
          {link.label}
        </a>
      ))}
    </div>
  </div>
</nav>

<style>
  nav {
    border-bottom: 1px solid var(--border-subtle);
    position: static;
  }

  .nav-inner {
    max-width: var(--width-container);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--gutter);
    padding-right: var(--gutter);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .site-name {
    font-family: var(--font-structure);
    font-size: var(--type-base);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    text-decoration: none;
  }

  .site-name:hover {
    color: var(--accent-primary);
  }

  .nav-links {
    display: flex;
    gap: var(--space-4);
  }

  .nav-link {
    font-family: var(--font-structure);
    font-size: var(--type-sm);
    font-weight: 400;
    color: var(--text-secondary);
    text-decoration: none;
  }

  .nav-link:hover {
    color: var(--text-primary);
  }

  .nav-link.active {
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-color: var(--accent-primary);
    text-decoration-thickness: 2px;
    text-underline-offset: 6px;
  }

  @media (max-width: 599px) {
    .nav-inner {
      flex-direction: column;
      gap: var(--space-1);
      text-align: center;
    }

    .nav-links {
      gap: var(--space-3);
    }
  }
</style>