<script lang="ts">
  import { accordion } from '$lib/actions/accordion';
  import { reveal } from '$lib/actions/reveal';
  import CtaCard from '$lib/components/CtaCard.svelte';
  import Icon from '$lib/components/Icon.svelte';
  import ServiceHero from '$lib/components/ServiceHero.svelte';
  import { getEnhancedImage } from '$lib/enhanced-images';
  import type { AboutPageContent } from '$lib/types';

  export let pageContent: AboutPageContent;

  $: standardSections = pageContent.sections.filter((s) => s.accent !== 'founder');
  $: founderSection = pageContent.sections.find((s) => s.accent === 'founder') ?? null;
  const heroChips = [
    { icon: 'fas fa-star', label: '30+ five-star Google reviews' },
    { icon: 'fas fa-location-dot', label: 'Auckland Central' },
    { icon: 'fas fa-paw', label: 'Small dog specialists' }
  ];
  const founderHeadingLead = 'Meet Aless,';
  const founderHeadingHighlight = 'the heart of Goodwalk';
</script>

<main class="about-page">
  <ServiceHero
    eyebrow="About Goodwalk"
    title={pageContent.title}
    subtitle="Small dog specialists serving Auckland Central. A team your dog knows by name."
    imageUrl="/images/about-good-walk.webp"
    imageAlt="Goodwalk dogs gathered together in the back of the car before a walk"
    chips={heroChips}
    cta={{ label: 'Book a Meet & Greet', href: '/contact-us', variant: 'yellow' }}
  />

  <!-- ── Standard sections (Who we are, Our impact) ── -->
  {#each standardSections as section}
    {@const enhanced = getEnhancedImage(section.imageUrl)}
    <section
      use:reveal
      class="about-section reveal-block"
      class:about-section-gradient={section.accent === 'gradient'}
    >
      <div class="page-inner about-section-grid" class:about-section-reverse={section.reverse}>
        <div class="about-copy">
          {#if section.eyebrow}
            <span class="eyebrow about-eyebrow">{section.eyebrow}</span>
          {/if}
          <h2>{section.title}</h2>
          {#each section.body as paragraph}
            <p>{paragraph}</p>
          {/each}
        </div>
        <div class="about-media">
          {#if enhanced}
            <enhanced:img src={enhanced} alt={section.imageAlt} loading="lazy" decoding="async" />
          {:else}
            <img src={section.imageUrl} alt={section.imageAlt} loading="lazy" decoding="async" />
          {/if}
        </div>
      </div>
    </section>
  {/each}

  <!-- ── Founder section ── -->
  {#if founderSection}
    {@const founderEnhanced = getEnhancedImage(founderSection.imageUrl)}
    <section use:reveal={{ delay: 50 }} class="about-founder reveal-block">
      <div class="page-inner about-founder-grid">
        <div class="about-founder-media">
          {#if founderEnhanced}
            <enhanced:img
              src={founderEnhanced}
              alt={founderSection.imageAlt}
              loading="lazy"
              decoding="async"
            />
          {:else}
            <img
              src={founderSection.imageUrl}
              alt={founderSection.imageAlt}
              loading="lazy"
              decoding="async"
            />
          {/if}
        </div>
        <div class="about-founder-copy">
          <article class="about-founder-note">
            {#if founderSection.eyebrow}
              <span class="eyebrow about-eyebrow about-founder-kicker">{founderSection.eyebrow}</span>
            {/if}
            <h2 class="about-founder-heading">
              <span class="about-founder-heading-desktop">
                <span class="about-founder-title-main">{founderHeadingLead}</span>
                <br />
                <span class="about-founder-title-highlight">{founderHeadingHighlight}</span>
              </span>
              <span class="about-founder-heading-mobile">
                <span class="about-founder-title-main">{founderHeadingLead}</span>
                <span class="about-founder-title-highlight">{founderHeadingHighlight}</span>
              </span>
            </h2>
            <div class="about-founder-body">
              {#each founderSection.body as paragraph}
                <p>{paragraph}</p>
              {/each}
            </div>

            <div class="about-founder-signoff">
              <div class="about-founder-signoff-text">
                <span class="about-founder-name">Aless</span>
                <span class="about-founder-role">Goodwalk founder</span>
              </div>
            </div>

            <a
              class="about-founder-contact-note"
              href="mailto:info@goodwalk.co.nz"
              aria-label="Email Aless at Goodwalk"
            >
              <span class="about-founder-contact-icon">
                <Icon name="fas fa-envelope" />
              </span>
              <span>If you are unsure about anything, feel free to email me anytime.</span>
            </a>

            <a href="/contact-us" class="btn btn-green btn-mobile-center about-founder-cta">
              Book a free Meet &amp; Greet
            </a>
          </article>
        </div>
      </div>
    </section>
  {/if}

  <!-- ── FAQs ── -->
  {#if pageContent.faqs && pageContent.faqs.length}
    <section use:reveal={{ delay: 30 }} class="about-faq reveal-block">
      <div class="page-inner">
        <div class="about-faq-header">
          <span class="eyebrow about-eyebrow">FAQ</span>
          <h2>{pageContent.faqTitle ?? 'Common questions'}</h2>
        </div>
        <div use:accordion class="faq about-faq-list">
          {#each pageContent.faqs as item}
            <details>
              <summary>{item.question}</summary>
              <p>{item.answer}</p>
            </details>
          {/each}
        </div>
      </div>
    </section>
  {/if}

  <!-- ── Contact CTA ── -->
  <section use:reveal={{ delay: 50 }} class="about-contact reveal-block">
    <div class="page-inner">
      <CtaCard
        title={pageContent.contact.title}
        description="Questions, pricing, or a first Meet &amp; Greet. Email, call, or send an Instagram DM. We&apos;ll reply within 24 hours."
        ctaHref={pageContent.contact.cta.href}
        ctaLabel={pageContent.contact.cta.label}
        email={pageContent.contact.email}
        phone={pageContent.contact.phone}
        instagramHref="https://www.instagram.com/goodwalk.nz/"
        contactNote="Email, call, or send an Instagram DM. We want to be easy to reach in the way that suits you best."
        showIcons={true}
      />
    </div>
  </section>

</main>

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

  /* ── Eyebrow ── */
  .about-eyebrow {
    display: inline-block;
    margin-bottom: 14px;
  }

  /* ── Standard sections ── */
  .about-section {
    padding: 88px 0;
  }

  .about-section-gradient {
    background: linear-gradient(180deg, #f5efe6 0%, #f9f6ef 100%);
  }

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

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

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

  .about-copy h2 {
    margin: 0 0 16px;
    font-family: var(--font-head);
    font-size: clamp(28px, 3vw, 40px);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: -0.03em;
    color: #0d1a0d;
  }

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

  .about-media {
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 28px;
    box-shadow: 0 16px 48px rgba(17, 20, 24, 0.1);
  }

  .about-media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
  }

  /* ── Founder section ── */
  .about-founder {
    padding: 88px 0;
    background: #fff;
  }

  .about-founder-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 64px;
    align-items: center;
  }

  .about-founder-media img {
    display: block;
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 28px;
    object-fit: cover;
    box-shadow: 0 24px 56px rgba(17, 20, 24, 0.12);
    margin: 0 auto;
  }

  .about-founder-copy h2 {
    margin: 0 0 16px;
    font-family: var(--font-head);
    font-size: clamp(30px, 3.5vw, 44px);
    font-weight: 800;
    line-height: 1.06;
    letter-spacing: -0.03em;
    text-wrap: balance;
    color: #0d1a0d;
  }

  .about-founder-note {
    padding: 40px 42px 34px;
    background: linear-gradient(180deg, rgba(251, 251, 251, 0.98) 0%, rgba(247, 248, 246, 1) 100%);
    border: 1px solid rgba(17, 20, 24, 0.08);
    border-radius: 28px;
    box-shadow: var(--shadow-panel-elevated);
  }

  .about-founder-kicker {
    display: block;
    width: fit-content;
    margin-bottom: 18px;
  }

  .about-founder-heading-desktop {
    display: block;
  }

  .about-founder-heading-mobile {
    display: none;
  }

  .about-founder-heading-mobile .about-founder-title-main,
  .about-founder-heading-mobile .about-founder-title-highlight {
    display: block;
  }

  .about-founder-title-main {
    color: #0d1a0d;
  }

  .about-founder-title-highlight {
    position: relative;
    display: inline-block;
    color: #0d1a0d;
  }

  .about-founder-title-highlight::after {
    content: '';
    position: absolute;
    left: 0;
    right: -6px;
    bottom: -16px;
    height: 24px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 34' fill='none'%3E%3Cpath d='M4 24C67 10 131 4 198 5c43 1 82 6 118 18' stroke='%23192419' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E")
      center/contain no-repeat;
    transform-origin: left center;
    animation: about-founder-underline-draw 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.2s both;
  }

  @keyframes about-founder-underline-draw {
    0% {
      opacity: 0;
      transform: scaleX(0.2) translateY(6px) rotate(-1.5deg);
    }

    65% {
      opacity: 1;
      transform: scaleX(1.04) translateY(0) rotate(0deg);
    }

    100% {
      opacity: 1;
      transform: scaleX(1) translateY(0) rotate(0deg);
    }
  }

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

  .about-founder-body {
    display: grid;
    gap: 14px;
  }

  .about-founder-signoff {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid rgba(17, 20, 24, 0.08);
  }

  .about-founder-signoff-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .about-founder-name {
    color: #0d1a0d;
    font-family: var(--font-head);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
  }

  .about-founder-role {
    color: var(--gray);
    font-size: 13px;
    line-height: 1.3;
  }

  .about-founder-contact-note {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding: 12px 16px;
    border-radius: 18px;
    background: rgba(33, 48, 33, 0.05);
    box-shadow: inset 0 0 0 1px rgba(17, 20, 24, 0.06);
    color: var(--gw-green);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: none;
    transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
  }

  .about-founder-contact-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #fff;
    box-shadow: inset 0 0 0 1px rgba(17, 20, 24, 0.07);
    color: var(--gw-green);
    font-size: 13px;
    flex: 0 0 auto;
  }

  .about-founder-cta {
    display: flex;
    width: fit-content;
    margin: 28px 0 0;
  }

  @media (hover: hover) {
    .about-founder-contact-note:hover {
      background: rgba(33, 48, 33, 0.08);
      box-shadow:
        inset 0 0 0 1px rgba(17, 20, 24, 0.08),
        0 10px 22px rgba(17, 20, 24, 0.05);
      transform: translateY(-1px);
    }
  }

  /* ── FAQs ── */
  .about-faq {
    padding: 80px 0;
    background: var(--off-white);
  }

  .about-faq-header {
    text-align: center;
    margin-bottom: 40px;
  }

  .about-faq-header h2 {
    margin: 0;
    font-family: var(--font-head);
    font-size: clamp(28px, 3vw, 40px);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: -0.03em;
    color: #0d1a0d;
  }

  .about-faq-list {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  /* ── Contact CTA ── */
  .about-contact {
    padding: 0 0 88px;
  }

  /* ── Tablet ── */
  @media (max-width: 1024px) {
    .about-section-grid,
    .about-founder-grid {
      grid-template-columns: 1fr;
      gap: 36px;
    }

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

    .about-founder-media img {
      max-width: 420px;
    }
  }

  /* ── Mobile ── */
  @media (max-width: 768px) {
    .about-section {
      padding: 60px 0;
    }

    .about-eyebrow {
      display: block;
      width: fit-content;
      margin-left: auto;
      margin-right: auto;
      text-align: center;
    }

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

    .about-copy h2 {
      font-size: 28px;
      text-align: center;
    }

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

    .about-founder {
      padding: 60px 0;
    }

    .about-founder-grid {
      gap: 28px;
    }

    .about-founder-note {
      padding: 26px 24px 24px;
      border-radius: 24px;
    }

    .about-founder-copy h2 {
      font-size: 26px;
      line-height: 1.02;
      text-align: center;
    }

    .about-founder-heading-desktop {
      display: none;
    }

    .about-founder-heading-mobile {
      display: block;
    }

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

    .about-founder-kicker {
      margin-left: auto;
      margin-right: auto;
    }

    .about-founder-contact-note {
      display: flex;
      width: 100%;
      font-size: 13px;
      padding: 11px 14px;
      text-align: center;
    }

    .about-founder-cta {
      width: 100%;
      justify-content: center;
    }

    .about-faq {
      padding: 60px 0;
    }

    .about-contact {
      padding-bottom: 60px;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .about-founder-title-highlight::after {
      animation: none;
    }
  }
</style>
