import{p as K,q as O,v as Q,f as G,a7 as H,m as l,h as W,g as Y,c as n,b as q,j as o,a as s,t as p,k as Z,F as P,r as N,x as M,y as J,z as A,l as b,o as a,U as X,C as ee}from"./DhTKlDYs.js";import{u as te,S as se,_ as re}from"./BKqvSnRA.js";import{_ as oe}from"./DuMRrxM0.js";import"./D6RH7Yzs.js";const ae={class:"flex min-h-screen flex-col"},ne={class:"mx-auto w-full max-w-6xl flex-1 px-4 pt-8 sm:px-6 lg:px-8"},le={key:0,class:"mb-4 rounded-2xl border border-amber-200 bg-amber-50 p-4 text-amber-900"},ce={key:1,class:"rounded-2xl border border-red-200 bg-red-50 p-4 text-red-800"},ie={key:2,class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},ue={key:3,class:"rounded-2xl border border-[var(--line)] bg-[var(--surface)] p-8 text-center"},de={key:4},me={class:"grid gap-6 lg:grid-cols-[280px_minmax(0,1fr)]"},pe={class:"h-fit rounded-2xl border border-[var(--line)] bg-[var(--surface)] p-4 lg:sticky lg:top-24"},he={class:"flex items-center justify-between gap-3"},ge=["disabled"],ye={class:"mt-4"},be={class:"mt-5"},fe={key:0,class:"mt-2 space-y-2"},ve={class:"flex items-center gap-2 text-sm"},xe=["value"],_e={class:"text-xs text-[var(--muted)]"},ke={key:1,class:"mt-2 text-sm text-[var(--muted)]"},Ce={class:"mb-3 flex items-end justify-between gap-3"},we={class:"text-xs text-[var(--muted)]"},Se={key:0,class:"rounded-2xl border border-[var(--line)] bg-[var(--surface)] p-8 text-center"},Pe={key:1,class:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3"},F="__uncategorized__",qe={__name:"products",setup(Ne){K({title:"Products",description:"Browse the full merchant inventory."});const U=te(),{ensureBootstrap:j,bootstrapState:f}=O(),{setShopDebug:D}=Q(),h=G(),I=H(),B=l(!0),v=l(""),x=l(""),_=l(f.value.identity?.merchantNpub||""),c=l(f.value.products||[]),k=l(f.value.merchantProfile||null),L=l(!1),m=l(""),u=l([]),C=r=>String(r||"").trim(),T=()=>Array.from(new Set([].concat(h.query.category||[]).map(C).filter(Boolean).map(r=>r.toLowerCase()))),V=r=>Array.from(new Set((r.categories||[]).map(C).filter(Boolean).map(e=>e.toLowerCase()))),R=b(()=>{const r=new Map;let e=0;for(const i of c.value){const d=Array.from(new Set((i.categories||[]).map(C).filter(Boolean)));if(!d.length){e+=1;continue}for(const S of d){const g=S.toLowerCase(),y=r.get(g)||{key:g,label:S,count:0};y.count+=1,r.set(g,y)}}const t=Array.from(r.values()).sort((i,d)=>i.label.localeCompare(d.label));return e>0&&t.push({key:F,label:"Uncategorized",count:e}),t}),w=b(()=>{const r=m.value.trim().toLowerCase(),e=new Set(u.value);return c.value.filter(t=>{const i=V(t),d=i.length===0;return e.size===0||e.has(F)&&d||i.some(y=>e.has(y))?r?[t.title,t.summary,t.description,...t.categories||[],d?"uncategorized":""].join(" ").toLowerCase().includes(r):!0:!1})}),z=b(()=>m.value.trim().length>0||u.value.length>0),$=b(()=>z.value?`${w.value.length} of ${c.value.length} items`:`${c.value.length} items`),E=()=>{m.value="",u.value=[],h.query.category&&I.replace({query:{...h.query,category:void 0}})};return W(()=>h.query.category,()=>{u.value=T()},{immediate:!0}),Y(async()=>{try{const r=await j(),e=r.identity,t=r.relayMap;_.value=e?.merchantNpub||"",k.value=r.merchantProfile||null,c.value=r.products||[],L.value=!0,D({merchantNpub:e?.merchantNpub||"",merchantPubkey:e?.merchantPubkey||"",identitySource:e?.source||"",relaySource:t?.sources?.merchant||"",themeSource:r.merchantThemeSource||"none",merchantOutbox:t?.merchantOutbox||[],merchantInbox:t?.merchantInbox||[],paymentListenRelays:t?.paymentListenRelays||[],orderPublishRelays:t?.orderPublishRelays||[],lastPage:"products",details:{productsLoaded:c.value.length,noProductsConfirmed:c.value.length===0}})}catch{x.value="Relay connection failed while loading products. Please retry once relays are reachable.",v.value=""}finally{B.value=!1}}),(r,e)=>(a(),n("div",ae,[q(se,{"item-count":o(U).totalItems,"merchant-profile":o(k),"merchant-npub":o(_)},null,8,["item-count","merchant-profile","merchant-npub"]),s("main",ne,[o(x)?(a(),n("section",le,p(o(x)),1)):Z("",!0),o(v)?(a(),n("section",ce,p(o(v)),1)):o(B)?(a(),n("section",ie,[(a(),n(P,null,N(9,t=>s("div",{key:t,class:"h-72 animate-pulse rounded-2xl border border-[var(--line)] bg-[var(--surface)]"})),64))])):o(L)&&o(c).length===0?(a(),n("section",ue,[...e[2]||(e[2]=[s("p",{class:"text-lg font-semibold"},"No products found for this merchant.",-1),s("p",{class:"mt-2 text-sm text-[var(--muted)]"},"This npub currently has no published listings.",-1)])])):(a(),n("section",de,[s("div",me,[s("aside",pe,[s("div",he,[e[3]||(e[3]=s("h2",{class:"text-base font-semibold tracking-tight"},"Filters",-1)),s("button",{class:"rounded border border-[var(--line)] px-2 py-1 text-xs",disabled:!o(z),onClick:E}," Clear ",8,ge)]),s("div",ye,[e[4]||(e[4]=s("label",{for:"product-search",class:"text-xs font-semibold uppercase tracking-[0.08em] text-[var(--muted)]"},"Search",-1)),M(s("input",{id:"product-search","onUpdate:modelValue":e[0]||(e[0]=t=>A(m)?m.value=t:null),type:"search",placeholder:"Search products",class:"mt-2 w-full rounded-lg border border-[var(--line)] bg-white px-3 py-2 text-sm text-black"},null,512),[[J,o(m)]])]),s("div",be,[e[5]||(e[5]=s("p",{class:"text-xs font-semibold uppercase tracking-[0.08em] text-[var(--muted)]"},"Categories",-1)),o(R).length?(a(),n("div",fe,[(a(!0),n(P,null,N(o(R),t=>(a(),n("label",{key:t.key,class:"flex cursor-pointer items-center justify-between gap-2 rounded-lg border border-[var(--line)] px-2 py-1.5"},[s("span",ve,[M(s("input",{"onUpdate:modelValue":e[1]||(e[1]=i=>A(u)?u.value=i:null),type:"checkbox",value:t.key,class:"h-4 w-4 rounded border-[var(--line)]"},null,8,xe),[[X,o(u)]]),s("span",null,p(t.label),1)]),s("span",_e,p(t.count),1)]))),128))])):(a(),n("p",ke,"No categories available."))])]),s("div",null,[s("div",Ce,[e[6]||(e[6]=s("h2",{class:"text-xl font-semibold tracking-tight"},"Full Inventory",-1)),s("p",we,p(o($)),1)]),o(w).length===0?(a(),n("div",Se,[...e[7]||(e[7]=[s("p",{class:"text-lg font-semibold"},"No matching products.",-1),s("p",{class:"mt-2 text-sm text-[var(--muted)]"},"Try a different search term or clear filters.",-1)])])):(a(),n("div",Pe,[(a(!0),n(P,null,N(o(w),t=>(a(),ee(oe,{key:t.id,product:t},null,8,["product"]))),128))]))])])]))]),q(re,{"merchant-profile":o(k),"merchant-npub":o(_)},null,8,["merchant-profile","merchant-npub"])]))}};export{qe as default};
