<script setup>
import { computed } from "vue";
import { cases } from "~/data/cases";

const route = useRoute();
const currentCase = computed(() => cases.find((item) => item.slug === route.params.slug));

const relatedCases = computed(() =>
  cases.filter((item) => item.slug !== currentCase.value?.slug).slice(0, 3),
);

if (!currentCase.value) {
  throw createError({ statusCode: 404, statusMessage: "Case not found" });
}

useHead(() => ({
  title: `${currentCase.value.title} - 大马棒·云途全域 GEO`,
  meta: [{ name: "description", content: currentCase.value.summary }],
}));
</script>

<template>
  <WebsiteShell>
    <section
      class="relative overflow-hidden bg-black bg-cover bg-center text-white"
      :style="{ backgroundImage: `url(${currentCase.image})` }"
    >
      <div class="absolute inset-0 bg-black/55" />
      <div class="absolute inset-x-0 bottom-0 h-24 bg-gradient-to-t from-white to-transparent" />
      <div class="container-gm relative z-10 py-24 md:py-32">
        <p class="text-sm uppercase tracking-[0.34em] text-white/65" data-hero-reveal>CASE DETAIL</p>
        <h1 class="mt-5 max-w-4xl text-balance text-[34px] font-semibold leading-tight md:text-[42px]" data-hero-reveal>
          {{ currentCase.title }}
        </h1>
        <p class="mt-6 max-w-2xl text-base leading-8 text-white/78 md:text-lg" data-hero-reveal>
          {{ currentCase.summary }}
        </p>
        <div class="mt-8" data-hero-reveal>
          <SectionRouteLinks
            :routes="[
              { label: '返回案例库', href: '/cases', path: '/cases' },
              { label: '当前详情', href: currentCase.path, path: currentCase.path },
              { label: '联系页', href: '/contact', path: '/contact' },
            ]"
            light
          />
        </div>
      </div>
    </section>

    <section class="bg-white py-16 md:py-20">
      <div class="container-gm grid gap-10 lg:grid-cols-[0.75fr_1.25fr]">
        <aside class="lg:sticky lg:top-28 lg:self-start" data-reveal>
          <p class="text-sm uppercase tracking-[0.3em] text-[#999]">Case</p>
          <h1 class="mt-4 text-balance text-[34px] font-semibold leading-tight text-[#262626] md:text-[42px]">
            {{ currentCase.title }}
          </h1>
          <p class="mt-5 text-base leading-8 text-[#666]">{{ currentCase.summary }}</p>
          <p class="mt-5 font-mono text-xs text-[#999]">页面路径 {{ currentCase.path }}</p>
          <NuxtLink to="#contact" class="gm-btn gm-btn-primary mt-8">立即免费咨询</NuxtLink>
        </aside>

        <div class="space-y-6">
          <div class="overflow-hidden rounded-lg border border-gm-border" data-reveal>
            <img :src="currentCase.image" :alt="currentCase.title" class="h-[320px] w-full object-cover" data-parallax="24" />
          </div>

          <div class="grid gap-4 md:grid-cols-2" data-stagger>
            <div
              v-for="metric in currentCase.metrics"
              :key="metric"
              class="rounded-lg border border-gm-border bg-gm-light p-5"
              data-stagger-item
            >
              <p class="text-sm font-medium text-[#262626]">{{ metric }}</p>
            </div>
          </div>

          <div class="grid gap-4" data-stagger>
            <article class="rounded-lg border border-gm-border p-6" data-stagger-item>
              <h2 class="text-[20px] font-semibold text-[#262626]">项目挑战</h2>
              <p class="mt-3 text-sm leading-7 text-[#666]">{{ currentCase.challenge }}</p>
            </article>
            <article class="rounded-lg border border-gm-border p-6" data-stagger-item>
              <h2 class="text-[20px] font-semibold text-[#262626]">解决方案</h2>
              <p class="mt-3 text-sm leading-7 text-[#666]">{{ currentCase.solution }}</p>
            </article>
            <article class="rounded-lg border border-gm-border p-6" data-stagger-item>
              <h2 class="text-[20px] font-semibold text-[#262626]">落地结果</h2>
              <p class="mt-3 text-sm leading-7 text-[#666]">{{ currentCase.result }}</p>
            </article>
          </div>
        </div>
      </div>
    </section>

    <section id="related-cases" class="bg-[#f7f8f7] py-20">
      <div class="container-gm">
        <div class="flex flex-col gap-6 md:flex-row md:items-end md:justify-between" data-reveal>
          <div class="max-w-3xl">
            <p class="text-sm uppercase tracking-[0.3em] text-[#9a9a9a]">Cases</p>
            <h2 class="section-title mt-4">相关案例推荐</h2>
          </div>
          <SectionRouteLinks
            :routes="[
              { label: '模块锚点', href: '#related-cases', path: `${currentCase.path}#related-cases` },
              { label: '返回案例库', href: '/cases', path: '/cases' },
            ]"
          />
        </div>

        <div class="mt-10 grid gap-6 md:grid-cols-2 xl:grid-cols-3" data-stagger>
          <NuxtLink
            v-for="item in relatedCases"
            :key="item.title"
            :to="item.path"
            class="overflow-hidden rounded-lg border border-gm-border bg-white shadow-sm transition hover:shadow-hover"
            data-stagger-item
            data-hover-card
          >
            <div class="h-56 overflow-hidden bg-gm-light">
              <img :src="item.image" :alt="item.title" class="h-full w-full object-cover" loading="lazy" />
            </div>
            <div class="p-6">
              <p class="text-xs font-medium text-gm-green">{{ item.category }}</p>
              <h3 class="mt-3 text-xl font-semibold leading-7 text-[#262626]">{{ item.title }}</h3>
              <p class="mt-3 text-sm leading-7 text-[#777]">{{ item.summary }}</p>
              <p class="mt-5 font-mono text-[11px] text-[#999]">案例路径 {{ item.path }}</p>
            </div>
          </NuxtLink>
        </div>
      </div>
    </section>

    <CtaSection />
  </WebsiteShell>
</template>
