veza/apps/web/dist_verification/assets/MarketplaceHome-DBtdadsi.js
2026-02-07 20:36:48 +01:00

1 line
9.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{j as e,a as r}from"./vendor-react-YMhRUmcb.js";import{m as z}from"./marketplaceService-BwlLR1ZR.js";import{C as H,b as se,c as te,f as re,s as V,e as ae,y as ne,B as l,h as le,g as $,D as ce,E as M,p as L,L as ie,d as oe,S as de}from"./index-D2uzyr9g.js";import{b8 as O,T as ue,S as me,aQ as xe,X as he,x as pe}from"./vendor-icons-DINCNwpk.js";import{I as fe,L as Q}from"./input-DL1WY4HG.js";import{u as J}from"./cartStore-C2PNCAMv.js";import{P as ge}from"./Pagination-DXc0wGeY.js";import"./vendor-fFnFILYR.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./vendor-utils-4BWoYre8.js";function je({product:a,onPurchase:m,onAddToCart:n,isPurchasing:x=!1}){const h=(d,b)=>new Intl.NumberFormat("fr-FR",{style:"currency",currency:b}).format(d);return e.jsxs(H,{className:"w-full h-full flex flex-col",children:[e.jsx(se,{children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(te,{className:"text-lg font-bold truncate",title:a.title,children:a.title}),e.jsx(re,{className:"line-clamp-2 mt-1",children:a.description})]}),e.jsx(V,{variant:a.product_type==="track"?"default":"secondary",children:a.product_type})]})}),e.jsxs(ae,{className:"flex-grow",children:[e.jsx("div",{className:"w-full h-32 bg-muted rounded-md flex items-center justify-center mb-4",children:e.jsx("span",{className:"text-muted-foreground text-sm",children:"No Cover"})}),e.jsx("div",{className:"text-2xl font-bold",children:h(a.price,a.currency)}),a.license_type&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["License: ",a.license_type]})]}),e.jsxs(ne,{className:"flex gap-2",children:[n&&e.jsxs(l,{variant:"outline",className:"flex-1",onClick:()=>n(a),children:[e.jsx(O,{className:"mr-2 h-4 w-4"})," Add to Cart"]}),e.jsx(l,{className:n?"flex-1":"w-full",onClick:()=>m(a),disabled:x,children:x?"Processing...":"Buy Now"})]})]})}function ye({isOpen:a,onClose:m}){const{items:n,removeItem:x,updateQuantity:h,clearCart:d,getTotal:b}=J(),{isAuthenticated:k}=le(),P=$(),[g,c]=r.useState(!1),[R,j]=r.useState(null),[y,N]=r.useState(null),[v,w]=r.useState(0),u=r.useRef(null),C=(t,p)=>new Intl.NumberFormat("fr-FR",{style:"currency",currency:p||"EUR"}).format(t),E=async()=>{if(j(null),N(null),!k){j("Please log in to checkout");return}if(n.length===0){j("Cart is empty");return}const t=n.map(i=>({product_id:i.product.id})),p=async()=>{await z.createOrder(t),P.success("Order placed successfully!"),d(),m(),N(null),w(0),u.current=null};u.current=p,c(!0);try{await p()}catch(i){const I=L(i);N(new Error(I.message))}finally{c(!1)}},S=async()=>{if(!(!u.current||v>=3)){w(t=>t+1),c(!0);try{await u.current()}catch{}finally{c(!1)}}};return e.jsx(ce,{open:a,onClose:m,title:"Shopping Cart",size:"lg",children:e.jsxs("div",{className:"space-y-4",children:[y&&e.jsx(M,{error:y,variant:"banner",severity:"error",onRetry:v<3?S:void 0,context:{action:"checking out",resource:"cart"},onDismiss:()=>{N(null),w(0),u.current=null}}),R&&e.jsx(M,{error:R,variant:"inline",severity:"error",size:"sm",dismissible:!1}),n.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(O,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Your cart is empty"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"max-h-96 overflow-y-auto space-y-2",children:n.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium",children:t.product.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[C(t.product.price,t.product.currency)," ×"," ",t.quantity]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(l,{variant:"outline",size:"sm",onClick:()=>h(t.product.id,t.quantity-1),children:"-"}),e.jsx("span",{className:"w-8 text-center",children:t.quantity}),e.jsx(l,{variant:"outline",size:"sm",onClick:()=>h(t.product.id,t.quantity+1),children:"+"}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>x(t.product.id),children:e.jsx(ue,{className:"h-4 w-4"})})]})]},t.product.id))}),e.jsxs("div",{className:"border-t pt-4 space-y-4",children:[e.jsxs("div",{className:"flex justify-between text-lg font-bold",children:[e.jsx("span",{children:"Total:"}),e.jsx("span",{children:n.length>0?C(b(),n[0].product.currency):"€0.00"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{variant:"outline",onClick:d,className:"flex-1",children:"Clear Cart"}),e.jsx(l,{onClick:E,disabled:g,className:"flex-1",children:g?"Processing...":"Checkout"})]})]})]})]})})}function Fe(){const[a,m]=r.useState([]),[n,x]=r.useState(!0),[h,d]=r.useState(null),[b,k]=r.useState(null),[P,g]=r.useState(0),c=r.useRef(null),[R,j]=r.useState(!1),[y,N]=r.useState(1),[v]=r.useState(12),[w,u]=r.useState(1),[C,E]=r.useState(0),S=r.useRef(!1),[t,p]=r.useState(""),[i,I]=r.useState(""),[o,D]=r.useState([0,1e3]),[F,U]=r.useState(!1),T=$(),{addItem:X,getItemCount:A}=J(),Y=async()=>{if(!S.current)try{S.current=!0,x(!0);const s={status:"active"};i&&(s.product_type=i),o[0]>0&&(s.min_price=o[0]),o[1]<1e3&&(s.max_price=o[1]),t.trim()&&(s.search=t.trim());const f=await z.fetchProducts(s,{page:y,limit:v});m(f.products),E(f.total),u(f.total_pages)}catch(s){const _=L(s).message||"Failed to load marketplace products";let q=0;s&&typeof s=="object"&&"httpStatus"in s&&(q=s.httpStatus),q===500?(m([]),E(0),u(1)):T.error(_)}finally{x(!1),S.current=!1}},G=JSON.stringify(o);r.useEffect(()=>{Y()},[y,v,i,G,t]);const K=s=>{X(s),T.success(`${s.title} added to cart`)},W=async s=>{const f=async()=>{await z.purchaseProduct(s.id),T.success(`Successfully purchased ${s.title}`),d(null),g(0),c.current=null};c.current=f,k(s.id),d(null);try{await f()}catch(_){d(new Error(L(_).message))}finally{k(null)}},Z=async()=>{if(!(!c.current||P>=3)){g(s=>s+1);try{await c.current()}catch{}}},ee=()=>{p(""),I(""),D([0,1e3])},B=t||i||o[0]>0||o[1]<1e3;return n&&a.length===0?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx(ie,{})}):e.jsxs("div",{className:"min-h-screen pb-24 relative",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-96 bg-gradient-to-b from-purple-900/20 via-background to-background pointer-events-none"}),e.jsxs("div",{className:"container mx-auto px-4 py-8 relative z-10",children:[h&&e.jsx(M,{error:h,variant:"banner",severity:"error",onRetry:P<3?Z:void 0,onDismiss:()=>{d(null),g(0),c.current=null}}),e.jsxs("div",{className:"flex items-end justify-between mb-8 gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl md:text-5xl font-display font-bold mb-2 text-transparent bg-clip-text bg-gradient-to-r from-white to-white/60",children:"Marketplace"}),e.jsx("p",{className:"text-lg text-muted-foreground",children:"Premium assets for your next masterpiece."})]}),e.jsxs(l,{onClick:()=>j(!0),className:"relative h-12 px-6 rounded-full shadow-glow-cyan",variant:"default",children:[e.jsx(O,{className:"mr-2 h-5 w-5"}),e.jsx("span",{className:"font-bold",children:"Cart"}),A()>0&&e.jsx(V,{className:"ml-2 bg-white text-primary font-bold shadow-none hover:bg-white",children:A()})]})]}),e.jsxs(H,{variant:"glass",className:"mb-8 p-4 sticky top-24 z-20 backdrop-blur-xl bg-black/40 border-white/10 shadow-xl",children:[e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(me,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(fe,{value:t,onChange:s=>p(s.target.value),placeholder:"Search tracks, packs, services...",className:"pl-10 bg-white/5 border-white/10 text-white placeholder:text-white/30 focus:bg-black/40 transition-all rounded-xl"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(l,{variant:"outline",onClick:()=>U(!F),className:oe("border-white/10 hover:bg-white/5",F&&"bg-primary/20 border-primary/50 text-white"),children:[e.jsx(xe,{className:"w-4 h-4 mr-2"})," Filters",B&&e.jsx("div",{className:"ml-2 w-2 h-2 rounded-full bg-primary shadow-[0_0_5px_var(--color-primary)]"})]}),B&&e.jsxs(l,{variant:"ghost",onClick:ee,className:"text-muted-foreground hover:text-white",children:[e.jsx(he,{className:"w-4 h-4 mr-2"})," Clear"]})]})]}),F&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8 pt-6 mt-4 border-t border-white/5 animate-slide-down",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(Q,{className:"text-xs uppercase tracking-widest text-muted-foreground",children:"Product Type"}),e.jsx("div",{className:"flex gap-2",children:["track","pack","service"].map(s=>e.jsx(l,{variant:i===s?"default":"outline",onClick:()=>I(i===s?"":s),size:"sm",className:"capitalize rounded-full px-6",children:s},s))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx(Q,{className:"text-xs uppercase tracking-widest text-muted-foreground",children:"Price Range"}),e.jsxs("span",{className:"text-sm font-mono text-primary",children:["€",o[0]," - €",o[1]]})]}),e.jsx(de,{min:0,max:1e3,step:10,value:o,onValueChange:s=>D([s[0],s[1]]),className:"py-4"})]})]})]}),!n&&e.jsxs("div",{className:"mb-6 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),e.jsxs("span",{children:["Found ",C," results"]})]}),a.length===0&&!n?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center opacity-60",children:[e.jsx(pe,{className:"w-16 h-16 mb-4 text-muted-foreground/50"}),e.jsx("h3",{className:"text-xl font-bold mb-2",children:"No items found"}),e.jsx("p",{className:"text-muted-foreground",children:"Try adjusting your signal filters."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 mb-8",children:a.map(s=>e.jsx(je,{product:s,onPurchase:W,onAddToCart:K,isPurchasing:b===s.id},s.id))}),e.jsx(ge,{currentPage:y,totalPages:w,onPageChange:N,totalItems:C,itemsPerPage:v,showItemsInfo:!0})]}),e.jsx(ye,{isOpen:R,onClose:()=>j(!1)})]})]})}export{Fe as MarketplaceHome};