---
export interface Props {
  tableOfContents?: Array<{
    id: string;
    title: string;
  }>;
}

const { tableOfContents = [] } = Astro.props;

// Создаем Map id -> номер
const idToNumber = new Map();
tableOfContents.forEach((item, index) => {
  idToNumber.set(item.id, index + 1);
});
---

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

<style>
  .numbered-content {
    color: #111827;
    line-height: 1.8;
  }

  .numbered-content :global(h2) {
    font-size: 1.875rem;
    font-weight: 700;
    color: #111827;
    margin-top: 2.5rem;
    margin-bottom: 1.25rem;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  /* Нумерация через CSS счетчик */
  .numbered-content {
    counter-reset: section;
  }

  .numbered-content :global(h2) {
    counter-increment: section;
  }

  .numbered-content :global(h2)::before {
    content: counter(section);
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
  }

  .numbered-content :global(h3) {
    font-size: 1.5rem;
    font-weight: 600;
    color: #111827;
    margin-top: 2rem;
    margin-bottom: 1rem;
  }

  .numbered-content :global(p) {
    color: #374151;
    margin-bottom: 1.25rem;
    font-size: 1.125rem;
    line-height: 1.8;
  }

  .numbered-content :global(ul),
  .numbered-content :global(ol) {
    padding-left: 1.5rem;
    margin-bottom: 1.5rem;
  }

  .numbered-content :global(ul) {
    list-style-type: disc;
  }

  .numbered-content :global(ol) {
    list-style-type: decimal;
  }

  .numbered-content :global(li) {
    color: #374151;
    margin-bottom: 0.75rem;
    font-size: 1.125rem;
    line-height: 1.7;
  }

  .numbered-content :global(a) {
    color: #2563eb;
    text-decoration: none;
    border-bottom: 1px solid #2563eb;
  }

  .numbered-content :global(a:hover) {
    color: #1d4ed8;
    border-bottom-width: 2px;
  }

  .numbered-content :global(strong) {
    color: #111827;
    font-weight: 700;
  }

  .numbered-content :global(h2 span[id]),
  .numbered-content :global(h3 span[id]) {
    scroll-margin-top: 100px;
  }
</style>
