1import{b6 as Ve,l as e,a9 as Ge,C as Ue,j as r,aK as J,ac as Me,au as h,aD as c,aJ as p,aF as Qe,ad as ze,ak as _e,al as He,aw as Ke,ax as Je,at as be,az as Ye}from"./index-CBr6eDOK.js";import{aG as F,aI as We,ap as Xe,aJ as Ze,A as es,C as A,K as D,M as $,$ as ye,b as q,ah as Y,w as W,x as X,y as Z,z as ee,G as g,cg as ss,P as ts,bR as as,B as ns,H as is,S as ds}from"../app-0AIdVgIG.js";import{S as Ne}from"./switch-DuIc8pGK.js";import{S as se}from"./separator-DqmZZywH.js";import{T as rs,a as ls,b as R}from"./tabs-BLSPyjO0.js";import{a as cs,b as os,c as us,d as ps,e as ms,f as xs}from"./useBundles-BpIQSUQq.js";import{u as hs}from"./useProducts-BGkweAge.js";import{n as C,a as S}from"./numberField-DYtLMvJ6.js";import{G as js}from"./grip-vertical-BcndIAdD.js";import{S as gs}from"./save-yObVKdT3.js";import"./customFieldErrors-hms2yvvN.js";function o(m){return`$${(m/100).toFixed(2)}`}const L={product:"Product",products:"Products","event-ticket":"Event","event-tickets":"Events","sponsorship-package":"Sponsorship","sponsorship-packages":"Sponsorships","membership-tier":"Membership","membership-tiers":"Memberships"},we={product:"bg-blue-100 text-blue-800","event-ticket":"bg-purple-100 text-purple-800","sponsorship-package":"bg-amber-100 text-amber-800","membership-tier":"bg-green-100 text-green-800"};function vs({bundleId:m}){const[,O]=Ge(),{toast:x}=Ue(),l=!!m,{data:d,isLoading:Ce}=cs(m||""),{components:te,addComponent:Se,removeComponent:Ie}=os(m||""),Te=us(),Ee=ps(),{products:Pe}=hs({status:"active",limit:200}),V=Pe.filter(s=>s.productType!=="bundle"),[T,ae]=r.useState(""),[ne,ie]=r.useState(""),[de,re]=r.useState(),[Be,ke]=r.useState(""),[E,le]=r.useState("fixed"),[v,ce]=r.useState("percentage"),[y,oe]=r.useState(),[u,G]=r.useState("bundle"),[U,ue]=r.useState(null),[M,pe]=r.useState(null),[Q,me]=r.useState(""),[z,xe]=r.useState(""),[i,f]=r.useState([]),[Ae,P]=r.useState(!1),[I,_]=r.useState(""),[he,je]=r.useState(!1),[N,De]=r.useState("products"),{data:H,isLoading:$e}=ms(N);r.useEffect(()=>{d&&l&&(ke(d.productId),ae(d.product?.name||""),ie(d.product?.description||""),re(d.product?.basePrice??0),le(d.bundleType),ce(d.discountType),oe(d.discountValue??0),G(d.discountSource||"bundle"),ue(d.minItems),pe(d.maxItems),me(d.availableFrom?d.availableFrom.split("T")[0]:""),xe(d.availableUntil?d.availableUntil.split("T")[0]:""),d.items&&f(d.items.map(s=>({id:s.id,productId:s.productId,variantId:s.variantId||null,defaultQuantity:s.defaultQuantity,isRequired:s.isRequired,isSwappable:s.isSwappable,swapGroupId:s.swapGroupId||null,sortOrder:s.sortOrder,product:s.product}))))},[d,l]);const{data:j}=xs(l&&m?m:""),w=i.reduce((s,t)=>{const a=V.find(n=>n.id===t.productId)||t.product;return s+(a?.basePrice??0)*t.defaultQuantity},0),B=v==="percentage"?Math.round(w*(y??0)/100):v==="fixed"?y??0:i.reduce((s,t)=>s+(y??0)*t.defaultQuantity,0),qe=Math.max(0,w-B),Re=s=>{if(i.some(t=>t.productId===s.id)){x({title:"Already added",description:"This product is already in the bundle.",variant:"destructive"});return}f(t=>[...t,{productId:s.id,variantId:null,defaultQuantity:1,isRequired:!0,isSwappable:!1,swapGroupId:null,sortOrder:t.length,product:{name:s.name,basePrice:s.basePrice,productType:s.productType}}]),P(!1),_("")},Le=s=>{const t=`${s.sourceEntityType}:${s.sourceEntityId}`;if(i.some(n=>(n.sourceEntityType&&n.sourceEntityId?`${n.sourceEntityType}:${n.sourceEntityId}`:`product:${n.productId}`)===t)){x({title:"Already added",description:"This item is already in the bundle.",variant:"destructive"});return}const a=s.parentName?`${s.parentName} â ${s.name}`:s.name;f(n=>[...n,{productId:s.productId||"",variantId:null,sourceEntityType:s.sourceEntityType,sourceEntityId:s.sourceEntityId,unitPriceCents:s.priceCents,defaultQuantity:1,isRequired:!0,isSwappable:!1,swapGroupId:null,sortOrder:n.length,product:{name:a,basePrice:s.priceCents,productType:s.sourceEntityType}}])},Fe=s=>{f(t=>t.filter((a,n)=>n!==s))},ge=(s,t)=>{const a=[...i],n=t==="up"?s-1:s+1;n<0||n>=a.length||([a[s],a[n]]=[a[n],a[s]],a.forEach((b,K)=>{b.sortOrder=K}),f(a))},k=(s,t)=>{f(a=>a.map((n,b)=>b===s?{...n,...t}:n))},ve=(s,t,a)=>{f(n=>n.map((b,K)=>K===s?{...b,[t]:a}:b))},Oe=async()=>
1{if(!l&&!T.trim()){x({title:"Error",description:"Please enter a bundle name.",variant:"destructive"});return}if(i.length===0){x({title:"Error",description:"Add at least one component product.",variant:"destructive"});return}if(!i.some(s=>s.isRequired)){x({title:"Error",description:"At least one component must be required.",variant:"destructive"});return}je(!0);try{if(l&&m){await Ee.mutateAsync({id:m,bundleType:E,discountType:v,discountValue:y??0,discountSource:u,minItems:U,maxItems:M,availableFrom:Q||null,availableUntil:z||null});const s=new Set(te.map(a=>a.id)),t=new Set(i.filter(a=>a.id).map(a=>a.id));for(const a of te)t.has(a.id)||await Ie.mutateAsync(a.id);for(const a of i)(!a.id||!s.has(a.id))&&await Se.mutateAsync({productId:a.productId,variantId:a.variantId,sourceEntityType:a.sourceEntityType,sourceEntityId:a.sourceEntityId,unitPriceCents:a.unitPriceCents,defaultQuantity:a.defaultQuantity,isRequired:a.isRequired,isSwappable:a.isSwappable,swapGroupId:a.swapGroupId,sortOrder:a.sortOrder});x({title:"Bundle updated",description:"Bundle configuration saved successfully."})}else await Te.mutateAsync({name:T.trim(),description:ne.trim()||null,basePrice:de??0,bundleType:E,discountType:v,discountValue:y??0,discountSource:u,minItems:U,maxItems:M,availableFrom:Q||null,availableUntil:z||null,items:i.map((s,t)=>({productId:s.productId,variantId:s.variantId,sourceEntityType:s.sourceEntityType,sourceEntityId:s.sourceEntityId,unitPriceCents:s.unitPriceCents,defaultQuantity:s.defaultQuantity,isRequired:s.isRequired,isSwappable:s.isSwappable,swapGroupId:s.swapGroupId,sortOrder:t,itemDiscountType:u==="product"?s.itemDiscountType||"percentage":null,itemDiscountValue:u==="product"?s.itemDiscountValue||0:null}))}),x({title:"Bundle created",description:"New bundle has been created."}),O("/estore/bundles")}catch(s){x({title:"Error",description:s.message||"Failed to save bundle.",variant:"destructive"})}finally{je(!1)}},fe=V.filter(s=>s.name.toLowerCase().includes(I.toLowerCase())||s.sku&&s.sku.toLowerCase().includes(I.toLowerCase()));return l&&Ce?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Me,{href:"/estore/bundles",children:e.jsx(h,{variant:"ghost",size:"icon","data-testid":"btn-back-bundles",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:l?"Edit Bundle":"Create Bundle"}),e.jsx("p",{className:"text-muted-foreground",children:l?"Modify bundle configuration and components":"Build a product bundle with discounted pricing"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(A,{children:[e.jsxs(D,{children:[e.jsx($,{children:"Bundle Configuration"}),e.jsx(ye,{children:"Set the base product and discount rules"})]}),e.jsxs(q,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Bundle Name *"}),e.jsx(p,{value:T,onChange:s=>ae(s.target.value),placeholder:"Enter bundle name...",maxLength:200,disabled:l,"data-testid":"input-bundle-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Description"}),e.jsx(p,{value:ne,onChange:s=>ie(s.target.value),placeholder:"Optional description...",maxLength:2e3,disabled:l,"data-testid":"input-bundle-description"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Base Price (cents)"}),e.jsxs("div",{className:"relative",children:[e.jsx(Y,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(p,{type:"number",className:"pl-9",value:S(de),onChange:C(s=>re(s??void 0)),min:0,disabled:l,"data-testid":"input-bundle-base-price"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Override price for the bundle (in cents). Set to 0 to calculate from components."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Discount Direction"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{type:"button",variant:u==="bundle"?"default":"outline",size:"sm",onClick:()=>G("bundle"),"data-testid":"btn-discount-source-bundle",children:"Bundle-Level Discount"}),e.jsx(h,{type:"button",variant:u==="product"?"default":"outline",size:"sm",onClick:()=>G("product"),"data-testid":"btn-discount-source-product",children:"Per-Product Discounts"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u==="bundle"?"A single discount is applied to the bundle and distributed proportionally across products by price.":"Each product in the bundle has its own discount type and value."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Bundle Type"}),e.jsxs(W,{value:E,onValueChange:s=>le(s),children:[e.jsx(X,{"data-testid":"select-bundle-type",children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(g,{value:"fixed",children:"Fixed (all items included)"}),e.jsx(g,{value:"configurable",children:"Configurable (choose items)"}),e.jsx(g,{value:"tiered",children:"Tiered (volume pricing)"})]})]})]}),u==="bundle"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Discount Type"}),e.jsxs(W,{value:v,onValueChange:s=>ce(s),children:[e.jsx(X,{"data-testid":"select-discount-type",children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(g,{value:"percentage",children:"Percentage Off"}),e.jsx(g,{value:"fixed",children:"Fixed Amount Off"}),e.jsx(g,{value:"per_item",children:"Per-Item Discount"})]})]})]})]}),u==="bundle"&&e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs(c,{children:["Discount Value ",v==="percentage"?"(%)":"(cents)"]}),e.jsxs("div",{className:"relative",children:[v==="percentage"?e.jsx(ss,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}):e.jsx(Y,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(p,{type:"number",className:"pl-9",value:S(y),onChange:C(s=>oe(s??void 0)),min:0,"data-testid":"input-discount-value"})]})]})}),E==="configurable"&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Min Items"}),e.jsx(p,{type:"number",value:S(U),onChange:C(s=>ue(s??null),{integer:!0}),min:0,placeholder:"No minimum","data-testid":"input-min-items"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Max Items"}),e.jsx(p,{type:"number",value:S(M),onChange:C(s=>pe(s??null),{integer:!0}),min:1,placeholder:"No maximum","data-testid":"input-max-items"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Available From"}),e.jsx(p,{type:"date",value:Q,onChange:s=>me(s.target.value),"data-testid":"input-available-from"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Available Until"}),e.jsx(p,{type:"date",value:z,onChange:s=>xe(s.target.value),"data-testid":"input-available-until"})]})]})]})]}),e.jsxs(A,{children:[e.jsx(D,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs($,{children:["Bundle Components ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(ye,{children:["Add products to include in this bundle. At least one component is required and at least one of them must be marked Required.",u==="product"&&e.jsx(e.Fragment,{children:" Each component must also have a discount type when using per-product discounts."})]}),i.length===0&&e.jsx("p",{className:"text-sm text-red-500 mt-1","data-testid":"text-bundle-components-required",children:"Add at least one component product."}),i.length>0&&!i.some(s=>s.isRequired)&&e.jsx("p",{className:"text-sm text-red-500 mt-1","data-testid":"text-bundle-required-component-missing",children:"At least one component must be marked Required."}),u==="product"&&i.some(s=>!s.itemDiscountType)&&e.jsx("p",{className:"text-sm text-red-500 mt-1","data-testid":"text-bundle-item-discount-missing",children:"Each component must have a discount type when using per-product discounts."})]}),e.jsx(F,{permission:"products:create",children:e.jsxs(h,{onClick:()=>P(!0),size:"sm","data-testid":"btn-add-component",children:[e.jsx(ts,{className:"h-4 w-4 mr-1"})," Add item"]})})]})}),e.jsx(q,{children:i.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground","data-testid":"text-no-components",children:[e.jsx(as,{className:"h-12 w-12 mx-auto mb-3 opacity-40"}),e.jsx("p",{children:'No components added yet. Click "Add item" to get started.'})]}):e.jsx("div",{className:"space-y-3",children:i.map((s,t)=>{const a=V.find(n=>n.id===s.productId)||s.product;return e.jsxs("div",{className:"flex items-center gap-3 p-3 border rounded-lg bg-card","data-testid":`component-item-${t}`,children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(h,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>ge(t,"up"),disabled:t===0,"data-testid":`btn-move-up-${t}`,children:e.jsx(Qe,{className:"h-3 w-3"})}),e.jsx(js,{className:"h-4 w-4 text-muted-foreground mx-auto"}),e.jsx(h,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>ge(t,"down"),disabled:t===i.length-1,"data-testid":`btn-move-down-${t}`,children:e.jsx(ze,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate","data-testid":`text-component-name-${t}`,children:a?.name||s.product?.name||"Unknown Product"}),s.sourceEntityType&&s.sourceEntityType!=="product"&&e.jsx("span",{className:`inline-flex px-1.5 py-0.5 rounded text-[10px] font-medium ${we[s.sourceEntityType]||""}`,"data-testid":`badge-source-type-${t}`,children:L[s.sourceEntityType]||s.sourceEntityType}),e.jsx(ns,{variant:"outline",className:"text-xs",children:o(s.unitPriceCents??a?.basePrice??0)})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c,{className:"text-xs",children:"Qty:"}),e.jsx(p,{type:"number",className:"w-16 h-7 text-xs",min:1,value:S(s.defaultQuantity),onChange:C(n=>k(t,{defaultQuantity:n??1}),{integer:!0}),"data-testid":`input-qty-${t}`})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{checked:s.isRequired,onCheckedChange:n=>k(t,{isRequired:n}),"data-testid":`switch-required-${t}`}),e.jsx(c,{className:"text-xs",children:"Required"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ne,{checked:s.isSwappable,onCheckedChange:n=>k(t,{isSwappable:n}),"data-testid":`switch-swappable-${t}`}),e.jsx(c,{className:"text-xs",children:"Swappable"})]}),s.isSwappable&&e.jsx(p,{className:"w-24 h-7 text-xs",placeholder:"Swap group",value:s.swapGroupId||"",onChange:n=>k(t,{swapGroupId:n.target.value||null}),"data-testid":`input-swap-group-${t}`}),u==="product"&&e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs(W,{value:s.itemDiscountType||"percentage",onValueChange:n=>ve(t,"itemDiscountType",n),children:[e.jsx(X,{className:"w-[100px] h-7 text-xs",children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(g,{value:"percentage",children:"%"}),e.jsx(g,{value:"fixed",children:"Fixed ($)"})]})]}),e.jsx(p,{type:"number",min:0,value:S(s.itemDiscountValue),onChange:C(n=>ve(t,"itemDiscountValue",n)),className:"w-[80px] h-7 text-xs",placeholder:"0","data-testid":`input-item-discount-${t}`})]})]})]}),e.jsx(F,{permission:"products:update",children:e.jsx(h,{variant:"ghost",size:"icon",className:"text-destructive hover:text-destructive",onClick:()=>Fe(t),"data-testid":`btn-remove-component-${t}`,children:e.jsx(is,{className:"h-4 w-4"})})})]},`${s.productId}-${t}`)})})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(A,{children:[e.jsx(D,{children:e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-4 w-4"}),"Pricing Preview"]})}),e.jsx(q,{className:"space-y-3",children:l&&j?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Component Total:"}),e.jsx("span",{className:"line-through","data-testid":"text-server-component-total",children:o(j.componentTotal)})]}),e.jsxs("div",{className:"flex justify-between text-sm text-green-600",children:[e.jsx("span",{children:"Discount:"}),e.jsxs("span",{"data-testid":"text-server-discount",children:["-",o(j.discountAmount)]})]}),e.jsx(se,{}),e.jsxs("div",{className:"flex justify-between font-bold text-lg",children:[e.jsx("span",{children:"Bundle Price:"}),e.jsx("span",{"data-testid":"text-server-bundle-price",children:o(j.bundlePrice)})]}),e.jsxs("div",{className:"flex justify-between text-sm text-green-600 font-medium",children:[e.jsx("span",{children:"You Save:"}),e.jsxs("span",{"data-testid":"text-server-savings",children:[o(j.savings)," (",j.savingsPercent.toFixed(0),"%)"]})]}),j.components.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(se,{}),e.jsx("div",{className:"text-xs text-muted-foreground space-y-1",children:j.components.map((s,t)=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:[s.name," Ã ",s.quantity]}),e.jsxs("div",{className:"text-right",children:[s.discountAmount>0&&e.jsx("span",{className:"text-xs text-muted-foreground line-through mr-2",children:o(s.lineTotal)}),e.jsx("span",{children:o(s.discountedLineTotal)})]})]},t))})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Component Total:"}),e.jsx("span",{className:"line-through","data-testid":"text-component-total",children:o(w)})]}),e.jsxs("div",{className:"flex justify-between text-sm text-green-600",children:[e.jsx("span",{children:"Est. Discount:"}),e.jsxs("span",{"data-testid":"text-est-discount",children:["-",o(B)]})]}),e.jsx(se,{}),e.jsxs("div",{className:"flex justify-between font-bold text-lg",children:[e.jsx("span",{children:"Est. Bundle Price:"}),e.jsx("span",{"data-testid":"text-est-bundle-price",children:o(qe)})]}),w>0&&e.jsxs("div",{className:"flex justify-between text-sm text-green-600 font-medium",children:[e.jsx("span",{children:"Est. Savings:"}),e.jsxs("span",{"data-testid":"text-est-savings",children:[o(B)," (",w>0?(B/w*100).toFixed(0):0,"%)"]})]})]})})]}),e.jsxs(A,{children:[e.jsx(D,{children:e.jsx($,{className:"text-sm",children:"Summary"})}),e.jsxs(q,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Components:"}),e.jsx("span",{"data-testid":"text-component-count",children:i.length})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Required:"}),e.jsx("span",{children:i.filter(s=>s.isRequired).length})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Optional:"}),e.jsx("span",{children:i.filter(s=>!s.isRequired).length})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Swappable:"}),e.jsx("span",{children:i.filter(s=>s.isSwappable).length})]})]})]}),e.jsx(F,{permission:"products:create",children:e.jsxs(h,{className:"w-full",size:"lg",onClick:Oe,disabled:he||i.length===0||(l?!Be:!T.trim()),"data-testid":"btn-save-bundle",children:[he?e.jsx(J,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(gs,{className:"h-4 w-4 mr-2"}
1),l?"Update Bundle":"Create Bundle"]})})]})]}),e.jsx(_e,{open:Ae,onOpenChange:P,children:e.jsxs(He,{className:"max-w-lg max-h-[80vh]",children:[e.jsx(Ke,{children:e.jsx(Je,{children:"Add Bundle Component"})}),e.jsx(rs,{value:N,onValueChange:De,className:"w-full",children:e.jsxs(ls,{className:"w-full grid grid-cols-4",children:[e.jsx(R,{value:"products","data-testid":"tab-source-products",children:"Products"}),e.jsx(R,{value:"event-tickets","data-testid":"tab-source-event-tickets",children:"Events"}),e.jsx(R,{value:"sponsorship-packages","data-testid":"tab-source-sponsor-packages",children:"Sponsors"}),e.jsx(R,{value:"membership-tiers","data-testid":"tab-source-memberships",children:"Members"})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(ds,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(p,{className:"pl-9",placeholder:`Search ${L[N]?.toLowerCase()||"items"}...`,value:I,onChange:s=>_(s.target.value),"data-testid":"input-search-component"})]}),N==="products"&&e.jsx("div",{className:"overflow-y-auto max-h-[50vh] space-y-1",children:fe.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-4",children:"No products found"}):fe.slice(0,50).map(s=>{const t=i.some(a=>a.productId===s.id);return e.jsx("button",{className:`w-full text-left p-3 rounded-lg border transition-colors ${t?"bg-muted cursor-not-allowed opacity-50":"hover:bg-accent cursor-pointer"}`,onClick:()=>!t&&Re(s),disabled:t,"data-testid":`btn-add-product-${s.id}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.productType," ",s.sku?`· ${s.sku}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:o(s.basePrice)}),t&&e.jsx(be,{className:"h-4 w-4 text-green-500"})]})]})},s.id)})}),N!=="products"&&e.jsx("div",{className:"overflow-y-auto max-h-[50vh] space-y-1",children:$e?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(J,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):!H||H.length===0?e.jsxs("p",{className:"text-center text-muted-foreground py-4",children:["No ",L[N]?.toLowerCase()||"items"," found"]}):H.filter(s=>!I||s.name?.toLowerCase().includes(I.toLowerCase())).slice(0,50).map(s=>{const t=i.some(a=>a.sourceEntityType===s.sourceEntityType&&a.sourceEntityId===s.sourceEntityId);return e.jsx("button",{className:`w-full text-left p-3 rounded-lg border transition-colors ${t?"bg-muted cursor-not-allowed opacity-50":"hover:bg-accent cursor-pointer"}`,onClick:()=>!t&&Le(s),disabled:t,"data-testid":`btn-add-item-${s.sourceEntityId}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.name}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx("span",{className:`inline-flex px-1.5 py-0.5 rounded text-[10px] font-medium ${we[s.sourceEntityType]||""}`,children:L[s.sourceEntityType]||s.sourceEntityType}),s.parentName&&e.jsx("span",{children:s.parentName})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:o(s.priceCents)}),t&&e.jsx(be,{className:"h-4 w-4 text-green-500"})]})]})},s.sourceEntityId)})}),e.jsx(Ye,{children:e.jsx(h,{variant:"outline",onClick:()=>{P(!1),_("")},children:"Close"})})]})})]})}function Bs(){const[m,O]=Ve("/estore/bundles/:id/edit"),x=m?O?.id:void 0;return e.jsx(F,{permission:"products:create",fallback:e.jsxs(We,{children:[e.jsx(Xe,{className:"h-4 w-4"}),e.jsx(Ze,{children:"You don't have permission to manage bundles."})]}),children:e.jsx(vs,{bundleId:x})})}export{Bs 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.