import React, { useState, useEffect } from 'react'; import { ShoppingCart, X, Plus, Minus, MapPin, Phone, Clock, ArrowRight, CheckCircle2 } from 'lucide-react'; // --- 數據定義 (Data Models) --- // 基於資料驅動視圖的邏輯,將商品資訊獨立出來,便於未來串接資料庫 const PRODUCTS = [ { id: 1, name: '雲朵特級床墊', description: '多層次獨立筒與透氣記憶棉的完美結合,給予脊椎最適切的支撐。', price: 15800, image: 'https://images.unsplash.com/photo-1554995207-c18c203602cb?q=80&w=800&auto=format&fit=crop' }, { id: 2, name: '呼吸記憶枕', description: '慢回彈高密度材質,符合人體工學,釋放頸部壓力。', price: 2500, image: 'https://images.unsplash.com/photo-1584100936595-c0654b55a2e6?q=80&w=800&auto=format&fit=crop' }, { id: 3, name: '輕柔純棉被套組', description: '100% 雙層水洗棉,如同親膚內衣般的極致柔軟體驗。', price: 3200, image: 'https://images.unsplash.com/photo-1522771731535-64582f34791a?q=80&w=800&auto=format&fit=crop' } ]; export default function App() { // --- 狀態管理 (State Management) --- const [cart, setCart] = useState([]); const [isCartOpen, setIsCartOpen] = useState(false); const [toastMessage, setToastMessage] = useState(null); // --- 業務邏輯 (Business Logic) --- const addToCart = (product) => { setCart(prevCart => { const existingItem = prevCart.find(item => item.id === product.id); if (existingItem) { return prevCart.map(item => item.id === product.id ? { ...item, quantity: item.quantity + 1 } : item ); } return [...prevCart, { ...product, quantity: 1 }]; }); setIsCartOpen(true); }; const updateQuantity = (id, delta) => { setCart(prevCart => { return prevCart.map(item => { if (item.id === id) { const newQuantity = item.quantity + delta; return newQuantity > 0 ? { ...item, quantity: newQuantity } : null; } return item; }).filter(Boolean); // 過濾掉 null 的項目 (即數量被扣到 0 的商品) }); }; const handleCheckout = () => { if (cart.length === 0) return; // 模擬送出訂單 setIsCartOpen(false); setCart([]); showToast("訂單已成功送出!感謝您的購買。"); }; const showToast = (msg) => { setToastMessage(msg); setTimeout(() => setToastMessage(null), 3000); }; // 衍生狀態 (Derived State) const cartTotal = cart.reduce((total, item) => total + (item.price * item.quantity), 0); const cartItemCount = cart.reduce((count, item) => count + item.quantity, 0); return ( // 使用指定的色彩計畫,並設定全域字體與背景紋理
以現代日系簡約為核心,我們重新定義了寢具的有機感與舒適度。為理性的你,提供最純粹的支撐。
"支撐力符合物理力學,完美的平衡。"
去除多餘裝飾,只保留睡眠最需要的機能與舒適。
{product.description}
NT$ {product.price.toLocaleString()}
我們深知數據無法取代體感。歡迎來到我們位於台北的實體據點,親自感受每一寸材質的回饋力道與呼吸感。
106 台北市大安區羅斯福路四段1號
(近台大公館商圈)
週一至週日 11:00 - 21:00
02-2366-XXXX
您的購物車目前是空的
NT$ {item.price.toLocaleString()}