const { useState, useEffect } = React; const fetchApi = async (url) => { const res = await fetch(url); return res.json(); }; function Navbar({ setView }) { return ( ); } function Footer() { return ( ); } function Home({ setView }) { const [data, setData] = useState({ categories: [], products: [], brands: [] }); const [loading, setLoading] = useState(true); useEffect(() => { window.scrollTo(0, 0); fetchApi('api/home.php').then(res => { if (res.success) setData(res.data); setLoading(false); }); }, []); const goToProduct = (prod) => { const slug = prod.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, ''); setView('product', prod.id, slug); }; if (loading) return
Loading Luxe Experience...
; return (
{/* HEROS */}

A Legacy You Wear

Uncompromising
craftsmanship

Discover an exclusive collection of luxury items crafted to perfection.

Luxury
{/* CATEGORIES */}

Shop By Category

{data.categories.map(cat => (
{cat.thumb_image ? ( {cat.name} ) : ( )}

{cat.name}

))} {data.categories.length===0 &&

No categories available.

}
{/* POPULAR PRODUCTS */}

Popular Products

View All
{data.products.map(prod => (
goToProduct(prod)} className="cursor-pointer bg-[#f7f7f7] relative w-full aspect-[4/5] flex items-center justify-center overflow-hidden"> {prod.main_image ? ( {prod.title} ) : ( )}
goToProduct(prod)}>

{prod.title}

AED {parseFloat(prod.price).toFixed(2)}

{/* WhatsApp Button - Smaller and inline */} e.stopPropagation()}> Inquire
))} {data.products.length === 0 &&

No products found.

}
{/* BRANDS */}
{data.brands.map(brand => (
{brand.thumb_image ? ( {brand.name} ) : (
{brand.name}
)}
))}
); } function Shop({ setView, initialFilters }) { const [data, setData] = useState({ categories: [], products: [], brands: [] }); const [loading, setLoading] = useState(true); useEffect(() => { window.scrollTo(0, 0); fetchApi('api/shop.php').then(res => { if (res.success) setData(res.data); setLoading(false); }); }, []); // Filter logic const { category, brands } = initialFilters; const filteredCategory = data.categories.find(c => c.slug === category) || null; let filteredProducts = data.products; // Recursive helper to get all child category IDs belonging to a parent const getDescendantCategoryIds = (catId, allCats) => { let ids = [parseInt(catId)]; const children = allCats.filter(c => parseInt(c.parent_id) === parseInt(catId)); children.forEach(child => { ids = ids.concat(getDescendantCategoryIds(child.id, allCats)); }); return ids; }; const getRootAncestor = (cat, allCats) => { if (!cat) return null; if (!cat.parent_id || cat.parent_id === '0') return cat; const parent = allCats.find(c => parseInt(c.id) === parseInt(cat.parent_id)); return getRootAncestor(parent, allCats); }; if (filteredCategory) { const validCatIds = getDescendantCategoryIds(filteredCategory.id, data.categories); filteredProducts = filteredProducts.filter(p => validCatIds.includes(parseInt(p.category_id))); } const activeTopCategory = getRootAncestor(filteredCategory, data.categories); // Isolate top-level categories for the UI selector const topLevelCategories = data.categories.filter(c => !c.parent_id || c.parent_id === '0' || c.parent_id === ''); const subCategoriesToDisplay = activeTopCategory ? data.categories.filter(c => parseInt(c.parent_id) === parseInt(activeTopCategory.id)) : []; // Extrapolate available brands to build the bottom bar filter const availableBrandIds = new Set(filteredProducts.map(p => parseInt(p.brand_id))); const availableBrands = data.brands.filter(b => availableBrandIds.has(parseInt(b.id))); // Actually apply brand filtering to the active products if (brands && brands.length > 0) { const brandIdsToKeep = data.brands.filter(b => brands.includes(b.slug)).map(b => parseInt(b.id)); filteredProducts = filteredProducts.filter(p => brandIdsToKeep.includes(parseInt(p.brand_id))); } const selectCategory = (catSlug) => { if (category === catSlug) return; setView('shop', null, '', { category: catSlug, brands: [] }); }; const toggleBrand = (brandSlug) => { let newBrands = brands ? [...brands] : []; if (newBrands.includes(brandSlug)) { newBrands = newBrands.filter(b => b !== brandSlug); } else { newBrands.push(brandSlug); } setView('shop', null, '', { category, brands: newBrands }); }; const goToProduct = (prod) => { const slug = prod.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, ''); setView('product', prod.id, slug); }; if (loading) return
Loading Catalog...
; return (
{/* Top Categories Horizontal Scroll */}
setView('shop', null, '', { category: null, brands: [] })} className={`snap-center shrink-0 flex flex-col items-center cursor-pointer w-20 transition-opacity ${!category ? 'opacity-100' : 'opacity-40 hover:opacity-100'}`}>
All
{topLevelCategories.map(cat => { const isActive = activeTopCategory && activeTopCategory.id === cat.id; return (
selectCategory(cat.slug)} className={`snap-center shrink-0 flex flex-col items-center cursor-pointer w-20 transition-opacity ${isActive ? 'opacity-100' : 'opacity-50 hover:opacity-100'}`}>
{cat.thumb_image ? : }
{cat.name}
)})}
{/* Product Grid */}

{filteredCategory ? filteredCategory.name : 'All Products'}

{filteredProducts.length} items
{/* Sub-categories row */} {subCategoriesToDisplay.length > 0 && (
{subCategoriesToDisplay.map(subCat => ( ))}
)}
{filteredProducts.map(prod => (
goToProduct(prod)} className="cursor-pointer bg-[#f7f7f7] relative w-full aspect-[4/5] flex items-center justify-center overflow-hidden"> {prod.main_image ? ( {prod.title} ) : ( )}
goToProduct(prod)}>

{prod.title}

AED {parseFloat(prod.price).toFixed(2)}

e.stopPropagation()}> Inquire
))} {filteredProducts.length === 0 &&

No products match your filters.

}
{/* Fixed Bottom Brands Bar (Multi-select pill navigation) */} {availableBrands.length > 0 && (
Filter: {availableBrands.map(b => ( ))}
)}
); } function ProductDetail({ productId, setView }) { const [product, setProduct] = useState(null); const [loading, setLoading] = useState(true); const [activeImage, setActiveImage] = useState(0); useEffect(() => { window.scrollTo(0, 0); fetchApi(`api/product.php?id=${productId}`).then(res => { if(res.success) setProduct(res.data); setLoading(false); }); }, [productId]); if (loading) return
Loading Details...
; if (!product) return
Product not found.
; const images = product.images || []; return (
{/* Top Breadcrumb */}
setView('home')}>Home / {product.category_name && <>{product.category_name} /} {product.title}
{/* Images Section */}
{images.map((img, i) => (
setActiveImage(i)} className={`w-20 h-24 lg:w-24 lg:h-28 flex-shrink-0 rounded-lg overflow-hidden cursor-pointer border-2 transition-all ${activeImage === i ? 'border-black' : 'border-transparent opacity-60 hover:opacity-100'}`}> Thumb
))}
{images[activeImage] ? ( Main ) : ( )}
{/* Info Section */}
{product.brand_name &&

{product.brand_name}

}

{product.title}

AED {parseFloat(product.price).toFixed(2)}

{/* Description HTML rendered safely */}
Inquire via WhatsApp

Global Delivery

Securely tracked and fully insured shipping worldwide. Expected delivery times calculated upon inquiry.

Cash on Delivery

We offer Cash on Delivery (COD) services anywhere within the UAE.

); } function App() { const [view, setView] = useState('home'); const [currentProductId, setCurrentProductId] = useState(null); const [shopFilters, setShopFilters] = useState({ category: null, brands: [] }); // Dynamic Hash URL Routing useEffect(() => { const handleHashChange = () => { const hash = window.location.hash.replace('#', ''); if (hash.startsWith('product/')) { const part = hash.replace('product/', ''); const id = part.split('-')[0]; // Extract the ID before the dash setCurrentProductId(id); setView('product'); } else if (hash.startsWith('shop')) { const urlParams = new URLSearchParams(hash.split('?')[1] || ''); const cat = urlParams.get('category'); const brs = urlParams.get('brands'); setShopFilters({ category: cat || null, brands: brs ? brs.split(',') : [] }); setView('shop'); } else { setView('home'); } }; handleHashChange(); // Execute on initial loud window.addEventListener('hashchange', handleHashChange); return () => window.removeEventListener('hashchange', handleHashChange); }, []); // Custom router navigate const navigate = (newView, id = null, slug = '', params = {}) => { if (newView === 'home') { window.location.hash = ''; } else if (newView === 'product') { window.location.hash = `product/${id}${slug ? '-' + slug : ''}`; } else if (newView === 'shop') { const urlParams = new URLSearchParams(); if (params.category) urlParams.set('category', params.category); if (params.brands && params.brands.length > 0) urlParams.set('brands', params.brands.join(',')); const qs = urlParams.toString(); window.location.hash = `shop${qs ? '?' + qs : ''}`; } }; return (