/* Products listing, Product Detail, Cart, Order Success. Exposes window.AXShop. */
(function(){
const { Button, IconButton, Badge, Rating, PriceTag, QuantityStepper, Eyebrow, ProductCard } = window.AXUI;
const Ic=()=>window.AXIcons; const D=()=>window.AX_DATA;
const wrap={maxWidth:'var(--container-max)',margin:'0 auto',padding:'0 var(--gutter)'};
const cats=['Short Sleeve Tees','Hoodies & Sweatshirts','Tops','Caps','Hanfu Dresses','Plaid Shirts','Pants','Outerwear'];
const sorts=[['featured','Featured'],['price-asc','Price: Low to High'],['price-desc','Price: High to Low'],['newest','Newest']];
/* ---------------- PRODUCTS ---------------- */
function Products({ initialLabel, query, onAdd, onView, onNav }){
const labelCat = cats.includes(initialLabel) ? [initialLabel] : [];
const [selCats,setSelCats]=React.useState(labelCat);
const [maxPrice,setMaxPrice]=React.useState(150);
const [minRating,setMinRating]=React.useState(0);
const [sort,setSort]=React.useState('featured');
const i=Ic();
const toggle=(c)=>setSelCats(s=>s.includes(c)?s.filter(x=>x!==c):[...s,c]);
let list=D().products.filter(p=>
(selCats.length===0||selCats.includes(p.category)) &&
p.price<=maxPrice && p.rating>=minRating &&
(!query||p.name.toLowerCase().includes(query.toLowerCase())||p.category.toLowerCase().includes(query.toLowerCase()))
);
if(sort==='price-asc')list=[...list].sort((a,b)=>a.price-b.price);
if(sort==='price-desc')list=[...list].sort((a,b)=>b.price-a.price);
if(sort==='newest')list=[...list].sort((a,b)=>(b.badge==='New')-(a.badge==='New'));
const title = initialLabel && !cats.includes(initialLabel) ? initialLabel : (selCats.length===1?selCats[0]:'All Products');
return
{e.preventDefault();onNav({type:'home'});}} style={{color:'var(--text-muted)'}}>Home
{React.createElement(i.ChevronRight,{size:14,style:{color:'var(--text-faint)'}})}{title}
Shop
{title}
{list.length} products
setSort(e.target.value)} style={{border:'none',outline:'none',background:'transparent',fontFamily:'var(--font-body)',fontSize:'var(--fs-sm)',fontWeight:600,color:'var(--text-strong)',cursor:'pointer'}}>
{sorts.map(([v,l])=>{l} )}
{cats.map(c=>
toggle(c)} style={{width:20,height:20,borderRadius:6,border:`1.5px solid ${selCats.includes(c)?'var(--blue-600)':'var(--border-strong)'}`,background:selCats.includes(c)?'var(--blue-600)':'#fff',display:'inline-flex',alignItems:'center',justifyContent:'center',color:'#fff',flex:'0 0 auto'}}>{selCats.includes(c)&&React.createElement(i.Check,{size:13,sw:3})}
toggle(c)}>{c}
)}
setMaxPrice(+e.target.value)} style={{width:'100%',accentColor:'var(--blue-600)'}}/>
$20 $150+
{[4,3,0].map(r=>setMinRating(r)}>
{minRating===r&&}
{r===0?'All ratings':`${r}.0 & up`}
)}
{list.length===0 ?
No products match your filters.
:
}
;
}
function FilterBlock({ title, children }){
return ;
}
/* ---------------- PRODUCT DETAIL ---------------- */
function ProductDetail({ product, onAdd, onBuy, onView, onNav }){
const [qty,setQty]=React.useState(1);
const [tab,setTab]=React.useState('Description');
const [active,setActive]=React.useState(0);
const i=Ic();
const tiles=[product.image || product.accent,'linear-gradient(135deg,#EEF2FF,#E0F7FB)','linear-gradient(135deg,#F4F7FF,#FDEFF6)','linear-gradient(135deg,#EAFBF2,#E7F1FF)'];
const related=D().products.filter(p=>p.category===product.category&&p.id!==product.id).slice(0,4);
const tabs=['Description','Features','Specifications','Shipping & Returns','Reviews'];
return
{e.preventDefault();onNav({type:'home'});}} style={{color:'var(--text-muted)'}}>Home
{React.createElement(i.ChevronRight,{size:14})}{e.preventDefault();onNav({type:'products',label:product.category});}} style={{color:'var(--text-muted)'}}>{product.category}
{React.createElement(i.ChevronRight,{size:14})}{product.name}
{product.badge &&
{product.badge}
}
{active===0&&product.image
?
:
{product.name.charAt(0)} }
{tiles.map((t,k)=>
setActive(k)} style={{flex:1,aspectRatio:'1/1',borderRadius:'var(--radius-lg)',background:k===0&&product.image?'var(--surface-card)':t,border:`2px solid ${active===k?'var(--blue-600)':'var(--border-subtle)'}`,cursor:'pointer',overflow:'hidden',padding:0}}>
{k===0&&product.image ? : null}
)}
{product.category}
{product.name}
·
{React.createElement(i.Check,{size:15})} In stock · {product.stock} left
{product.description}
onAdd(product,qty)} style={{flex:1,minWidth:180}}>Add to Cart
onBuy(product,qty)}>Buy Now
{[['Truck','Free shipping over $49'],['Refresh','30-day returns'],['Shield','2-year warranty']].map(([ic,t])=>{React.createElement(i[ic],{size:17,style:{color:'var(--blue-600)'}})}{t} )}
{tabs.map(t=>setTab(t)} style={{padding:'12px 14px',background:'none',border:'none',borderBottom:`2px solid ${tab===t?'var(--blue-600)':'transparent'}`,color:tab===t?'var(--text-strong)':'var(--text-muted)',fontFamily:'var(--font-body)',fontWeight:600,fontSize:'var(--fs-sm)',cursor:'pointer',whiteSpace:'nowrap',marginBottom:-1}}>{t} )}
{tab==='Description' &&
{product.description} Designed and quality-checked by AshopNexa, every order ships carbon-neutral and is backed by our satisfaction guarantee.
}
{tab==='Features' &&
{product.features.map(f=>{React.createElement(i.Check,{size:16,sw:2.5})} {f} )} }
{tab==='Specifications' &&
{Object.entries(product.specifications).map(([k,v])=>{k} {v} )}
}
{tab==='Shipping & Returns' &&
Free standard shipping on orders over $49 (3–5 business days). Express options at checkout. Not the right fit? Return any unused item within 30 days for a full refund — we even cover return shipping on your first order.
}
{tab==='Reviews' &&
{D().reviews.map((r,k)=>
)}
}
Related products
{related.map(p=>
onAdd(pp,1)} onView={onView}/>)}
;
}
/* ---------------- CART ---------------- */
function Cart({ items, onQty, onRemove, onNav, onCheckout }){
const i=Ic();
const sub=items.reduce((s,it)=>s+it.price*it.qty,0);
const ship=sub>49||sub===0?0:6.99;
const tax=+(sub*0.08).toFixed(2);
const total=+(sub+ship+tax).toFixed(2);
if(items.length===0) return
{React.createElement(i.Cart,{size:32})}
Your cart is empty
Looks like you haven't added anything yet.
onNav({type:'products',label:'Best Sellers'})}>Start shopping
;
return
Shopping cart ({items.length})
{items.map(it=>
{it.name.charAt(0)}
onQty(it.id,q)} max={it.stock}/>
onRemove(it.id)} style={{display:'inline-flex',alignItems:'center',gap:5,background:'none',border:'none',cursor:'pointer',color:'var(--text-faint)',fontSize:'var(--fs-sm)'}} onMouseEnter={e=>e.currentTarget.style.color='var(--status-danger)'} onMouseLeave={e=>e.currentTarget.style.color='var(--text-faint)'}>{React.createElement(i.Trash,{size:15})} Remove
)}
onNav({type:'products',label:'Best Sellers'})} style={{alignSelf:'flex-start',display:'inline-flex',alignItems:'center',gap:6,background:'none',border:'none',cursor:'pointer',color:'var(--blue-600)',fontWeight:600,fontSize:'var(--fs-base)',marginTop:6}}>← Continue shopping
;
}
function OrderSummary({ sub, ship, tax, total, onCheckout, cta='Proceed to Checkout' }){
const i=Ic();
const row=(l,v,strong)=>{l} {v}
;
return
Order summary
{row('Subtotal','$'+sub.toFixed(2))}
{row('Shipping',ship===0?'Free':'$'+ship.toFixed(2))}
{row('Estimated tax','$'+tax.toFixed(2))}
{sub>0 && sub<49 &&
Add ${(49-sub).toFixed(2)} more for free shipping
}
{row('Total','$'+total.toFixed(2),true)}
{cta}
{React.createElement(i.Lock,{size:14})} Secure 256-bit checkout
;
}
/* ---------------- ORDER SUCCESS ---------------- */
function OrderSuccess({ orderNo, onNav }){
const i=Ic();
return
{React.createElement(i.CheckCircle,{size:42})}
Thank you for your order!
Your order is confirmed. A receipt is on its way to you@example.com .
onNav({type:'track',order:orderNo})}>Track Order
onNav({type:'home'})}>Continue Shopping
;
}
window.AXShop = { Products, ProductDetail, Cart, OrderSummary, OrderSuccess };
})();