import{a2 as V,g as z,l as x,k as j,a3 as E,m as $,u as H,f as q,o,c as n,a as r,b,w as y,t as _,d as C,a4 as F,i as d,j as N,X as G,W as U,s as D,v as J,x as Q,F as P,r as Y,A as W}from"./CN-e9H4V.js";import{_ as X}from"./51eKFUUA.js";const L="gamma-market-cart-v1",Ne=V("cart",()=>{const t=x([]),l=x({name:"",addressLine1:"",addressLine2:"",city:"",postalCode:"",country:"",email:"",phone:"",notes:""}),u=x(""),c=x(null),m=x({orderId:"",status:"idle",submittedEventId:"",invoice:"",invoiceAmount:"",invoiceExpiration:""});(()=>{const s=localStorage.getItem(L);if(s)try{const a=JSON.parse(s);t.value=a.items||[],l.value={...l.value,...a.shippingInfo||{}},u.value=a.shippingReference||"",c.value=a.guestKeys||null,m.value={...m.value,...a.orderState||{}}}catch{localStorage.removeItem(L)}})(),z([t,l,u,c,m],()=>{const s={items:t.value,shippingInfo:l.value,shippingReference:u.value,guestKeys:c.value,orderState:m.value};localStorage.setItem(L,JSON.stringify(s))},{deep:!0});const f=j(()=>t.value.reduce((s,a)=>{const i=Number(a.price?.amount||0);return s+i*a.quantity},0)),v=j(()=>t.value.reduce((s,a)=>s+a.quantity,0)),g=(s,a=1)=>{const i=t.value.find(e=>e.reference===s.reference);if(i){i.quantity+=a;return}t.value.push({reference:s.reference,d:s.d,title:s.title,image:s.image,price:s.price,quantity:a})},k=s=>{t.value=t.value.filter(a=>a.reference!==s)},w=(s,a)=>{const i=t.value.find(e=>e.reference===s);i&&(i.quantity=Math.max(1,Number(a)||1))},S=s=>{l.value={...l.value,...s}},T=s=>{c.value=s},M=s=>{m.value={...m.value,...s}},I=()=>{u.value="",m.value={orderId:"",status:"idle",submittedEventId:"",invoice:"",invoiceAmount:"",invoiceExpiration:""}};return{items:t,shippingInfo:l,shippingReference:u,guestKeys:c,orderState:m,subtotal:f,totalItems:v,addToCart:g,removeFromCart:k,updateQuantity:w,setShippingInfo:S,setGuestKeys:T,setOrderState:M,clearCheckout:I,clearCart:()=>{t.value=[],I()}}}),A="gamma-market-theme",O=t=>t==="light"?"light":"dark",Z=()=>{const t=E("theme-mode",()=>"dark"),l=E("shop-bootstrap-state",()=>({merchantTheme:null,merchantThemeMode:""})),u=j(()=>!!l.value?.merchantTheme);z(()=>[u.value,l.value?.merchantThemeMode],()=>{if(!u.value)return;const f=O(l.value?.merchantThemeMode||"dark");t.value=f,document.documentElement.setAttribute("data-theme",f)},{immediate:!0});const c=f=>{if(u.value){const g=l.value?.merchantThemeMode||"dark";t.value=O(g),document.documentElement.setAttribute("data-theme",t.value);return}const v=O(f);t.value=v,document.documentElement.setAttribute("data-theme",v),localStorage.setItem(A,v)};return{theme:t,hasMerchantTheme:u,initializeTheme:()=>{if(u.value){c(l.value?.merchantThemeMode||"dark");return}const f=localStorage.getItem(A);c(f||"dark")},applyTheme:c,toggleTheme:()=>{u.value||c(t.value==="dark"?"light":"dark")}}},ee={class:"sticky top-0 z-10 border-b border-[var(--line)] bg-[color:var(--surface)]/95 backdrop-blur"},te={class:"mx-auto flex max-w-6xl items-center px-4 py-3 sm:px-6 lg:px-8"},se={class:"flex flex-1 justify-start"},re=["src"],ae={key:1,class:"flex h-9 w-9 items-center justify-center rounded-full border border-[var(--line)] bg-stone-100 text-xs font-bold text-[var(--muted)]"},oe={class:"hidden items-center gap-4 text-sm font-medium sm:gap-6 md:flex"},ne={class:"flex flex-1 items-center justify-end gap-4 text-sm font-medium"},le={class:"text-xs font-semibold"},ie=["href"],de={class:"sr-only"},ue={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7",class:"h-5 w-5","aria-hidden":"true"},ce={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7",class:"h-5 w-5","aria-hidden":"true"},me={xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8",class:"h-5 w-5","aria-hidden":"true"},he={key:0,d:"M4 7h16M4 12h16M4 17h16"},pe={key:1,d:"M6 6l12 12M18 6 6 18"},ve={key:0,class:"border-b border-[var(--line)] bg-[var(--surface)] md:hidden"},fe={class:"mx-auto flex max-w-6xl flex-col gap-1 px-4 py-3 text-sm font-medium sm:px-6 lg:px-8"},ge={class:"w-full max-w-2xl rounded-2xl border border-[var(--line)] bg-[var(--surface)] p-5 shadow-2xl"},xe={class:"flex items-center justify-between gap-3"},ye={key:0,class:"mt-3 text-sm text-[var(--muted)]"},be={key:1,class:"mt-3 rounded-lg border border-red-200 bg-red-50 p-2 text-sm text-red-800"},ke={key:2,class:"mt-3 text-sm text-[var(--muted)]"},we={key:3,class:"mt-3 text-sm text-[var(--muted)]"},Se={key:4,class:"mt-3 space-y-2"},_e={class:"min-w-0 truncate text-sm font-medium"},Ce={class:"shrink-0 text-xs text-[var(--muted)]"},Me="/nostr-assets/nostr-logo-black.svg",je={__name:"ShopHeader",props:{itemCount:{type:Number,default:0},merchantProfile:{type:Object,default:null},merchantNpub:{type:String,default:""}},setup(t){const{theme:l,hasMerchantTheme:u,initializeTheme:c,toggleTheme:m}=Z(),{ensureBootstrap:R}=$(),f=H(),v=x(!1),g=x(!1),k=x(""),w=x(!1),S=x(""),T=E("shop-search-inventory",()=>[]),M=E("shop-search-loaded",()=>!1),I=async()=>{if(!(w.value||M.value)){w.value=!0,S.value="";try{const i=await R();T.value=i.products||[],M.value=!0}catch(i){S.value=i.message||"Could not load products for search."}finally{w.value=!1}}},B=async()=>{v.value=!0,g.value=!1,M.value||await I()},s=j(()=>{const i=k.value.trim().toLowerCase();return i?T.value.filter(e=>{const h=(e.categories||[]).map(K=>String(K||"").trim()).filter(Boolean);return[e.title,e.summary,e.description,...h,h.length?"":"uncategorized"].join(" ").toLowerCase().includes(i)}).slice(0,5):[]}),a=i=>`/product/${encodeURIComponent(i.d)}`;return z(()=>f.fullPath,()=>{v.value=!1,g.value=!1}),q(()=>{c()}),(i,e)=>{const h=X;return o(),n(P,null,[r("header",ee,[r("div",te,[r("div",se,[b(h,{to:"/",class:"flex items-center gap-3 text-lg font-semibold tracking-tight"},{default:y(()=>[t.merchantProfile?.picture?(o(),n("img",{key:0,src:t.merchantProfile.picture,alt:"Merchant profile",class:"h-9 w-9 rounded-full border border-[var(--line)] object-cover"},null,8,re)):(o(),n("div",ae," M ")),r("span",null,_(t.merchantProfile?.name||"loading"),1)]),_:1})]),r("nav",oe,[b(h,{to:"/"},{default:y(()=>[...e[5]||(e[5]=[C("Home",-1)])]),_:1}),b(h,{to:"/products"},{default:y(()=>[...e[6]||(e[6]=[C("Products",-1)])]),_:1}),b(h,{to:"/categories"},{default:y(()=>[...e[7]||(e[7]=[C("Categories",-1)])]),_:1}),r("button",{class:"cursor-pointer",onClick:B},"Search")]),r("nav",ne,[b(h,{to:"/cart",class:"inline-flex items-center gap-2 rounded-full border border-[var(--line)] px-2 py-1.5"},{default:y(()=>[e[8]||(e[8]=r("span",{class:"sr-only"},"Open cart",-1)),e[9]||(e[9]=r("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8",class:"h-5 w-5","aria-hidden":"true"},[r("circle",{cx:"9",cy:"20",r:"1.5"}),r("circle",{cx:"18",cy:"20",r:"1.5"}),r("path",{d:"M3 4h2l2.2 10.2a2 2 0 0 0 2 1.6h7.8a2 2 0 0 0 2-1.5L21 7H7.5"})],-1)),r("span",le,_(t.itemCount),1)]),_:1}),t.merchantNpub?(o(),n("a",{key:0,href:`https://njump.me/${t.merchantNpub}`,target:"_blank",rel:"noopener noreferrer",class:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-[var(--line)]"},[e[10]||(e[10]=r("span",{class:"sr-only"},"Open merchant npub",-1)),r("img",{src:Me,alt:"",class:"h-5 w-5 object-contain",style:F({filter:d(l)==="dark"?"invert(1)":"none"}),"aria-hidden":"true"},null,4)],8,ie)):N("",!0),d(u)?N("",!0):(o(),n("button",{key:1,class:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-[var(--line)]",onClick:e[0]||(e[0]=(...p)=>d(m)&&d(m)(...p))},[r("span",de,_(d(l)==="dark"?"Switch to light mode":"Switch to dark mode"),1),d(l)==="dark"?(o(),n("svg",ue,[...e[11]||(e[11]=[G('',9)])])):(o(),n("svg",ce,[...e[12]||(e[12]=[r("path",{d:"M12 3a7 7 0 1 0 9 9 9 9 0 1 1-9-9z"},null,-1)])]))])),r("button",{class:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-[var(--line)] md:hidden",onClick:e[1]||(e[1]=p=>g.value=!d(g))},[e[13]||(e[13]=r("span",{class:"sr-only"},"Toggle menu",-1)),(o(),n("svg",me,[d(g)?(o(),n("path",pe)):(o(),n("path",he))]))])])])]),d(g)?(o(),n("div",ve,[r("nav",fe,[b(h,{to:"/",class:"rounded-lg px-3 py-2"},{default:y(()=>[...e[14]||(e[14]=[C("Home",-1)])]),_:1}),b(h,{to:"/products",class:"rounded-lg px-3 py-2"},{default:y(()=>[...e[15]||(e[15]=[C("Products",-1)])]),_:1}),b(h,{to:"/categories",class:"rounded-lg px-3 py-2"},{default:y(()=>[...e[16]||(e[16]=[C("Categories",-1)])]),_:1}),r("button",{class:"rounded-lg px-3 py-2 text-left",onClick:B},"Search")])])):N("",!0),d(v)?(o(),n("div",{key:1,class:"fixed inset-0 z-50 flex items-start justify-center bg-black/60 px-4 pt-20",onClick:e[4]||(e[4]=U(p=>v.value=!1,["self"]))},[r("div",ge,[r("div",xe,[e[17]||(e[17]=r("h2",{class:"text-lg font-semibold"},"Search Products",-1)),r("button",{class:"rounded border border-[var(--line)] px-2 py-1 text-xs",onClick:e[2]||(e[2]=p=>v.value=!1)},"Close")]),D(r("input",{"onUpdate:modelValue":e[3]||(e[3]=p=>Q(k)?k.value=p:null),type:"search",placeholder:"Type to search products",class:"mt-4 w-full rounded-lg border border-[var(--line)] bg-white px-3 py-2 text-sm text-black"},null,512),[[J,d(k)]]),d(w)?(o(),n("p",ye,"Loading inventory…")):d(S)?(o(),n("p",be,_(d(S)),1)):d(k).trim()?d(s).length===0?(o(),n("p",we,"No matching products.")):(o(),n("div",Se,[(o(!0),n(P,null,Y(d(s),p=>(o(),W(h,{key:p.id,to:a(p),class:"flex items-center justify-between gap-3 rounded-lg border border-[var(--line)] px-3 py-2 hover:bg-black/5"},{default:y(()=>[r("span",_e,_(p.title),1),r("span",Ce,_(p.price.display),1)]),_:2},1032,["to"]))),128))])):(o(),n("p",ke,"Start typing to see up to 5 matching products."))])])):N("",!0)],64)}}};export{je as _,Ne as u};