---
/**
 * Homepage - Main landing page
 * Fetches data from Payload CMS and renders all sections
 * Pixel-perfect implementation based on Webflow design
 */
import Layout from '../layouts/Layout.astro'
import HeroSection from '../sections/HeroSection.astro'
import PainpointSection from '../sections/PainpointSection.astro'
import StatisticsSection from '../sections/StatisticsSection.astro'
// ServiceFeatures - REMOVED: Services should only appear in Footer, not as a main section
// import ServiceFeatures from '../sections/ServiceFeatures.astro'
import ClientCasesSection from '../sections/ClientCasesSection.astro'
import PortfolioPreview from '../sections/PortfolioPreview.astro'
import CTASection from '../sections/CTASection.astro'
import { getHomepageData } from '../lib/api/home'
import type { HomeData, PortfolioItem } from '../lib/api/home'

// Fetch data from Payload CMS
let homeData: HomeData | null = null
let portfolioItems: PortfolioItem[] = []

try {
  const data = await getHomepageData()
  homeData = data.home
  portfolioItems = data.portfolioItems || []
} catch (error) {
  console.error('Failed to fetch homepage data:', error)
}

// Metadata for SEO
const title = '恩群數位行銷 | 專業數位行銷服務'
const description = '恩群數位行銷提供專業的 Google Ads、社群代操、論壇行銷、網站設計等全方位數位行銷服務，協助您的品牌在數位時代脫穎而出。'
---

<Layout title={title} description={description}>
  <!-- Hero Section -->
  <HeroSection homeData={homeData} />

  <!-- Painpoint Section (您的困擾) -->
  <PainpointSection homeData={homeData} />

  <!-- Statistics Section (數據統計) -->
  <StatisticsSection homeData={homeData} />

  <!-- Service Features - REMOVED: Services should only appear in Footer, not as a main section -->

  <!-- Client Cases Section (客戶案例) -->
  <ClientCasesSection homeData={homeData} />

  <!-- Portfolio Preview Section -->
  <PortfolioPreview homeData={homeData} portfolioItems={portfolioItems} />

  <!-- CTA Section -->
  <CTASection homeData={homeData} />
</Layout>
