1import{c as te,k as B,r as b,a as q,j as e,f as z,B as _,x as ae,D as re,s as P,af as G,J as u,ap as U,aq as F,ar as I,as as $,at as C,a6 as H,a7 as W,a8 as Y,a9 as J,h as f,t as k,al as ne,Q as X,p as ue,X as Z,a_ as le}from"./index-C4LWZPK9.js";import{T as xe,a as me,b as E,c as V}from"./tabs-k4Vtuswt.js";import{T as ie}from"./textarea-G6LYtFU8.js";import{P as R}from"./plus-Nk5sUbpA.js";import{D as he}from"./dollar-sign-BoONtnCz.js";import{I as ce}from"./image-CxqL-AuT.js";import{P as de}from"./pencil-DiYrB8i9.js";import{T as ee}from"./tag-D7QmsNKQ.js";import{R as pe}from"./refresh-cw-CU0g5HPB.js";import{C as ge}from"./circle-check-big-CS9PldFe.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const je=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]],se=te("Package",je);/** 7 * @license lucide-react v0.475.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ve=[["path",{d:"M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2",key:"wrbu53"}],["path",{d:"M15 18H9",key:"1lyqi6"}],["path",{d:"M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14",key:"lysw3i"}],["circle",{cx:"17",cy:"18",r:"2",key:"332jqn"}],["circle",{cx:"7",cy:"18",r:"2",key:"19iecd"}]],be=te("Truck",ve);function T(i){return`$${((i||0)/100).toFixed(2)}`}function fe(i){return i?new Date(i).toLocaleDateString():"â"}const ye={pending:"bg-yellow-500/20 text-yellow-400",paid:"bg-blue-500/20 text-blue-400",fulfilled:"bg-purple-500/20 text-purple-400",shipped:"bg-accent/20 text-accent",delivered:"bg-green-500/20 text-green-400",refunded:"bg-destructive/20 text-destructive",cancelled:"bg-secondary text-muted-foreground"},oe=["pending","paid","fulfilled","shipped","delivered","refunded","cancelled"];function Ne({product:i,categories:y,onSave:h,onClose:n}){const[a,x]=b.useState(i||{name:"",description:"",short_description:"",category:"",price_cents:0,compare_at_price_cents:0,status:"draft",featured:!1,inventory:0,sku:"",shipping_note:"",preorder_enabled:!1,estimated_ship_date:"",images:[],variants:[],tags:[],sort_order:0}),[c,p]=b.useState({label:"",sku:"",inventory:0,price_cents:0}),[j,l]=b.useState(""),[v,r]=b.useState(!1),[d,M]=b.useState(!1),w=b.useRef(),m=(s,o)=>x(N=>({...N,[s]:o})),g=()=>{c.label&&(m("variants",[...a.variants||[],{...c,inventory:Number(c.inventory),price_cents:Number(c.price_cents)||a.price_cents}]),p({label:"",sku:"",inventory:0,price_cents:0}))},O=s=>m("variants",a.variants.filter((o,N)=>N!==s)),Q=(s,o)=>m("variants",a.variants.map((N,D)=>D===s?{...N,inventory:Number(o)}:N)),A=()=>{j.trim()&&(m("images",[...a.images||[],j.trim()]),l(""))},L=s=>m("images",a.images.filter((o,N)=>N!==s)),t=async s=>{if(!s)return;r(!0);const{file_url:o}=await f.integrations.Core.UploadFile({file:s});m("images",[...a.images||[],o]),r(!1)},S=async()=>{if(!a.name||!a.price_cents){k.error("Name and price required");return}M(!0),await h({...a,price_cents:Number(a.price_cents),compare_at_price_cents:Number(a.compare_at_price_cents)||0}),M(!1),n()};return e.jsxs("div",{className:"space-y-4 max-h-[75vh] overflow-y-auto pr-1",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Product Name *"}),e.jsx(u,{value:a.name,onChange:s=>m("name",s.target.value),placeholder:"e.g. Goby Wave Tee"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Price ($) *"}),e.jsx(u,{type:"number",value:a.price_cents/100||"",onChange:s=>m("price_cents",Math.round(parseFloat(s.target.value||0)*100)),placeholder:"25.00",step:"0.01"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Compare-at Price ($)"}),e.jsx(u,{type:"number",value:a.compare_at_price_cents/100||"",onChange:s=>m("compare_at_price_cents",Math.round(parseFloat(s.target.value||0)*100)),placeholder:"30.00",step:"0.01"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Category"}),e.jsxs(U,{value:a.category||"",onValueChange:s=>m("category",s),children:[e.jsx(F,{children:e.jsx(I,{placeholder:"Select category"})}),e.jsx($,{children:y.map(s=>e.jsx(C,{value:s.slug,children:s.name},s.slug))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Status"}),e.jsxs(U,{value:a.status,onValueChange:s=>m("status",s),children:[e.jsx(F,{children:e.jsx(I,{})}),e.jsxs($,{children:[e.jsx(C,{value:"draft",children:"Draft"}),e.jsx(C,{value:"published",children:"Published"}),e.jsx(C,{value:"coming_soon",children:"Coming Soon"}),e.jsx(C,{value:"archived",children:"Archived"})]})]})]}),a.status==="coming_soon"&&e.jsxs("div",{className:"col-span-2 space-y-3 p-3 bg-accent/5 rounded-lg border border-accent/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"preorder_enabled",checked:a.preorder_enabled||!1,onChange:s=>m("preorder_enabled",s.target.checked),className:"rounded"}),e.jsx("label",{htmlFor:"preorder_enabled",className:"text-sm font-medium",children:"Enable pre-orders (charge now, ship later)"})]}),a.preorder_enabled&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Estimated Ship Date"}),e.jsx(u,{type:"date",value:a.estimated_ship_date||"",onChange:s=>m("estimated_ship_date",s.target.value)})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"SKU"}),e.jsx(u,{value:a.sku||"",onChange:s=>m("sku",s.target.value),placeholder:"GOBY-TEE-001"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Sort Order"}),e.jsx(u,{type:"number",value:a.sort_order||0,onChange:s=>m("sort_order",Number(s.target.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Inventory (if no variants)"}),e.jsx(u,{type:"number",value:a.inventory||0,onChange:s=>m("inventory",Number(s.target.value))})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-5",children:[e.jsx("input",{type:"checkbox",id:"featured",checked:a.featured||!1,onChange:s=>m("featured",s.target.checked),className:"rounded"}),e.jsx("label",{htmlFor:"featured",className:"text-sm",children:"Featured product"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Short Description"}),e.jsx(u,{value:a.short_description||"",onChange:s=>m("short_description",s.target.value),placeholder:"Brief tagline..."})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Full Description"}),e.jsx(ie,{value:a.description||"",onChange:s=>m("description",s.target.value),placeholder:"Product details...",rows:3})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Shipping Note"}),e.jsx(u,{value:a.shipping_note||"",onChange:s=>m("shipping_note",s.target.value),placeholder:"Ships in 3-5 business days"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-2 block font-semibold uppercase tracking-wide",children:"Product Images"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(u,{value:j,onChange:s=>l(s.target.value),placeholder:"Paste image URL...",onKeyDown:s=>s.key==="Enter"&&A()}),e.jsx(_,{size:"sm",onClick:A,variant:"outline",children:e.jsx(R,{className:"w-4 h-4"})}),e.jsx(_,{size:"sm",variant:"outline",onClick:()=>{var s;return(s=w.current)==null?void 0:s.click()},disabled:v,children:v?e.jsx("div",{className:"w-4 h-4 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}):e.jsx(ce,{className:"w-4 h-4"})}),e.jsx("input",{ref:w,type:"file",accept:"image/*",className:"hidden",onChange:s=>t(s.target.files[0])})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:(a.images||[]).map((s,o)=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:s,alt:"",className:"w-16 h-16 object-cover rounded-lg border border-border"}),e.jsx("button",{onClick:()=>L(o),className:"absolute -top-1 -right-1 w-4 h-4 bg-destructive rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(Z,{className:"w-2.5 h-2.5 text-white"})})]},o))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-2 block font-semibold uppercase tracking-wide",children:"Variants (Size / Color)"}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 mb-2",children:[e.jsx(u,{placeholder:"Label (e.g. S)",value:c.label,onChange:s=>p(o=>({...o,label:s.target.value}))}),e.jsx(u,{placeholder:"SKU",value:c.sku,onChange:s=>p(o=>({...o,sku:s.target.value}))}),e.jsx(u,{type:"number",placeholder:"Inventory",value:c.inventory,onChange:s=>p(o=>({...o,inventory:s.target.value}))}),e.jsx(_,{size:"sm",onClick:g,variant:"outline",children:e.jsx(R,{className:"w-4 h-4"})})]}),(a.variants||[]).length>0&&e.jsx("div",{className:"space-y-1.5",children:a.variants.map((s,o)=>e.jsxs("div",{className:"flex items-center gap-2 bg-secondary/50 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium w-16",children:s.label}),e.jsx("span",{className:"text-xs text-muted-foreground flex-1",children:s.sku||"â"}),e.jsx(u,{type:"number",value:s.inventory||0,onChange:N=>Q(o,N.target.value),className:"w-20 h-7 text-xs"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"units"}),e.jsx("button",{onClick:()=>O(o),className:"text-destructive hover:text-destructive/80",children:e.jsx(Z,{className:"w-3.5 h-3.5"})})]},o))})]}),e.jsxs(le,{className:"pt-2",children:[e.jsx(_,{variant:"outline",onClick:n,children:"Cancel"}),e.jsx(_,{onClick:S,disabled:d,children:d?"Saving...":i?"Update Product":"Create Product"})]})]})}function _e(){const i=B(),{data:y=[]}=q({queryKey:["merch-categories-admin"],queryFn:()=>f.entities.MerchCategory.list("sort_order",100)}),[h,n]=b.useState({name:"",slug:"",description:"",sort_order:0,visible:!0}),[a,x]=b.useState(null),c=async()=>
11{if(!h.name||!h.slug){k.error("Name and slug required");return}a?await f.entities.MerchCategory.update(a.id,h):await f.entities.MerchCategory.create(h),i.invalidateQueries({queryKey:["merch-categories-admin"]}),i.invalidateQueries({queryKey:["merch-categories"]}),n({name:"",slug:"",description:"",sort_order:0,visible:!0}),x(null),k.success("Category saved")},p=async l=>{confirm("Delete this category?")&&(await f.entities.MerchCategory.delete(l),i.invalidateQueries({queryKey:["merch-categories-admin"]}))},j=l=>{x(l),n(l)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 p-4 bg-secondary/30 rounded-xl",children:[e.jsx(u,{placeholder:"Category name",value:h.name,onChange:l=>n(v=>({...v,name:l.target.value}))}),e.jsx(u,{placeholder:"slug (e.g. apparel)",value:h.slug,onChange:l=>n(v=>({...v,slug:l.target.value.toLowerCase().replace(/\s+/g,"-")}))}),e.jsx(u,{placeholder:"Description",value:h.description,onChange:l=>n(v=>({...v,description:l.target.value}))}),e.jsx(u,{type:"number",placeholder:"Sort order",value:h.sort_order,onChange:l=>n(v=>({...v,sort_order:Number(l.target.value)}))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:h.visible,onChange:l=>n(v=>({...v,visible:l.target.checked})),id:"cat-visible"}),e.jsx("label",{htmlFor:"cat-visible",className:"text-sm",children:"Visible in store"})]}),e.jsx(_,{onClick:c,children:a?"Update":"Add Category"})]}),e.jsx("div",{className:"space-y-2",children:y.map(l=>e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-secondary/30 rounded-lg",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-sm",children:l.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["/",l.slug," · Order: ",l.sort_order]})]}),e.jsx(P,{variant:l.visible?"default":"secondary",children:l.visible?"Visible":"Hidden"}),e.jsx("button",{onClick:()=>j(l),className:"text-muted-foreground hover:text-foreground",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>p(l.id),className:"text-destructive hover:text-destructive/80",children:e.jsx(G,{className:"w-4 h-4"})})]},l.id))})]})}function Ce({order:i,onUpdate:y,onClose:h}){const[n,a]=b.useState(i.status),[x,c]=b.useState(i.tracking_number||""),[p,j]=b.useState(i.tracking_url||""),[l,v]=b.useState(i.admin_notes||""),[r,d]=b.useState(!1),M=async()=>{d(!0);const g=n==="shipped"&&!i.shipped_at;if(await y(i.id,{status:n,tracking_number:x,tracking_url:p,admin_notes:l,...g?{shipped_at:new Date().toISOString()}:{}}),g&&i.customer_email)try{await f.integrations.Core.SendEmail({to:i.customer_email,subject:"Your Goby Merch order has shipped! ð¦",body:`Great news! Your order has been shipped. 12 13Tracking Number: ${x||"N/A"} 14${p?`Track your package: ${p} 15 16`:""}Thank you for shopping with Goby TV!`}),k.success("Shipping notification email sent")}catch{k.error("Order updated, but email could not be sent (customer may not be a registered user)")}d(!1),h()},w=i.shipping_address||{},m=[w.line1,w.line2,w.city,w.state,w.postal_code,w.country].filter(Boolean).join(", ");return e.jsxs("div",{className:"space-y-4 max-h-[75vh] overflow-y-auto pr-1",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-3 bg-secondary/50 rounded-lg",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Customer"}),e.jsx("p",{className:"font-medium text-sm",children:i.customer_name||"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i.customer_email})]}),e.jsxs("div",{className:"p-3 bg-secondary/50 rounded-lg",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Order Total"}),e.jsx("p",{className:"font-bold text-primary",children:T(i.total_cents)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Shipping: ",T(i.shipping_cents)]})]}),m&&e.jsxs("div",{className:"col-span-2 p-3 bg-secondary/50 rounded-lg",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Ship To"}),e.jsx("p",{className:"text-sm",children:m})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2",children:"Items"}),e.jsx("div",{className:"space-y-2",children:(i.line_items||[]).map((g,O)=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-secondary/30 rounded-lg text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:g.product_name}),g.variant_label&&e.jsx("p",{className:"text-xs text-muted-foreground",children:g.variant_label})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"font-medium",children:["x",g.quantity]}),e.jsx("p",{className:"text-primary",children:T(g.total_cents)})]})]},O))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Order Status"}),e.jsxs(U,{value:n,onValueChange:a,children:[e.jsx(F,{children:e.jsx(I,{})}),e.jsx($,{children:oe.map(g=>e.jsx(C,{value:g,className:"capitalize",children:g},g))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Tracking Number"}),e.jsx(u,{value:x,onChange:g=>c(g.target.value),placeholder:"1Z999AA10123456784"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Tracking URL"}),e.jsx(u,{value:p,onChange:g=>j(g.target.value),placeholder:"https://tracking.ups.com/..."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Admin Notes"}
16),e.jsx(ie,{value:l,onChange:g=>v(g.target.value),rows:2,placeholder:"Internal notes..."})]})]}),e.jsxs(le,{children:[e.jsx(_,{variant:"outline",onClick:h,children:"Cancel"}),e.jsx(_,{onClick:M,disabled:r,children:r?"Saving...":"Update Order"})]})]})}function ke({products:i}){const y=B(),{data:h=[]}=q({queryKey:["merch-discount-codes"],queryFn:()=>f.entities.MerchDiscountCode.list("-created_date",200)}),[n,a]=b.useState({code:"",label:"",discount_type:"percent",discount_value:10,applies_to:"all",product_ids:[],min_order_cents:0,max_uses:0,active:!0,expires_at:""}),[x,c]=b.useState(!1),p=()=>{const r=n.label?n.label.toUpperCase().replace(/\s+/g,"")+"-":"GOBY-",d=Math.random().toString(36).substring(2,7).toUpperCase();a(M=>({...M,code:r+d}))},j=async()=>{if(!n.code){k.error("Code is required");return}c(!0),await f.entities.MerchDiscountCode.create({...n,discount_value:Number(n.discount_value),min_order_cents:Number(n.min_order_cents||0)*100,max_uses:Number(n.max_uses||0),uses:0}),y.invalidateQueries({queryKey:["merch-discount-codes"]}),k.success("Discount code created!"),a({code:"",label:"",discount_type:"percent",discount_value:10,applies_to:"all",product_ids:[],min_order_cents:0,max_uses:0,active:!0,expires_at:""}),c(!1)},l=async r=>{await f.entities.MerchDiscountCode.update(r.id,{active:!r.active}),y.invalidateQueries({queryKey:["merch-discount-codes"]})},v=async r=>{confirm("Delete this code?")&&(await f.entities.MerchDiscountCode.delete(r),y.invalidateQueries({queryKey:["merch-discount-codes"]}))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-5 bg-secondary/30 rounded-xl space-y-4",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(ee,{className:"w-4 h-4 text-primary"})," Generate New Code"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"col-span-2 md:col-span-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Label (used in code name)"}),e.jsx(u,{placeholder:"e.g. DEEPDIVER, SUMMER25",value:n.label,onChange:r=>a(d=>({...d,label:r.target.value.toUpperCase()}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Code *"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(u,{placeholder:"CODE",value:n.code,onChange:r=>a(d=>({...d,code:r.target.value.toUpperCase()})),className:"font-mono"}),e.jsx(_,{size:"sm",variant:"outline",onClick:p,title:"Auto-generate",children:e.jsx(pe,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Type"}),e.jsxs(U,{value:n.discount_type,onValueChange:r=>a(d=>({...d,discount_type:r})),children:[e.jsx(F,{children:e.jsx(I,{})}),e.jsxs($,{children:[e.jsx(C,{value:"percent",children:"% Off"}),e.jsx(C,{value:"fixed",children:"$ Off"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Discount Value"}),e.jsx(u,{type:"number",value:n.discount_value,onChange:r=>a(d=>({...d,discount_value:r.target.value})),placeholder:n.discount_type==="percent"?"10":"5.00"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Min Order ($)"}),e.jsx(u,{type:"number",value:n.min_order_cents||"",onChange:r=>a(d=>({...d,min_order_cents:r.target.value})),placeholder:"0 = no minimum"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Max Uses (0 = unlimited)"}),e.jsx(u,{type:"number",value:n.max_uses||"",onChange:r=>a(d=>({...d,max_uses:r.target.value})),placeholder:"0"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Expires (optional)"}),e.jsx(u,{type:"date",value:n.expires_at,onChange:r=>a(d=>({...d,expires_at:r.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Applies To"}),e.jsxs(U,{value:n.applies_to,onValueChange:r=>a(d=>({...d,applies_to:r})),children:[e.jsx(F,{children:e.jsx(I,{})}),e.jsxs($,{children:[e.jsx(C,{value:"all",children:"All Products"}),e.jsx(C,{value:"selected",children:"Selected Products"})]})]})]})]}),e.jsxs(_,{onClick:j,disabled:x,className:"gap-2",children:[e.jsx(R,{className:"w-4 h-4"})," ",x?"Creating...":"Create Code"]}
16)]}),e.jsxs("div",{className:"space-y-2",children:[h.length===0&&e.jsxs("div",{className:"text-center py-10 text-muted-foreground",children:[e.jsx(ee,{className:"w-8 h-8 mx-auto mb-3 opacity-20"}),e.jsx("p",{children:"No discount codes yet. Generate one above."})]}),h.map(r=>e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-secondary/30 rounded-xl border border-border",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono font-bold text-primary",children:r.code}),r.label&&e.jsx(P,{variant:"outline",className:"text-xs",children:r.label}),e.jsx(P,{className:r.active?"bg-green-500/20 text-green-400":"bg-secondary text-muted-foreground",children:r.active?"Active":"Inactive"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[r.discount_type==="percent"?`${r.discount_value}% off`:`$${(r.discount_value||0).toFixed(2)} off`,r.min_order_cents>0&&` · Min $${(r.min_order_cents/100).toFixed(0)}`,r.max_uses>0&&` · ${r.uses||0}/${r.max_uses} uses`,r.max_uses===0&&` · ${r.uses||0} uses`,r.expires_at&&` · Expires ${new Date(r.expires_at).toLocaleDateString()}`]})]}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(r.code),k.success("Copied!")},className:"text-muted-foreground hover:text-foreground",title:"Copy code",children:e.jsx(ne,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>l(r),className:"text-muted-foreground hover:text-foreground",title:"Toggle active",children:e.jsx(ge,{className:`w-4 h-4 ${r.active?"text-green-400":""}`})}),e.jsx("button",{onClick:()=>v(r.id),className:"text-destructive hover:text-destructive/80",children:e.jsx(G,{className:"w-4 h-4"})})]},r.id))]})]})}function we({products:i}){const{data:y=[]}=q({queryKey:["merch-waitlist-admin"],queryFn:()=>f.entities.MerchWaitlist.list("-created_date",1e3)}),h=()=>{const a=["Email,Product,Signed Up"];y.forEach(j=>{const l=(j.product_name||"").replace(/"/g,'""'),v=new Date(j.created_date).toLocaleString();a.push(`${j.email},"${l}",${v}`)});const x=new Blob([a.join(` 17`)],{type:"text/csv"}),c=URL.createObjectURL(x),p=document.createElement("a");p.href=c,p.download="merch-waitlist.csv",p.click(),URL.revokeObjectURL(c)},n=y.reduce((a,x)=>{const c=x.product_id;return a[c]||(a[c]={product_name:x.product_name,emails:[]}),a[c].emails.push(x),a},{});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"w-5 h-5 text-primary"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[y.length," total signups across ",Object.keys(n).length," product(s)"]})]}),y.length>0&&e.jsxs(_,{size:"sm",variant:"outline",onClick:h,className:"gap-2",children:[e.jsx(ne,{className:"w-4 h-4"})," Export CSV"]})]}),y.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(X,{className:"w-10 h-10 mx-auto mb-3 opacity-20"}),e.jsx("p",{children:"No waitlist signups yet."}),e.jsx("p",{className:"text-xs mt-1",children:'Mark a product as "Coming Soon" to start collecting emails.'})]}):e.jsx("div",{className:"space-y-3",children:Object.entries(n).map(([a,x])=>{var p;const c=i.find(j=>j.id===a);return e.jsx(ae,{className:"bg-secondary/30",children:e.jsxs(re,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[(p=c==null?void 0:c.images)!=null&&p[0]?e.jsx("img",{src:c.images[0],alt:"",className:"w-10 h-10 object-cover rounded-lg"}):e.jsx("div",{className:"w-10 h-10 bg-secondary rounded-lg flex items-center justify-center",children:e.jsx(ue,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm",children:x.product_name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[x.emails.length," signup(s)"]})]}),e.jsx(P,{className:"bg-accent/20 text-accent",children:x.emails.length})]}),e.jsx("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:x.emails.map(j=>e.jsxs("div",{className:"flex items-center justify-between text-xs px-3 py-1.5 bg-background/40 rounded",children:[e.jsx("span",{className:"text-foreground",children:j.email}),e.jsx("span",{className:"text-muted-foreground",children:new Date(j.created_date).toLocaleDateString()})]},j.id))})]})},a)})})]})}function $e(){const i=B(),[y,h]=b.useState(!1),[n,a]=b.useState(null),[x,c]=b.useState(null),[p,j]=b.useState("all"),[l,v]=b.useState(""),{data:r=[]}=q({queryKey:["merch-products-admin"],queryFn:()=>f.entities.MerchProduct.list("sort_order",500)}),{data:d=[]}=q({queryKey:["merch-orders-admin"],queryFn:()=>f.entities.MerchOrder.list("-created_date",500)}),{data:M=[]}=q({queryKey:["merch-categories"],queryFn:()=>f.entities.MerchCategory.list("sort_order",100)}),w=async t=>{n?(await f.entities.MerchProduct.update(n.id,t),k.success("Product updated")):(await f.entities.MerchProduct.create(t),k.success("Product created")),i.invalidateQueries({queryKey:["merch-products-admin"]}),i.invalidateQueries({queryKey:["merch-products"]})},m=async t=>{confirm("Delete this product?")&&(await f.entities.MerchProduct.delete(t),i.invalidateQueries({queryKey:["merch-products-admin"]}),k.success("Product deleted"))}
17,g=async(t,S)=>{await f.entities.MerchOrder.update(t,S),i.invalidateQueries({queryKey:["merch-orders-admin"]}),k.success("Order updated")},O=d.filter(t=>t.payment_status==="paid").reduce((t,S)=>t+(S.total_cents||0),0),Q=d.filter(t=>["pending","paid","fulfilled"].includes(t.status)).length,A=d.filter(t=>t.payment_status==="paid").length,L=d.filter(t=>{var N,D,K;const S=p==="all"||t.status===p,s=l.toLowerCase(),o=!l||((N=t.customer_email)==null?void 0:N.toLowerCase().includes(s))||((D=t.customer_name)==null?void 0:D.toLowerCase().includes(s))||((K=t.stripe_session_id)==null?void 0:K.includes(s));return S&&o});return e.jsxs("div",{className:"pb-12 max-w-[1440px] mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{className:"w-6 h-6 text-primary"}),e.jsx("h1",{className:"text-2xl font-display font-bold",children:"Merch Store"})]}),e.jsxs(_,{onClick:()=>{a(null),h(!0)},className:"gap-2",children:[e.jsx(R,{className:"w-4 h-4"})," Add Product"]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[{label:"Total Revenue",value:T(O),icon:he,color:"text-green-400"},{label:"Total Orders",value:A,icon:se,color:"text-primary"},{label:"Pending Fulfillment",value:Q,icon:be,color:"text-yellow-400"},{label:"Products Listed",value:r.filter(t=>t.status==="published").length,icon:z,color:"text-accent"}].map(({label:t,value:S,icon:s,color:o})=>e.jsx(ae,{className:"bg-secondary/40",children:e.jsxs(re,{className:"p-4",children:[e.jsx(s,{className:`w-5 h-5 mb-1.5 ${o}`}),e.jsx("p",{className:"text-2xl font-bold",children:S}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})},t))}),e.jsxs(xe,{defaultValue:"products",children:[e.jsxs(me,{className:"mb-4",children:[e.jsxs(E,{value:"products",children:["Products (",r.length,")"]}),e.jsxs(E,{value:"orders",children:["Orders (",d.length,")"]}),e.jsx(E,{value:"categories",children:"Categories"}),e.jsx(E,{value:"discount-codes",children:"Discount Codes"}),e.jsx(E,{value:"waitlist",children:"Waitlist"})]}),e.jsx(V,{value:"products",children:e.jsxs("div",{className:"space-y-2",children:[r.map(t=>{var s,o,N;const S=((s=t.variants)==null?void 0:s.length)>0?t.variants.reduce((D,K)=>D+(K.inventory||0),0):t.inventory||0;return e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-secondary/30 rounded-xl border border-border hover:border-primary/30 transition-colors",children:[(o=t.images)!=null&&o[0]?e.jsx("img",{src:t.images[0],alt:t.name,className:"w-14 h-14 object-cover rounded-lg shrink-0"}):e.jsx("div",{className:"w-14 h-14 bg-secondary rounded-lg flex items-center justify-center shrink-0",children:e.jsx(ce,{className:"w-6 h-6 text-muted-foreground opacity-40"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"font-semibold",children:t.name}),e.jsx(P,{className:t.status==="published"?"bg-green-500/20 text-green-400":t.status==="draft"?"bg-yellow-500/20 text-yellow-400":t.status==="coming_soon"?"bg-accent/20 text-accent":"bg-secondary text-muted-foreground",children:t.status==="coming_soon"?"coming soon":t.status}),t.featured&&e.jsx(P,{className:"bg-primary/20 text-primary",children:"Featured"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5 flex-wrap",children:[e.jsx("p",{className:"text-primary font-bold",children:T(t.price_cents)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Stock: ",S," units"]}),t.category&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.category})]}),((N=t.variants)==null?void 0:N.length)>0&&e.jsx("div",{className:"flex gap-1.5 mt-1 flex-wrap",children:t.variants.map(D=>e.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded border ${(D.inventory||0)>0?"border-border text-muted-foreground":"border-destructive/50 text-destructive"}`,children:[D.label,": ",D.inventory||0]},D.label))})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(_,{size:"sm",variant:"outline",onClick:()=>{a(t),h(!0)},children:e.jsx(de,{className:"w-3.5 h-3.5"})}),e.jsx(_,{size:"sm",variant:"outline",className:"text-destructive hover:text-destructive",onClick:()=>m(t.id),children:e.jsx(G,{className:"w-3.5 h-3.5"})})]})]},t.id)}),r.length===0&&e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(z,{className:"w-10 h-10 mx-auto mb-3 opacity-20"}),e.jsx("p",{children:'No products yet. Click "Add Product" to get started.'})]})]})}),e.jsxs(V,{value:"orders",children:[e.jsxs("div",{className:"flex gap-3 mb-4 flex-wrap",children:[e.jsx(u,{placeholder:"Search by email, name...",value:l,onCh
17ange:t=>v(t.target.value),className:"max-w-xs"}),e.jsxs(U,{value:p,onValueChange:j,children:[e.jsx(F,{className:"w-44",children:e.jsx(I,{})}),e.jsxs($,{children:[e.jsx(C,{value:"all",children:"All Orders"}),oe.map(t=>e.jsx(C,{value:t,className:"capitalize",children:t},t))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[L.map(t=>e.jsxs("div",{onClick:()=>c(t),className:"flex items-center gap-4 p-4 bg-secondary/30 rounded-xl border border-border hover:border-primary/30 transition-colors cursor-pointer",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"font-medium text-sm",children:t.customer_name||t.customer_email||"Unknown"}),e.jsx(P,{className:ye[t.status]||"bg-secondary text-muted-foreground",children:t.status}),t.payment_status==="paid"&&e.jsx(P,{className:"bg-green-500/20 text-green-400 text-xs",children:"Paid"}),t.is_preorder&&e.jsx(P,{className:"bg-primary/20 text-primary text-xs",children:"Pre-order"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5 text-xs text-muted-foreground flex-wrap",children:[e.jsx("span",{children:t.customer_email}),e.jsx("span",{children:fe(t.created_date)}),e.jsxs("span",{children:[(t.line_items||[]).length," item(s)"]}),t.tracking_number&&e.jsxs("span",{className:"text-accent",children:["Tracking: ",t.tracking_number]})]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("p",{className:"font-bold text-primary",children:T(t.total_cents)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["+ ",T(t.shipping_cents)," ship"]})]})]},t.id)),L.length===0&&e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(se,{className:"w-10 h-10 mx-auto mb-3 opacity-20"}),e.jsx("p",{children:"No orders found."})]})]})]}),e.jsx(V,{value:"categories",children:e.jsx(_e,{})}),e.jsx(V,{value:"discount-codes",children:e.jsx(ke,{products:r})}),e.jsx(V,{value:"waitlist",children:e.jsx(we,{products:r})})]}),e.jsx(H,{open:y,onOpenChange:h,children:e.jsxs(W,{className:"max-w-2xl bg-card text-foreground",children:[e.jsx(Y,{children:e.jsx(J,{children:n?"Edit Product":"Add Product"})}),e.jsx(Ne,{product:n,categories:M,onSave:w,onClose:()=>h(!1)})]})}),e.jsx(H,{open:!!x,onOpenChange:()=>c(null),children:e.jsxs(W,{className:"max-w-lg bg-card text-foreground",children:[e.jsx(Y,{children:e.jsx(J,{children:"Order Details"})}),x&&e.jsx(Ce,{order:x,onUpdate:g,onClose:()=>c(null)})]})})]})}export{$e as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.