import { Head, Link, router, InfiniteScroll } from '@inertiajs/react'; import { useState, useCallback, useRef } from 'react'; import { Search, ShoppingBag, Plus, ArrowRight, Star, Info, ChevronRight, Phone, MapPin, Mail, LogIn, Check, } from 'lucide-react'; import { formatRupiah } from '@/lib/rupiah'; import ProductCard from '@/components/home/ProductCard'; import ProductModal from '@/components/home/ProductModal'; import type { Product, Category, HomepageData, ProductPrice, Paginated } from '@/types/homepage'; type Props = { appName: string; aboutApp: string | null; contactEmail: string | null; contactPhone: string | null; contactAddress: string | null; instagramUrl: string | null; facebookUrl: string | null; tiktokUrl: string | null; homepage: HomepageData; categories: Category[]; products: Paginated; filters: { search: string; category: string }; seo: { title: string; description: string; image: string; url: string }; }; export default function Welcome({ appName, aboutApp, contactEmail, contactPhone, contactAddress, instagramUrl, facebookUrl, tiktokUrl, homepage, categories, products, filters, }: Props) { const [searchInput, setSearchInput] = useState(filters.search); const [selectedCategory, setSelectedCategory] = useState(filters.category); const [activeProduct, setActiveProduct] = useState(null); const searchTimeoutRef = useRef>(undefined); const getProductImage = (product: Product): string => { const fallbacks: Record = { daster: [ 'https://images.unsplash.com/photo-1595777457583-95e059d581b8?w=800&auto=format&fit=crop&q=80', ], 'setelan-celana': [ 'https://images.unsplash.com/photo-1539109136881-3be0616acf4b?w=800&auto=format&fit=crop&q=80', ], atasan: [ 'https://images.unsplash.com/photo-1515886657613-9f3515b0c78f?w=800&auto=format&fit=crop&q=80', ], bawahan: [ 'https://images.unsplash.com/photo-1583496661160-fb4886b36ca7?w=800&auto=format&fit=crop&q=80', ], }; const firstCat = product.categories?.[0]?.slug || ''; const urls = fallbacks[firstCat] || [ 'https://images.unsplash.com/photo-1490481651871-ab68de25d43d?w=800&auto=format&fit=crop&q=80', ]; return urls[0]; }; const getProductPriceRange = (product: Product): string => { const prices = product.product_variants.flatMap((v) => v.product_prices .filter((p: ProductPrice) => p.type === 'retail') .map((p: ProductPrice) => p.price), ); if (prices.length === 0) { const fallbackPrices = product.product_variants.flatMap((v) => v.product_prices.map((p: ProductPrice) => p.price), ); if (fallbackPrices.length === 0) return 'Rp 0'; const min = Math.min(...fallbackPrices); const max = Math.max(...fallbackPrices); return min === max ? `Rp ${formatRupiah(min)}` : `Rp ${formatRupiah(min)} - Rp ${formatRupiah(max)}`; } const min = Math.min(...prices); const max = Math.max(...prices); return min === max ? `Rp ${formatRupiah(min)}` : `Rp ${formatRupiah(min)} - Rp ${formatRupiah(max)}`; }; const fetchProducts = useCallback( (search: string, category: string) => { const params = new URLSearchParams(); if (search) params.set('search', search); if (category) params.set('category', category); const url = `/${params.toString() ? `?${params.toString()}` : ''}`; router.visit(url, { only: ['products', 'filters'], reset: ['products'], preserveState: true, preserveScroll: true, }); }, [], ); const handleSearchChange = useCallback( (value: string) => { setSearchInput(value); if (searchTimeoutRef.current) { clearTimeout(searchTimeoutRef.current); } searchTimeoutRef.current = setTimeout(() => { fetchProducts(value, selectedCategory); }, 400); }, [selectedCategory, fetchProducts], ); const handleCategoryChange = useCallback( (slug: string | null) => { const newCategory = slug ?? ''; setSelectedCategory(newCategory); fetchProducts(searchInput, newCategory); }, [searchInput, fetchProducts], ); const handleResetFilters = useCallback(() => { setSearchInput(''); setSelectedCategory(''); fetchProducts('', ''); }, [fetchProducts]); // Use first 3 products from current page as featured for hero const featuredProducts = products.data.slice(0, 3); return ( <>
{/* Sticky Header */}
{/* Hero Section */}
{/* Left Column */}
{homepage.hero_badge}

{homepage.hero_title_line1}
{homepage.hero_title_line2}{' '} {homepage.hero_title_highlight}

{homepage.hero_description}

{/* Center Column: Visual */}
{homepage.hero_bg_text_left} {homepage.hero_bg_text_right}
{appName}
{/* Floating Tag 1 */} {featuredProducts[0] && (
setActiveProduct(featuredProducts[0])} className="absolute top-10 left-4 md:-left-6 z-20 flex items-center space-x-3 bg-white/90 backdrop-blur-md p-3 rounded-2xl shadow-lg border border-amber-100/40 cursor-pointer transform hover:-translate-y-1 transition-all" > Preview Produk

Terpopuler

{featuredProducts[0].name}

{getProductPriceRange(featuredProducts[0])}
)} {/* Floating Tag 2 */} {featuredProducts[1] && (
setActiveProduct(featuredProducts[1])} className="absolute top-28 right-4 md:-right-6 z-20 flex items-center space-x-3 bg-white/90 backdrop-blur-md p-3 rounded-2xl shadow-lg border border-amber-100/40 cursor-pointer transform hover:-translate-y-1 transition-all" > Preview Produk
{[1, 2, 3, 4, 5].map((i) => ( ))}

{featuredProducts[1].name}

Stok Tersedia
)}
{/* Scroll Indicator */}
#{homepage.scroll_hashtag} {homepage.scroll_tagline}
Lihat katalog lengkap
{/* Catalog Section */}

{homepage.catalog_badge}

{homepage.catalog_title}

{homepage.catalog_description}

{/* Filters */}
handleSearchChange(e.target.value)} type="text" placeholder={homepage.catalog_search_placeholder} className="w-full bg-slate-50 border border-slate-200 text-xs px-4 py-3 pr-10 rounded-xl outline-none focus:border-amber-500 text-slate-700 transition-all" />
{categories.map((category) => ( ))}
{/* Product Grid with Infinite Scroll */} (
Memuat produk lainnya...
)} > {products.data.length > 0 ? (
{products.data.map((product) => ( ))}
) : (

Produk Tidak Ditemukan

Mohon maaf, kami tidak menemukan pakaian yang cocok dengan kata kunci pencarian Anda.

)}
{/* Gallery Section */} {/* Order Guide Section */}

{homepage.order_guide_badge}

{homepage.order_guide_title}

{homepage.order_guide_description}

{homepage.order_steps.map((step, index) => (
{index + 1}
{index === 0 && } {index === 1 && } {index === 2 && } {index === 3 && }
{step.title}

{step.description}

))}
{/* About Section */}
Tentang Kami
{homepage.about_badge}

{homepage.about_title}

{aboutApp || 'Kami adalah rumah produksi busana dan batik lokal berkualitas tinggi. Berfokus pada keindahan motif, ketepatan detail jahitan, dan pemilihan kain adem yang mengedepankan aspek fungsionalitas dan estetika.'}

{homepage.about_features.map((feature, index) => (
{feature}
))}
{/* Contact Section */}
{homepage.contact_badge}

{homepage.contact_title}

{homepage.contact_description}

{contactPhone && (
{contactPhone}
)} {contactEmail && (
{contactEmail}
)} {contactAddress && (
{contactAddress}
)}

{homepage.contact_form_title}