---
import type { CollectionEntry } from "astro:content";

interface Props {
  children: CollectionEntry<"blog">[];
  currentId?: string;
  parent?: CollectionEntry<"blog">;
  sidebar?: boolean;
}

const { children, currentId, parent, sidebar = false } = Astro.props;
---

<aside class:list={["series", { "series--sidebar": sidebar }]}>
  <p class="series__heading">Parts in Series:</p>
  <ol class="series__list">
    {
      parent &&
        (parent.id === currentId ? (
          <li class="series__item">
            <span
              class="series__link series__link--current"
              aria-current="page"
            >
              {parent.data.title}
            </span>
          </li>
        ) : (
          <li class="series__item">
            <a href={`/blog/${parent.id}`} class="series__link">
              {parent.data.title}
            </a>
          </li>
        ))
    }
    {
      children.map((child) =>
        child.id === currentId ? (
          <li class="series__item">
            <span
              class="series__link series__link--current"
              aria-current="page"
            >
              {child.data.title}
            </span>
          </li>
        ) : (
          <li class="series__item">
            <a href={`/blog/${child.id}`} class="series__link">
              {child.data.title}
            </a>
          </li>
        ),
      )
    }
  </ol>
</aside>

<style>
  /* ── Inline variant (bottom of article) ── */
  .series {
    margin-top: 3rem;
    padding: 1.25rem 1.5rem;
    border-top: 2px solid #111;
    background: #eeeeed;
    border-radius: 4px;
    margin-bottom: 1rem;
  }

  .series__heading {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #888;
    margin-bottom: 0.75rem;
  }

  /* ── Sidebar variant ── */
  .series--sidebar {
    margin-top: 1.5rem;
    padding: 0;
    background: none;
    border-radius: 4px;
    background: #eeeeed;
    border-top: 2px solid #111;
    padding: 0.75rem 0.75rem;
  }

  .series__parent {
    display: block;
    font-size: 0.8rem;
    color: #555;
    text-decoration: none;
    margin-bottom: 0.5rem;
    line-height: 1.4;
  }

  .series__parent:hover {
    color: var(--accent);
  }

  .series__list {
    padding-left: 1.25rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  .series--sidebar .series__list {
    padding-left: 1.1rem;
  }

  .series__item {
    font-size: 0.9rem;
  }

  .series--sidebar .series__item {
    font-size: 0.8rem;
  }

  .series__link {
    color: #333;
    text-decoration: none;
    text-underline-offset: 3px;
    line-height: 1.4;
    display: block;
  }

  .series__link:hover {
    color: var(--accent);
    text-decoration: underline;
  }

  .series__link--current {
    color: var(--accent);
    font-weight: 500;
  }

  .series__link--current:hover {
    text-decoration: none;
  }
</style>
