<script lang="ts">
  import { reveal } from '$lib/actions/reveal';
  import ServicesSection from '$lib/components/ServicesSection.svelte';
  import { getImageMetadata } from '$lib/image-metadata';
  import type { AboutPageContent, SiteSharedContent } from '$lib/types';

  export let content: SiteSharedContent;
  export let pageContent: AboutPageContent;
</script>

<main class="about-page">
  <section class="about-hero">
    <div class="about-inner">
      <h1>{pageContent.title}</h1>
    </div>
  </section>

  {#each pageContent.sections as section}
    <section
      use:reveal
      class:about-section-gradient={section.accent === 'gradient'}
      class="about-section reveal-block"
    >
      <div class:about-section-reverse={section.reverse} class="about-inner about-section-grid">
        <div class="about-copy">
          <h2>{section.title}</h2>
          {#each section.body as paragraph}
            <p>{paragraph}</p>
          {/each}
        </div>

        <div class="about-media">
          <img
            src={section.imageUrl}
            alt={section.imageAlt}
            width={getImageMetadata(section.imageUrl)?.width}
            height={getImageMetadata(section.imageUrl)?.height}
            loading="lazy"
            decoding="async"
          />
        </div>
      </div>
    </section>
  {/each}

  <ServicesSection services={content.services} heading={pageContent.servicesTitle} />

  <section use:reveal={{ delay: 70 }} class="about-contact reveal-block">
    <div class="about-inner">
      <div class="about-contact-card">
        <h2>{pageContent.contact.title}</h2>
        <div class="about-contact-grid">
          <a class="about-contact-link" href={`mailto:${pageContent.contact.email}`}>
            {pageContent.contact.email}
          </a>
          <a class="btn btn-yellow" href={pageContent.contact.cta.href}>
            {pageContent.contact.cta.label}
          </a>
          <a class="about-contact-link" href={`tel:${pageContent.contact.phone.replace(/[^0-9+]/g, '')}`}>
            {pageContent.contact.phone}
          </a>
        </div>
      </div>
    </div>
  </section>
</main>

<style>
  .about-page {
    background: var(--off-white);
  }

  .about-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 50px;
  }

  .about-hero {
    padding: 72px 0 40px;
  }

  .about-hero h1,
  .about-copy h2,
  .about-contact-card h2 {
    margin: 0;
    font-family: var(--font-head);
    font-size: clamp(34px, 4vw, 56px);
    line-height: 1.05;
    letter-spacing: -0.04em;
    color: #000;
  }

  .about-hero h1 {
    text-align: center;
  }

  .about-section {
    padding: 0 0 88px;
  }

  .about-section-gradient {
    margin: 0 24px 88px;
    padding: 40px 0;
    border-radius: 36px;
    background: linear-gradient(180deg, #f5efe6 0%, #f9f6ef 100%);
  }

  .about-section-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 44px;
    align-items: center;
  }

  .about-section-reverse {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .about-section-reverse .about-copy {
    order: 2;
  }

  .about-section-reverse .about-media {
    order: 1;
  }

  .about-copy h2 {
    font-size: clamp(28px, 3vw, 40px);
  }

  .about-copy p {
    margin: 18px 0 0;
    color: #34363a;
    font-size: 17px;
    line-height: 1.75;
  }

  .about-media img {
    display: block;
    width: 100%;
    max-width: 460px;
    aspect-ratio: 4 / 3;
    height: auto;
    margin-left: auto;
    margin-right: auto;
    border-radius: 28px;
    object-fit: cover;
    box-shadow: 0 16px 40px rgba(17, 20, 24, 0.08);
  }

  :global(.reveal-ready.reveal-block) {
    opacity: 0;
    transform: translate3d(0, var(--reveal-distance, 24px), 0);
    transition:
      opacity 0.55s ease,
      transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: var(--reveal-delay, 0ms);
  }

  :global(.reveal-visible.reveal-block) {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }

  .about-contact {
    padding: 0 0 88px;
  }

  .about-contact-card {
    border-radius: 36px;
    background: #fff;
    padding: 42px 48px;
    box-shadow: 0 14px 34px rgba(17, 20, 24, 0.05);
    text-align: center;
  }

  .about-contact-card h2 {
    font-size: clamp(28px, 3vw, 42px);
  }

  .about-contact-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    align-items: center;
    margin-top: 28px;
  }

  .about-contact-link {
    color: #34363a;
    font-size: 20px;
    font-weight: 600;
    text-decoration: none;
  }

  @media (max-width: 1024px) {
    .about-section-grid,
    .about-section-reverse {
      grid-template-columns: 1fr;
    }

    .about-section-reverse .about-copy,
    .about-section-reverse .about-media {
      order: initial;
    }

    .about-contact-grid {
      grid-template-columns: 1fr;
    }
  }

  @media (max-width: 768px) {
    .about-inner {
      padding: 0 24px;
    }

    .about-hero {
      padding: 56px 0 24px;
    }

    .about-section,
    .about-contact {
      padding-bottom: 64px;
    }

    .about-section-gradient {
      margin: 0 12px 64px;
      padding: 28px 0;
      border-radius: 28px;
    }

    .about-section-grid {
      gap: 24px;
    }

    .about-copy h2,
    .about-contact-card h2 {
      font-size: 30px;
    }

    .about-copy p {
      font-size: 16px;
      line-height: 1.7;
    }

    .about-contact-card {
      padding: 30px 24px;
    }

    .about-contact-grid {
      margin-top: 22px;
    }

    .about-contact-link {
      font-size: 18px;
    }
  }
</style>
