1import{r,j as e}from"./react-vendor-CU6Sz31W.js";import{e as ee,q as se,w as te,f as ae}from"./firebase-w6DYUbFN.js";import{u as re,as as le,gd as oe,ge as ie,gf as ce,gg as ne,ax as de,C as me,dd as H,i as p,S as O,dP as xe,cr as ue,I as he,ce as pe,eC as fe,eE as ge,eF as be,eG as je,eI as R,eH as Ne,gh as ye,g8 as ke,cd as Se}from"./index-DEXJEDAi.js";import{P as $}from"./pill-filter-CtZSNPVl.js";import{T}from"./text-highlight-BFqqfcjs.js";import{T as ve,a as q,b as we,c as Ce,d as f}from"./table-CxPdvV_9.js";import{S as y}from"./DataTableCard-BluwWKn_.js";import{u as Fe}from"./useTableSort-KpNOL2n3.js";import{M as ze,o as Me}from"./modal-form-CqN5DZuv.js";import{E as Pe}from"./ellipsis-vertical-C-dQ6Kzj.js";import{P as Te}from"./pencil-CpqYHolO.js";import"./payment-icons-Daq1K3F1.js";import"./index-BSuGcRaZ.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./date-picker-filter-Qp1kqu9t.js";import"./calendar-RV2oTCrW.js";import"./addWeeks-1hrFjz19.js";import"./clear-filters-button-DmPemFGr.js";import"./ExportCsvAction-BJr9eiP6.js";import"./modal-option-cards-Dksohkou.js";function Ze({open:n,onOpenChange:D,integration:a=null,productCategories:g=[],onCreateProduct:U,onEditProduct:V,onSyncCatalog:I,syncingCatalog:A=!1}){const{userDoc:G}=re(),[k,b]=r.useState(!0),[o,S]=r.useState([]),[c,v]=r.useState(""),[d,w]=r.useState([]),[m,C]=r.useState([]);r.useEffect(()=>{n||(v(""),w([]),C([]))},[n]),r.useEffect(()=>{if(!n||!(a!=null&&a.integrationId))return S([]),b(!1),()=>{};b(!0);const s=ee(le,"Products"),t=se(s,te("type","==","lab")),l=ae(t,h=>{const Y=h.docs.map(i=>({id:i.id,...i.data()})).filter(i=>!i.providerNetworkId&&i.catalogScope!=="provider_network").filter(i=>i.integrationId===a.integrationId).sort((i,Z)=>String(i.name||"").localeCompare(String(Z.name||"")));S(Y),b(!1)},()=>{S([]),b(!1)});return()=>l()},[a==null?void 0:a.integrationId,n]);const F=r.useMemo(()=>g.reduce((s,t)=>(t!=null&&t.id&&(s[t.id]=t.name||"Category"),s),{}),[g]),Q=r.useMemo(()=>a!=null&&a.name?`${a.name} products`:"Integration products",[a==null?void 0:a.name]),J=oe(G),W=["junction","tasso"].includes(a==null?void 0:a.adapterKey)&&typeof I=="function",L=r.useMemo(()=>o.map(s=>{const t=(s.categories||[]).map(h=>F[h]||"Category").join(" "),l=(s.status||"inactive").toLowerCase();return{...s,_statusNorm:l,sortCategories:t||"",_searchBlob:ie([s.id,s.productId,s.integrationProductId,s.name,s.code,s.description,t,l])}}),[o,F]),z=r.useMemo(()=>ce(c),[c]),M=r.useMemo(()=>{const s={};for(const t of o){const l=(t.status||"inactive").toLowerCase();s[l]=(s[l]||0)+1}return Object.keys(s).sort().map(t=>({id:t,label:t.charAt(0).toUpperCase()+t.slice(1),count:s[t]}))},[o]),K=r.useMemo(()=>{const s=new Set;for(const t of o)(t.categories||[]).forEach(l=>s.add(l));return g.filter(t=>(t==null?void 0:t.id)&&s.has(t.id)).map(t=>({id:t.id,label:t.name||t.id,count:o.filter(l=>(l.categories||[]).includes(t.id)).length}))},[o,g]),B=r.useMemo(()=>{let s=L;return z.length&&(s=s.filter(t=>ne(t._searchBlob,z))),d.length>0&&(s=s.filter(t=>d.includes(t._statusNorm))),m.length>0&&(s=s.filter(t=>{const l=t.categories||[];return m.some(h=>l.includes(h))})),s},[L,z,d,m]),{sortedData:E,sortKey:x,sortDirection:u,handleSort:j}=Fe(B,"name","asc"),N=s=>x===s?u==="asc"?"ascending":"descending":"none",_=!!(c.trim()||d.length>0||m.length>0),X=c.trim()?"No results found for your search.":_?"No results match your current filters.":"No products are linked to this integration yet.",P=c.trim()||"";return e.jsx(de,{mobileCompactHeaderRow:!0,open:n,onOpenChange:D,contentClassName:"max-w-4xl",title:Q,description:"Manage the products offered through this integration.",footerClassName:"bg-slate-100 dark:bg-slate-900",footer:e.jsxs(e.Fragment,{children:[e.jsx(p,{type:"button",variant:"outline",onClick:()=>D(!1),className:"w-full sm:w-auto",children:"Close"}),e.jsxs(p,{type:"submit",form:"integration-products-modal-form",className:"w-full sm:w-auto",children:[e.jsx(Se,{className:"mr-2 size-4"}),"Add product"]})]}),children:e.jsx("form",{id:"integration-products-modal-form",className:ze,onSubmit:Me(()=>U(a)),children:e.jsxs(me,{className:"overflow-hidden rounded-xl border border-subtle dark:bg-slate-800",children:[e.jsxs("div",{className:"border-b border-subtle bg-surface-sunken p-3 max-lg:p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 max-lg:gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("div",{className:"rounded-lg bg-blue-50 p-1.5 text-blue-600 dar
1k:bg-blue-950/50 dark:text-blue-400",children:e.jsx(H,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm font-semibold text-content-primary max-lg:text-xs",children:"Products"}),e.jsx("p",{className:"text-xs text-content-tertiary",children:k?e.jsx("span",{className:"inline-block h-3 w-16 animate-pulse rounded bg-slate-200 align-middle dark:bg-slate-700/60"}):`${B.length} of ${o.length}`})]})]}),W?e.jsxs(p,{type:"button",variant:"outline",size:"sm",onClick:()=>I(a),disabled:A,className:"h-8 shrink-0 gap-1.5 rounded-full text-xs dark:border-slate-600 dark:hover:bg-slate-700",children:[A?e.jsx(O,{size:"sm"}):e.jsx(xe,{className:"size-3.5"}),"Sync"]}):null]}),e.jsxs("div",{className:"relative mt-3 max-lg:mt-2",children:[e.jsx(ue,{className:"absolute left-2 top-1/2 size-3 -translate-y-1/2 text-slate-400"}),e.jsx(he,{placeholder:"Search by name, code, description, categoryâ¦",value:c,onChange:s=>v(s.target.value),disabled:k,className:"h-8 pl-7 text-xs dark:border-slate-600 dark:bg-slate-700","aria-label":"Search products"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 max-lg:mt-2",children:[M.length>0?e.jsx($,{filters:M,activeFilters:d,onFilterChange:w,defaultLabel:"All statuses",searchable:M.length>6}):null,K.length>0?e.jsx($,{filters:K,activeFilters:m,onFilterChange:C,defaultLabel:"All categories",searchable:!0}):null,_?e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:()=>{v(""),w([]),C([])},className:"h-7 px-2 text-2xs font-semibold text-content-tertiary hover:text-slate-900 dark:hover:text-slate-200",children:"Clear all"}):null]})]}),k?e.jsxs("div",{className:"flex items-center justify-center py-12 text-sm text-content-tertiary max-lg:text-xs",children:[e.jsx(O,{size:"md",className:"mr-2"}),"Loading products..."]}):o.length===0?e.jsx("div",{className:"py-12 text-center text-sm text-content-tertiary max-lg:text-xs",children:"No products are linked to this integration yet."}):E.length===0?e.jsx("div",{className:"py-12 text-center text-sm text-content-tertiary max-lg:text-xs",children:X}):e.jsx("div",{className:"max-h-[500px] overflow-x-auto overflow-y-auto",children:e.jsxs("table",{className:"w-full caption-bottom text-sm max-lg:text-xs",style:{tableLayout:"fixed"},"aria-label":"Integration products","data-testid":"table-integration-products",children:[e.jsx(ve,{children:e.jsxs(q,{className:"hover:bg-transparent dark:border-slate-700",children:[e.jsx(y,{sortKey:"_statusNorm",currentSortKey:x,currentSortDirection:u,onSort:j,"aria-sort":N("_statusNorm"),className:"sticky top-0 z-raised w-[10%] bg-surface-raised py-2 text-left text-xs dark:text-slate-300",children:"Status"}),e.jsx(y,{sortKey:"code",currentSortKey:x,currentSortDirection:u,onSort:j,"aria-sort":N("code"),className:"sticky top-0 z-raised w-[12%] bg-surface-raised py-2 text-left text-xs dark:text-slate-300",children:"Code"}),e.jsx(y,{sortKey:"name",currentSortKey:x,currentSortDirection:u,onSort:j,"aria-sort":N("name"),className:"sticky top-0 z-raised bg-surface-raised py-2 text-left text-xs dark:text-slate-300",children:"Name"}),e.jsx(y,{sortKey:"sortCategories",currentSortKey:x,currentSortDirection:u,onSort:j,"aria-sort":N("sortCategories"),className:"sticky top-0 z-raised w-[24%] bg-surface-raised py-2 text-left text-xs dark:text-slate-300",children:"Categories"}),e.jsx(we,{className:"sticky top-0 z-raised w-[8%] bg-surface-raised py-2 text-center text-xs dark:text-slate-300",children:"Actions"})]})}),e.jsx(Ce,{children:E.map(s=>e.jsxs(q,{className:"hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-700/50",children:[e.jsx(f,{className:"py-2",children:e.jsx(pe,{className:fe(s.status||"inactive"),children:s.status||"Inactive"})}),e.jsx(f,{className:"py-2 text-content-primary",children:e.jsx(T,{text:s.code||"-",highlight:P})}),e.jsx(f,{className:"py-2 align-middle",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate font-medium text-content-primary",children:[e.jsx(H,{className:"size-4 shrink-0 text-content-tertiary"}),e.jsx("span",{className:"min-w-0 truncate",children:e.jsx(T,{text:s.name||"",highlight:P})})]}),s.description?e.jsx("div",{className:"line-clamp-2 text-xs text-content-tertiary",children:e.jsx(T,{text:s.description,highlight:P})}):null]})}),e.jsx(f,{className:"py-2 align-middle",children:e.jsx("div",{className:"flex flex-wrap gap-1",children:Array.isArray(s.categories)&&s.categories.length>0?s.categories.map(t=>e.jsx("span",{className:"inline-flex rounded-full border border-subtle bg-slate-100 px-2 py-0.5 text-3xs text-content-secondary dark:bg-slate-800",children:F[t]||"Category"},`${s.id}-${t}`)):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500",children:"No categories"})})}),e.jsx(f,{className:"py-2 text-center",children:e.jsxs(ge,{children:[e.jsx(be,{asChild:!0,children:e.jsx(p,{size:"sm",variant:"outline",className:"size-7 p-0 dark:border-slate-600 dar
1k:hover:bg-slate-700","aria-label":`Open actions for ${s.name}`,onClick:t=>t.stopPropagation(),children:e.jsx(Pe,{className:"size-3"})})}),e.jsxs(je,{className:"w-44",align:"end",children:[e.jsxs(R,{onClick:()=>V(s,a),className:"gap-2",children:[e.jsx(Te,{className:"size-3.5"}),e.jsx("span",{children:"Edit product"})]}),J?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{}),e.jsxs(R,{onClick:()=>ke("Products",s.id),className:"gap-2",children:[e.jsx(ye,{className:"size-3.5 text-orange-500"}),e.jsx("span",{children:"Open Firestore"})]})]}):null]})]})})]},s.id))})]})})]})})})}export{Ze 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.