<script lang="ts">
  import { onMount } from 'svelte';
  import { reveal } from '$lib/actions/reveal';
  import BookingWizard from '$lib/components/BookingWizard.svelte';
  import Icon from '$lib/components/Icon.svelte';
  import PageHeader from '$lib/components/PageHeader.svelte';
  import PricingPlanCard from '$lib/components/PricingPlanCard.svelte';
  import TestimonialsSection from '$lib/components/TestimonialsSection.svelte';
  import { decoratePlans } from '$lib/utils/pricing';
  import type { PricingPageContent, SiteSharedContent } from '$lib/types';

  export let content: SiteSharedContent;
  export let pageContent: PricingPageContent;

  onMount(() => {
    /* eslint-disable no-console */
    console.log(
      '%c🐾  If you are reading this, you love dogs.\n     So do we. Come say hi: hello@goodwalk.co.nz',
      'color:#213021;font:600 13px/1.5 system-ui;padding:6px 0'
    );
  });

  const includedPromises = [
    { icon: 'fas fa-handshake', label: 'Free Meet & Greet first' },
    { icon: 'fas fa-car', label: 'Pickup and drop-off included' },
    { icon: 'fas fa-user-check', label: 'Same walker every week' },
    { icon: 'fas fa-rotate-left', label: 'No contracts, cancel anytime' }
  ];

</script>

<main class="pricing-page">
  <PageHeader variant="green" title={pageContent.title} subtitle={pageContent.subtitle}>
    <a
      class="pricing-trust"
      href="https://g.page/r/CUsvrWPhkYrAEB0/"
      target="_blank"
      rel="noopener"
      aria-label="Read our 5-star Google reviews"
    >
      <img
        class="pricing-trust-logo"
        src="/images/google-g-logo.svg"
        alt=""
        width="18"
        height="19"
      />
      <span class="pricing-trust-stars" aria-hidden="true">
        {#each Array(5) as _}
          <Icon name="fas fa-star" />
        {/each}
      </span>
      <span class="pricing-trust-label">30+ 5-star Google reviews, trusted by Auckland dog owners</span>
      <Icon name="fas fa-arrow-right" className="pricing-trust-arrow" />
    </a>
  </PageHeader>

  {#if pageContent.comparison}
    <section use:reveal class="pricing-block pricing-block--lead reveal-block">
      <div class="page-inner">
        <div class="section-header pricing-section-header">
          <span class="eyebrow">How to choose</span>
          <h2 class="section-heading">{pageContent.comparison.title}</h2>
          {#if pageContent.comparison.intro}
            <p class="section-intro">{pageContent.comparison.intro}</p>
          {/if}
        </div>

        <p class="pricing-attribution">
          <img
            class="pricing-attribution-avatar"
            src="/images/alessandra-goodwalk-founder-auckland.webp"
            alt="Aless, Goodwalk founder"
            width="40"
            height="40"
          />
          <span class="pricing-attribution-body">
            <span class="pricing-attribution-name">
              <span class="pricing-attribution-paw" aria-hidden="true">
                <Icon name="fas fa-paw" />
              </span>
              Aless, Goodwalk founder
              <svg
                class="pricing-attribution-sig"
                viewBox="0 0 120 8"
                fill="none"
                aria-hidden="true"
                focusable="false"
              >
                <path
                  d="M2 5 Q 14 1, 26 4 T 50 4 T 74 5 T 98 3 T 118 4"
                  stroke="currentColor"
                  stroke-width="1.6"
                  stroke-linecap="round"
                />
              </svg>
            </span>
            <span class="pricing-attribution-text">
              Most owners start with Tiny Gang, but the right answer is whichever fits your dog.
              If you are not sure, the free Meet &amp; Greet is the easiest way to work it out.
            </span>
          </span>
        </p>
      </div>
    </section>
  {/if}

  {#each pageContent.sections as section, sectionIndex}
    <section
      use:reveal
      class="pricing-block pricing-block--plans reveal-block"
      class:pricing-block--tinted={sectionIndex % 2 === 1}
    >
      <div class="page-inner">
        {#if sectionIndex > 0}
          <div class="pricing-section-divider" aria-hidden="true">
            <span class="pricing-section-divider-mark">
              <Icon name="fas fa-paw" />
            </span>
          </div>
        {/if}

        <div class="section-header pricing-section-header">
          {#if section.icon}
            <span class="pricing-section-emblem" aria-hidden="true">
              <Icon name={section.icon} className="pricing-section-emblem-glyph" />
            </span>
          {/if}
          {#if section.eyebrow}
            <span class="eyebrow">{section.eyebrow}</span>
          {/if}
          <h2 class="section-heading">{section.title}</h2>
          {#if section.lede ?? section.blurb}
            <p class="section-intro">{section.lede ?? section.blurb}</p>
          {/if}
        </div>

        {#if section.meta?.length}
          <ul class="pricing-meta-chips" aria-label="{section.title} at a glance">
            {#each section.meta as item}
              <li class="pricing-meta-chip">
                <span class="pricing-meta-chip-label">{item.label}</span>
                <span class="pricing-meta-chip-value">{item.value}</span>
              </li>
            {/each}
          </ul>
        {/if}

        {#if section.detailCta}
          <p class="pricing-section-link-wrap">
            <a class="pricing-block-link" href={section.detailCta.href}>
              <span>{section.detailCta.label}</span>
              <Icon name="fas fa-arrow-right" />
            </a>
          </p>
        {/if}

        <div class:pricing-plan-grid-three={section.plans.length === 3} class="pricing-plan-grid">
          {#each decoratePlans(section.plans) as plan}
            <PricingPlanCard {plan} variant="pricing" />
          {/each}
        </div>
      </div>
    </section>
  {/each}

  <section use:reveal class="pricing-block pricing-block--promise pricing-block--tinted reveal-block">
    <div class="page-inner">
      <div class="section-header pricing-section-header">
        <span class="eyebrow">What every booking includes</span>
        <h2 class="section-heading">Built around trust, not contracts.</h2>
      </div>

      <ul class="pricing-promise-row" aria-label="What every Goodwalk booking includes">
        {#each includedPromises as promise}
          <li class="pricing-promise">
            <span class="pricing-promise-icon" aria-hidden="true">
              <Icon name={promise.icon} />
            </span>
            <span class="pricing-promise-label">{promise.label}</span>
          </li>
        {/each}
      </ul>
    </div>
  </section>

  <TestimonialsSection
    heading={pageContent.testimonialsHeading}
    testimonials={content.testimonials}
    seedKey="/our-pricing"
  />
  <BookingWizard booking={pageContent.booking} pagePath="/our-pricing" />
</main>

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

  /* ── Trust pill in header ── */
  .pricing-trust {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-top: 22px;
    padding: 9px 18px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--text-inverse);
    font-family: var(--font-head);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.01em;
    text-decoration: none;
    transition:
      background 0.2s ease,
      transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pricing-trust-logo {
    width: 18px;
    height: 19px;
    flex: 0 0 auto;
  }

  .pricing-trust:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
  }

  .pricing-trust-stars {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: var(--yellow);
    font-size: 13px;
  }

  :global(.pricing-trust .pricing-trust-arrow) {
    font-size: 12px;
    opacity: 0.85;
  }

  /* ── Section rhythm ── */
  .pricing-block {
    padding: 56px 0 40px;
  }

  .pricing-block--lead {
    padding-top: 48px;
    padding-bottom: 20px;
  }

  .pricing-block:last-of-type {
    padding-bottom: 64px;
  }

  .pricing-block--plans {
    padding-top: 56px;
    padding-bottom: 56px;
  }

  .pricing-block--promise {
    padding-top: 56px;
    padding-bottom: 56px;
  }

  /* ── Surface alternation (chapter banding) ─────────
     Lead + sections 1/3 stay on the page cream.
     Section 2 + promise sit on a slightly warmer cream.
  */
  .pricing-block--tinted {
    background: var(--surface-panel-cream);
  }

  /* ── Section divider (paw on hairline) ── */
  .pricing-section-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 460px;
    margin: 0 auto 32px;
    color: var(--gw-green);
    opacity: 0.55;
  }

  .pricing-section-divider::before,
  .pricing-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: currentColor;
    opacity: 0.35;
  }

  .pricing-section-divider-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: var(--off-white);
    color: var(--gw-green);
    font-size: 13px;
    box-shadow: inset 0 0 0 1px rgba(33, 48, 33, 0.18);
  }

  .pricing-block--tinted .pricing-section-divider-mark {
    background: var(--surface-panel-cream);
  }

  /* ── Section header (uses global .section-header / .section-heading / .eyebrow / .section-intro) ── */
  .pricing-section-header {
    margin-bottom: 22px;
    gap: 10px;
  }

  /* Green emblem tile — canonical Goodwalk identity above each service heading */
  .pricing-section-emblem {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin-bottom: 4px;
    justify-self: center;
    border-radius: 20px;
    background: var(--gw-green);
    box-shadow: 0 12px 28px rgba(33, 48, 33, 0.20);
  }

  :global(.pricing-section-emblem .pricing-section-emblem-glyph) {
    color: var(--yellow);
    font-size: 26px;
  }

  /* ── Meta chip row (centered label · value pills) ── */
  .pricing-meta-chips {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 auto 18px;
    padding: 0;
    max-width: 940px;
    list-style: none;
  }

  .pricing-meta-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    padding: 9px 16px;
    border-radius: 999px;
    background: var(--surface-panel);
    border: 1px solid rgba(33, 48, 33, 0.10);
    color: var(--text-heading);
    font-size: 13px;
    line-height: 1.4;
  }

  .pricing-meta-chip-label {
    color: var(--gw-green);
    font-family: var(--font-head);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    opacity: 0.78;
  }

  .pricing-meta-chip-value {
    font-weight: 500;
  }

  /* ── Section CTA link (centered under chips) ── */
  .pricing-section-link-wrap {
    margin: 0 auto 28px;
    text-align: center;
  }

  .pricing-block-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--gw-green);
    font-family: var(--font-head);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    transition: gap 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pricing-block-link :global(.icon) {
    font-size: 11px;
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pricing-block-link:hover {
    gap: 12px;
  }

  .pricing-block-link:hover :global(.icon) {
    transform: translateX(2px);
  }

  /* ── Aless attribution (signed-note feel, centered) ── */
  .pricing-attribution {
    display: inline-flex;
    align-items: flex-start;
    gap: 16px;
    margin: 26px auto 0;
    padding: 16px 22px 16px 14px;
    border-radius: 20px;
    background: var(--surface-panel);
    border: 1px solid rgba(33, 48, 33, 0.12);
    color: var(--text-heading);
    font-size: 14px;
    line-height: 1.6;
    max-width: 640px;
    text-align: left;
    transition:
      transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
      border-color 0.22s ease;
  }

  .pricing-block--lead .page-inner {
    text-align: center;
  }

  @media (hover: hover) {
    .pricing-attribution:hover {
      transform: rotate(-0.4deg) translateY(-2px);
      border-color: rgba(33, 48, 33, 0.22);
    }

    .pricing-attribution:hover .pricing-attribution-avatar {
      transform: rotate(2deg) scale(1.04);
    }
  }

  .pricing-attribution-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center top;
    flex: 0 0 auto;
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pricing-attribution-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .pricing-attribution-name {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: relative;
    align-self: flex-start;
    color: var(--gw-green);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.01em;
    padding-bottom: 6px;
  }

  .pricing-attribution-paw {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: var(--gw-green);
    font-size: 10px;
    opacity: 0.7;
  }

  .pricing-attribution-sig {
    position: absolute;
    left: 26px;
    right: 0;
    bottom: -2px;
    width: calc(100% - 26px);
    height: 8px;
    color: var(--gw-green);
    opacity: 0.55;
    pointer-events: none;
  }

  .pricing-attribution-text {
    color: var(--text-heading);
  }

  /* ── Plan grid (centered, tighter) ── */
  .pricing-plan-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    max-width: 1120px;
    margin: 0 auto;
  }

  .pricing-plan-grid-three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: 880px;
  }

  /* ── Promise row (centered, no card chrome) ── */
  .pricing-promise-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 18px 32px;
    margin: 0 auto;
    padding: 0;
    max-width: 860px;
    list-style: none;
  }

  .pricing-promise {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pricing-promise-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(33, 48, 33, 0.06);
    color: var(--gw-green);
    font-size: 13px;
    flex: 0 0 auto;
    transition:
      background 0.28s ease,
      color 0.28s ease,
      transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  }

  @media (hover: hover) {
    .pricing-promise:hover {
      transform: translateY(-2px);
    }

    .pricing-promise:hover .pricing-promise-icon {
      background: var(--gw-green);
      color: var(--yellow);
      transform: rotate(-4deg);
    }
  }

  .pricing-promise-label {
    color: var(--text-heading);
    font-family: var(--font-head);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
  }

  /* ── Reduced motion: drop rotational delights, keep color/lift ── */
  @media (prefers-reduced-motion: reduce) {
    .pricing-attribution,
    .pricing-attribution-avatar,
    .pricing-promise,
    .pricing-promise-icon {
      transition: none;
    }

    .pricing-attribution:hover,
    .pricing-attribution:hover .pricing-attribution-avatar,
    .pricing-promise:hover .pricing-promise-icon {
      transform: none;
    }
  }

  /* ── Responsive ── */
  @media (max-width: 1024px) {
    .pricing-plan-grid,
    .pricing-plan-grid-three {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      max-width: none;
    }
  }

  @media (max-width: 768px) {
    .pricing-block {
      padding: 40px 0 32px;
    }

    .pricing-block--lead {
      padding-top: 32px;
      padding-bottom: 12px;
    }

    .pricing-block:last-of-type {
      padding-bottom: 40px;
    }

    .pricing-block--plans,
    .pricing-block--promise {
      padding-top: 40px;
      padding-bottom: 40px;
    }

    .pricing-section-divider {
      margin-bottom: 24px;
      gap: 12px;
    }

    .pricing-section-divider-mark {
      width: 26px;
      height: 26px;
      font-size: 10px;
    }

    .pricing-section-header {
      margin-bottom: 18px;
    }

    .pricing-section-emblem {
      width: 54px;
      height: 54px;
      margin-bottom: 2px;
      border-radius: 16px;
    }

    :global(.pricing-section-emblem .pricing-section-emblem-glyph) {
      font-size: 21px;
    }

    .pricing-meta-chips {
      gap: 8px;
      margin-bottom: 22px;
    }

    .pricing-meta-chip {
      padding: 8px 14px;
      font-size: 12.5px;
    }

    .pricing-section-link-wrap {
      margin-bottom: 24px;
    }

    .pricing-attribution {
      max-width: none;
      gap: 12px;
      padding: 12px 16px 12px 10px;
      border-radius: 22px;
      font-size: 13px;
      align-items: flex-start;
    }

    .pricing-attribution-avatar {
      width: 36px;
      height: 36px;
    }

    .pricing-trust {
      gap: 10px;
      padding: 10px 14px;
      font-size: 13px;
    }

    .pricing-plan-grid,
    .pricing-plan-grid-three {
      grid-template-columns: 1fr;
      gap: 16px;
    }

    .pricing-promise-row {
      gap: 18px 24px;
    }
  }
</style>
