---
import type { CollectionEntry } from 'astro:content';
import { render } from 'astro:content';
import Base from '@layouts/Base.astro';

interface Props {
  entry: CollectionEntry<'elements'>;
}

const { entry } = Astro.props;
const { Content } = await render(entry);
const { title, seo, symbol } = entry.data;

const glyph = symbol.discriminant === 'font' ? symbol.value : null;
---

<Base title={title} seo={seo}>
  <main class="content">
    <article>
      <h1>
        <span class="element-name">{title}</span>
        {
          glyph && (
            <span
              class="element-glyph"
              style={`font-family: ${glyph.family}, serif`}
            >
              {glyph.character}
            </span>
          )
        }
      </h1>
      <Content />
    </article>
  </main>
</Base>

<style>
  h1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .element-glyph {
    text-align: center;
    line-height: 0.875;
    border-radius: 50%;
    display: inline-block;
    color: var(--color-text-inverse);
    width: 0.875em;
    height: 0.875em;
    background: var(--color-primary);
  }
</style>
