<script setup>
import { computed, onMounted } from 'vue'
import { useWindowSize } from '@vueuse/core'
import { usePhotoboothStore } from '../stores/photoboothStore'
import { STRIP_THEMES } from '../data/stripThemes'

const store = usePhotoboothStore()
const { width } = useWindowSize()

const isCompact = computed(() => width.value < 960)
const activeTheme = computed(() => store.stripTheme)

function selectTheme(themeId) {
  store.setTheme(themeId)
}

onMounted(() => {
  store.setStep(0)
  store.setSessionActive(false)
})
</script>

<template>
  <main class="home">
    <section class="hero-grid" :class="{ compact: isCompact }">
      <div class="hero-copy">
        <p class="eyebrow">Aesthetic keepsakes</p>
        <h1
          v-motion
          :initial="{ opacity: 0, y: 40 }"
          :enter="{ opacity: 1, y: 0, transition: { duration: 0.6 } }"
        >
          Capture three dreamy snaps and print a cute strip.
        </h1>
        <p class="sub">
          Transform spontaneous moments into nostalgic digital memories with a soft glow and pastel
          charm.
        </p>
        <div class="cta-row">
          <RouterLink class="primary-cta" to="/capture">Start Photobooth</RouterLink>
          <button class="ghost-cta" type="button">View Samples</button>
        </div>
        <div class="mini-steps">
          <span>01 Choose theme</span>
          <span>02 Snap three shots</span>
          <span>03 Save the strip</span>
        </div>
      </div>

      <aside
        class="theme-card"
        v-motion
        :initial="{ opacity: 0, y: 30 }"
        :enter="{ opacity: 1, y: 0 }"
      >
        <div class="theme-card-header">
          <h2>Select Strip Theme</h2>
          <p>Choose your signature look for the session.</p>
        </div>
        <div class="theme-list">
          <button
            v-for="theme in STRIP_THEMES"
            :key="theme.id"
            class="theme-option"
            :class="{ active: activeTheme === theme.id }"
            @click="selectTheme(theme.id)"
          >
            <span class="tone" :style="{ backgroundImage: `url('${theme.image}')` }"></span>
            <span class="theme-text">
              <strong>{{ theme.label }}</strong>
              <small>Signature strip</small>
            </span>
            <span class="radio"></span>
          </button>
        </div>
        <div class="signature">
          <span>Lumi Signature</span>
          <button class="signature-pill" type="button">Tokyo Studio • 2024</button>
        </div>
      </aside>
    </section>

    <section class="works">
      <div class="section-title">
        <h2>How Lumi Works</h2>
        <p>Three simple steps to create your perfect digital souvenir.</p>
      </div>
      <div class="works-grid">
        <article class="work-card">
          <div class="icon blush">😊</div>
          <h3>Smile</h3>
          <p>Get into position and let your personality shine through the lens.</p>
        </article>
        <article class="work-card">
          <div class="icon peach">📷</div>
          <h3>Snap</h3>
          <p>Three high-fidelity shots with gentle lighting and soft-focus styling.</p>
        </article>
        <article class="work-card">
          <div class="icon blue">☁️</div>
          <h3>Save</h3>
          <p>Instantly receive your digital strip ready for sharing or printing.</p>
        </article>
      </div>
    </section>

    <section class="aesthetic">
      <div class="section-title inline">
        <div>
          <h2>Choose Your Aesthetic</h2>
          <p>From Y2K nostalgia to clean minimal vibes, find the theme that fits your mood.</p>
        </div>
        <div class="slider-controls">
          <button class="circle-btn" type="button">‹</button>
          <button class="circle-btn" type="button">›</button>
        </div>
      </div>
      <div class="aesthetic-grid">
        <article class="aesthetic-card pastel">
          <div class="card-image"></div>
          <h3>Cotton Candy</h3>
          <span>Minimalist</span>
        </article>
        <article class="aesthetic-card noir">
          <div class="card-image"></div>
          <h3>Midnight Film</h3>
          <span>Dramatic</span>
        </article>
        <article class="aesthetic-card retro">
          <div class="card-image"></div>
          <h3>Sugar Pop</h3>
          <span>Y2K Retro</span>
        </article>
        <article class="aesthetic-card glow">
          <div class="card-image"></div>
          <h3>Golden Hour</h3>
          <span>Elegant</span>
        </article>
      </div>
    </section>

    <RouterLink class="floating" to="/capture" aria-label="Start capture">📸</RouterLink>
  </main>
</template>

<style scoped>
.home {
  display: grid;
  gap: 64px;
}

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

.hero-grid.compact {
  grid-template-columns: 1fr;
}

.hero-copy {
  padding: 40px;
  border-radius: 36px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: var(--soft-shadow);
  display: grid;
  gap: 18px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 0.7rem;
  color: var(--muted);
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(2.4rem, 4vw, 3.6rem);
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.primary-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 30px;
  border-radius: 999px;
  background: #7c3b54;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 18px 40px rgba(124, 59, 84, 0.25);
}

.ghost-cta {
  border: 1px solid rgba(124, 59, 84, 0.3);
  background: transparent;
  color: #7c3b54;
  padding: 12px 26px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

.mini-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.theme-card {
  padding: 32px;
  border-radius: 36px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 22px 50px rgba(190, 120, 150, 0.2);
  border: 1px solid rgba(200, 90, 124, 0.2);
  display: grid;
  gap: 20px;
}

.theme-card-header h2 {
  margin: 0;
  font-size: 1.6rem;
}

.theme-card-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.theme-list {
  display: grid;
  gap: 12px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.theme-option {
  display: grid;
  grid-template-columns: 40px 1fr 20px;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 999px;
  border: 1px solid rgba(124, 59, 84, 0.2);
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-option.active {
  border-color: rgba(124, 59, 84, 0.5);
  box-shadow: 0 12px 26px rgba(124, 59, 84, 0.16);
}

.tone {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid rgba(124, 59, 84, 0.15);
  background-size: cover;
  background-position: center;
}

.theme-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.theme-text strong {
  font-weight: 600;
  font-size: 0.95rem;
}

.theme-text small {
  color: var(--muted);
  font-size: 0.8rem;
}

.radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(124, 59, 84, 0.3);
  position: relative;
}

.theme-option.active .radio::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: #7c3b54;
}

.signature {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(124, 59, 84, 0.08);
  color: #7c3b54;
}

.signature-pill {
  border: none;
  background: rgba(124, 59, 84, 0.2);
  color: #7c3b54;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.works {
  display: grid;
  gap: 24px;
}

.section-title {
  text-align: center;
  display: grid;
  gap: 6px;
}

.section-title.inline {
  text-align: left;
  grid-template-columns: 1fr auto;
  align-items: center;
}

.section-title h2 {
  margin: 0;
  font-size: 2rem;
}

.section-title p {
  margin: 0;
  color: var(--muted);
}

.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.work-card {
  padding: 26px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 16px 36px rgba(200, 90, 124, 0.15);
  display: grid;
  gap: 12px;
  text-align: center;
}

.work-card h3 {
  margin: 0;
}

.work-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  margin: 0 auto;
}

.icon.blush {
  background: #f5ccd9;
}

.icon.peach {
  background: #f7d3c4;
}

.icon.blue {
  background: #d7e7f6;
}

.aesthetic {
  display: grid;
  gap: 24px;
}

.slider-controls {
  display: flex;
  gap: 10px;
}

.circle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(124, 59, 84, 0.12);
  color: #7c3b54;
  font-size: 1.2rem;
  cursor: pointer;
}

.aesthetic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
}

.aesthetic-card {
  padding: 16px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 18px 40px rgba(200, 90, 124, 0.12);
  display: grid;
  gap: 12px;
  text-align: center;
}

.aesthetic-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.aesthetic-card span {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.card-image {
  height: 180px;
  border-radius: 18px;
  background: linear-gradient(145deg, #f6d1dd, #f9f0f4);
}

.aesthetic-card.noir .card-image {
  background: linear-gradient(160deg, #2b2730, #6a646f);
}

.aesthetic-card.retro .card-image {
  background: linear-gradient(160deg, #f3b6c7, #d782b4);
}

.aesthetic-card.glow .card-image {
  background: linear-gradient(160deg, #f5c6a1, #f9e1ba);
}

.floating {
  position: fixed;
  right: 32px;
  bottom: 32px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #7c3b54;
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 18px 40px rgba(124, 59, 84, 0.3);
}

@media (max-width: 900px) {
  .hero-copy,
  .theme-card {
    padding: 28px;
  }

  .section-title.inline {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}
</style>
