import{_ as j}from"./51eKFUUA.js";import{m as I,q as L,l as n,f as V,c as o,b as k,i as s,a as t,t as w,j as h,F as f,r as x,W as D,w as $,X as A,k as N,o as r,A as P,d as O}from"./CN-e9H4V.js";import{u as T,_ as W}from"./dpMmCQ8_.js";import{_ as S}from"./C-fgfmCx.js";import{a as E}from"./CcX5Eni-.js";const F={class:"min-h-screen pb-12"},G={class:"mx-auto max-w-6xl px-4 pt-8 sm:px-6 lg:px-8"},q={key:0,class:"mb-4 rounded-2xl border border-amber-200 bg-amber-50 p-4 text-amber-900"},z={key:1,class:"rounded-2xl border border-red-200 bg-red-50 p-4 text-red-800"},H={key:2,class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},Q={key:3,class:"rounded-2xl border border-[var(--line)] bg-[var(--surface)] p-8 text-center"},X={key:4},J={class:"mb-8"},K={class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},U={key:0},Y={class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},Z={class:"w-full max-w-xl rounded-2xl border border-[var(--line)] bg-[var(--surface)] p-6 shadow-2xl"},ee={class:"mt-4"},te={class:"mt-6 flex justify-end"},ie={__name:"index",setup(se){E({title:"Gamma Market Webshop",description:"Minimal NIP-99 webshop with Gamma market checkout flow."});const C=T(),{ensureBootstrap:M,bootstrapState:p}=I(),{setShopDebug:B}=L(),g=n(!0),c=n(""),u=n(""),v=n(p.value.identity?.merchantNpub||""),l=n(p.value.products||[]),y=n(p.value.merchantProfile||null),b=n(!1),m=n(!1),R=N(()=>l.value.slice(0,3)),_=N(()=>l.value.slice(3,15));return V(async()=>{try{const i=await M(),e=i.identity,d=i.relayMap;v.value=e?.merchantNpub||"",y.value=i.merchantProfile||null,l.value=i.products||[],b.value=!0,m.value=l.value.length===0,B({merchantNpub:e?.merchantNpub||"",merchantPubkey:e?.merchantPubkey||"",identitySource:e?.source||"",relaySource:d?.sources?.merchant||"",themeSource:i.merchantThemeSource||"none",merchantOutbox:d?.merchantOutbox||[],merchantInbox:d?.merchantInbox||[],paymentListenRelays:d?.paymentListenRelays||[],orderPublishRelays:d?.orderPublishRelays||[],lastPage:"index",details:{productsLoaded:l.value.length,noProductsConfirmed:l.value.length===0}})}catch{u.value="Relay connection failed while loading products. Please retry once relays are reachable.",c.value=""}finally{g.value=!1}}),(i,e)=>{const d=j;return r(),o("div",F,[k(W,{"item-count":s(C).totalItems,"merchant-profile":s(y),"merchant-npub":s(v)},null,8,["item-count","merchant-profile","merchant-npub"]),t("main",G,[s(u)?(r(),o("section",q,w(s(u)),1)):h("",!0),s(c)?(r(),o("section",z,w(s(c)),1)):s(g)?(r(),o("section",H,[(r(),o(f,null,x(6,a=>t("div",{key:a,class:"h-72 animate-pulse rounded-2xl border border-[var(--line)] bg-[var(--surface)]"})),64))])):s(b)&&s(l).length===0?(r(),o("section",Q,[...e[2]||(e[2]=[t("p",{class:"text-lg font-semibold"},"No products found for this merchant.",-1),t("p",{class:"mt-2 text-sm text-[var(--muted)]"},"This npub currently has no published listings.",-1)])])):(r(),o("section",X,[t("div",J,[e[3]||(e[3]=t("div",{class:"mb-3 flex items-end justify-between gap-3"},[t("h2",{class:"text-xl font-semibold tracking-tight"},"New Arrivals")],-1)),t("div",K,[(r(!0),o(f,null,x(s(R),a=>(r(),P(S,{key:a.id,product:a},null,8,["product"]))),128))])]),s(_).length?(r(),o("div",U,[e[4]||(e[4]=t("div",{class:"mb-3 flex items-end justify-between gap-3"},[t("h2",{class:"text-xl font-semibold tracking-tight"},"Inventory"),t("p",{class:"text-xs text-[var(--muted)]"},"Everything else in stock")],-1)),t("div",Y,[(r(!0),o(f,null,x(s(_),a=>(r(),P(S,{key:a.id,product:a},null,8,["product"]))),128))])])):h("",!0)]))]),s(m)&&s(b)&&!s(u)&&!s(c)?(r(),o("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4",onClick:e[1]||(e[1]=D(a=>m.value=!1,["self"]))},[t("div",Z,[e[6]||(e[6]=t("h2",{class:"text-2xl font-bold"},"No products yet",-1)),e[7]||(e[7]=t("p",{class:"mt-3 text-sm text-[var(--muted)]"}," Hey! Ready to start listing your first products? ",-1)),t("div",ee,[k(d,{to:"/portal",class:"inline-flex items-center rounded-lg bg-purple-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-purple-700"},{default:$(()=>[...e[5]||(e[5]=[O(" Open Merchant Portal ",-1)])]),_:1})]),e[8]||(e[8]=A('<p class="mt-2 text-sm text-[var(--muted)]"> Alternatively visit one of these marketplaces to publish your first listings: </p><div class="mt-4 flex flex-wrap gap-2"><a href="https://plebeian.market" target="_blank" rel="noopener noreferrer" class="rounded-full border border-[var(--line)] px-3 py-1 text-sm">plebeian.market</a><a href="https://shopstr.store" target="_blank" rel="noopener noreferrer" class="rounded-full border border-[var(--line)] px-3 py-1 text-sm">shopstr.store</a><a href="https://conduit.market" target="_blank" rel="noopener noreferrer" class="rounded-full border border-[var(--line)] px-3 py-1 text-sm">conduit.market</a></div>',2)),t("div",te,[t("button",{class:"rounded-lg border border-[var(--line)] px-4 py-2 text-sm",onClick:e[0]||(e[0]=a=>m.value=!1)}," Close ")])])])):h("",!0)])}}};export{ie as default};
