---
import Html from '~/components/page/Html.astro';
import type { GetStaticPaths } from "astro";
import { render } from "astro:content";
import { data } from '~/data/data'
import { Picture } from 'astro:assets';

export const getStaticPaths = (async () => {
  const posts = await data.posts.getPublished();
  return posts.map((post) => ({
    params: { id: post.id }
  }));
}) satisfies GetStaticPaths;

const post = await data.posts.get(Astro.params.id);
const { Content } = await render(post);
---

<Html
  title={post.data.title}
  description={post.data.description}
  jsonLd={post.jsonLd}
  image={`/posts/${post.id}/share.png`}
>
  <article>
    <header>
      <h1>
        {post.data.title.split(' ').map((word) => <span>{word}</span>)}
      </h1>
      <a href='/'><h2>By {data.profile.name}</h2></a>
    </header>
    <Picture
      loading='eager'
      class='img'
      fetchpriority="high"
      src={post.data.heroImage}
      widths={[320, 640, 1024, 1400]}
      formats={['avif', 'webp', 'png']}
      alt='Cover image'
    />
    <div class='content'>
      <Content />
    </div>
  </article>
</Html>

<style>
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-family: var(--font-family-heading);
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
  }


  article {
    --left-padding: 100px;
    font-family: var(--font-family);
    font-size: var(--font-size);
    letter-spacing: var(--letter-spacing);
    color: var(--color);
    background-color: var(--background-color);
    display: grid;
    letter-spacing: 0.05rem;
    font-size: 1rem;
    line-height: 1.3rem;
    grid-template-columns: 1fr calc(60ch + var(--left-padding)) 2fr;
    grid-template-rows: auto;
    grid-template-areas:
      '. title cover'
      '. content cover';
  }

  article picture {
    grid-area: cover;
    position: relative;
  }

  .img {
    max-width: 100%;
    height: 100vh;
    top: 0;
    position: sticky;
    object-fit: cover;
    object-position: center;
    right: 0;
    clip-path: polygon(40% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 50%);
  }

  header {
    grid-area: title;
    min-height: 80vh;
    display: flex;
    justify-content: center;
    flex-direction: column;

    .subtitle {
      font-size: 1rem;
      line-height: 2rem;
      padding-top: 1rem;
      padding-bottom: 1rem;
      text-transform: uppercase;
    }
  }

  h2 {
    font-size: 1.5rem;
    font-weight: 300;
    color: #fff;
    text-transform: uppercase;
    margin-top: var(--space-md);
    color: #000;
  }

  h3 {
    font-size: 1.1rem;
  }

  h1 {
    display: flex;
    flex-wrap: wrap;
    font-size: 4rem;
    line-height: 1;
    color: #fff;
    text-transform: uppercase;
    font-weight: 400;
    gap: 1rem;

    span {
      display: inline-block;
      background: red;
      padding: 0.5rem 1rem;
    }
  }

  .content {
    max-width: 100vw;
    grid-area: content;
    padding: var(--space-xl);
    padding-left: var(--left-padding);

    img {
      max-width: 100%;
      height: auto;
      margin-bottom: var(--space-lg);
    }

    p {
      text-align: justify;
      margin-bottom: var(--space-md);
      line-height: 1.5rem;
    }

    p:first-of-type {
      &:first-letter {
        font-size: 5rem;
        border: 5px solid #000;
        float: left;
        padding: 0 var(--space-md);
        margin-right: 1rem;
        line-height: 1;
      }
    }

    h2 {
      font-size: 1.2rem;
      font-weight: 600;
      margin-bottom: var(--space-lg);
      padding-top: var(--space-lg);
      text-transform: uppercase;

      &:first-letter {
        background: #000;
        color: #fff;
        padding: 0 5px;
        letter-spacing: -0.2rem;
      }
    }

    h3 {
      font-size: 1rem;
      text-transform: uppercase;
      font-weight: 900;
      margin-bottom: 1rem;

      &:first-letter {
        font-size: 1.2rem;
      }
    }

    strong {
      background: #000;
      padding: 0 5px;
      color: #fff;
      font-weight: 600;
    }

    em {
      font-style: italic;
    }

    li {
      list-style-type: circle;
      margin-left: 2rem;
      padding-bottom: var(--space-md);
    }

    pre {
      max-width: 100%;
      overflow-x: auto;
      font-family: monospace;
      padding: var(--space-lg);
    }
  }

  @media (max-width: 1024px) {
    article {
      --left-padding: 0;
      grid-template-columns: 1fr;
      grid-template-areas:
        'title'
        'cover'
        'content';
    }

    article picture {
      position: absolute;
      z-index: 0;
      height: 80vh;
    }

    .img {
      clip-path: none;
      height: 80vh;
      opacity: 0.5;
    }

    header {
      padding: var(--space-xl);
      height: 80vh;
      z-index: 1;
    }

    h1 {
      font-size: 2.5rem;
    }

    h2 {
      font-size: 1.2rem;
    }

    .content {
      padding: var(--space-lg);
    }
  }
</style>
