1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="0bd8950b-02e4-4ad0-bf03-b376bb4b13cd",e._sentryDebugIdIdentifier="sentry-dbid-0bd8950b-02e4-4ad0-bf03-b376bb4b13cd")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[188],{188:(e,t,s)=>{s.r(t),s.d(t,{default:()=>eE});var r=s(24554),n=s(93438),a=s(87066),i=s(91394),l=s(24912),o=s(90207),c=s(51640);let d=(0,s(11342).v)()(e=>({rowSelection:{},setRowSelection:t=>e(e=>({rowSelection:"function"==typeof t?t(e.rowSelection):t}))}));var u=s(17668),p=s(22463),m=s(53875),h=s(86171),x=s(9378),g=s(17223),f=s(19233),j=s(60345),y=s(71324);function v(e){let{product:t,onEdit:s,onDelete:a,onCopy:i}=e,{t:l}=(0,n.uU)();return(0,r.jsxs)(m.rI,{children:[(0,r.jsx)(x.V,{}),(0,r.jsxs)(m.SQ,{align:"end",children:[i&&(0,r.jsxs)(m._2,{onClick:()=>i(t),children:[(0,r.jsx)(j.T,{className:"mr-2 h-4 w-4"}),l("partners.products.copyAction")]}),s&&(0,r.jsx)(g.Bk,{permission:f.Jj.PRODUCTS_EDIT,hideIfDisabled:!0,children:(0,r.jsxs)(m._2,{onClick:()=>s(t),children:[(0,r.jsx)(y.Z,{className:"mr-2 h-4 w-4"}),l("partners.products.editAction")]})}),a&&(0,r.jsx)(g.Bk,{permission:f.Jj.PRODUCTS_DELETE,hideIfDisabled:!0,children:(0,r.jsx)(h.c,{onClick:()=>a(t)})})]})]})}var b=s(54451);function w(e){let{product:t,onClick:s,onEdit:a,onDelete:i,onCopy:l}=e,{t:o}=(0,n.uU)();return(0,r.jsx)(u.Zp,{className:"mb-4 overflow-hidden ".concat(s?"cursor-pointer hover:bg-accent/50 transition-colors":""),onClick:s?()=>s(t):void 0,children:(0,r.jsx)(u.Wu,{className:"p-4",children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex justify-between items-start gap-4 pb-2 border-b",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-muted-foreground min-w-[100px] shrink-0",children:o("partners.products.productName")}
1),(0,r.jsx)("div",{className:"text-base text-right flex-1 break-all min-w-0 font-semibold",children:t.productName})]}),t.sku&&(0,r.jsxs)("div",{className:"flex justify-between items-start gap-4",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-muted-foreground min-w-[100px] shrink-0",children:o("partners.products.sku")}),(0,r.jsx)("div",{className:"text-sm text-right flex-1 break-all min-w-0 font-mono",children:t.sku})]}),t.size&&(0,r.jsxs)("div",{className:"flex justify-between items-start gap-4",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-muted-foreground min-w-[100px] shrink-0",children:o("partners.products.size")}),(0,r.jsx)("div",{className:"text-sm text-right flex-1 break-all min-w-0",children:t.size})]}),t.hsCode&&(0,r.jsxs)("div",{className:"flex justify-between items-start gap-4",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-muted-foreground min-w-[100px] shrink-0",children:o("partners.products.hsCode")}),(0,r.jsx)("div",{className:"text-sm text-right flex-1 break-all min-w-0 font-mono",children:t.hsCode})]}),t.countryOfOrigin&&(0,r.jsxs)("div",{className:"flex justify-between items-start gap-4",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-muted-foreground min-w-[100px] shrink-0",children:o("partners.products.countryOfOrigin")}),(0,r.jsx)("div",{className:"text-sm text-right flex-1 break-all min-w-0",children:t.countryOfOrigin})]}),t.materialType&&(0,r.jsxs)("div",{className:"flex justify-between items-start gap-4",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-muted-foreground min-w-[100px] shrink-0",children:o("partners.products.materialType")}),(0,r.jsx)("div",{className:"text-sm text-right flex-1 min-w-0",children:(0,r.jsx)(p.E,{variant:"outline",className:"text-xs font-normal",children:b.Hn[t.materialType]})})]}),(0,r.jsx)("div",{className:"flex justify-end pt-2 border-t",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(v,{product:t,onEdit:a,onDelete:i,onCopy:l})})]})})})}var N=s(86022),C=s(13169),S=s(65046),k=s(92484),z=s(65364),T=s(63438),P=s(5182);function O(e){let{data:t,onRowClick:s,onEdit:a,onDelete:u,onCopy:m}=e,{t:h}=(0,n.uU)(),x=(0,c.a)(),{rowSelection:g,setRowSelection:f}=d(),j=(0,i.useMemo)(()=>[{id:"select",size:k.W.select.size,minSize:k.W.select.minSize,enableSorting:!1,enableResizing:!1,header:e=>{let{table:t}=e;return(0,r.jsx)(C.S,{checked:t.getIsAllPageRowsSelected(),onCheckedChange:e=>t.toggleAllPageRowsSelected(!!e),"aria-label":"Select all"})},cell:e=>{let{row:t}=e;return(0,r.jsx)(C.S,{checked:t.getIsSelected(),onCheckedChange:e=>t.toggleSelected(!!e),"aria-label":"Select row"})}},{accessorKey:"productName",id:"productName",header:h("partners.products.productName"),size:k.W.productName.size,minSize:k.W.productName.minSize,cell:e=>{let{row:t}=e;return(0,r.jsx)(S.SU,{value:t.original.productName,fontMedium:!0,fallback:"â"})}},{accessorKey:"sku",id:"sku",header:h("partners.products.sku"),size:k.W.sku.size,minSize:k.W.sku.minSize,cell:e=>{let{row:t}=e;return(0,r.jsx)(S.SU,{value:t.original.sku,mono:!0,fallback:"â"})}},{accessorKey:"size",id:"size",header:h("partners.products.size"),size:k.W.productSize.size,minSize:k.W.productSize.minSize,cell:e=>{let{row:t}=e;return(0,r.jsx)("div",{children:t.original.size||(0,r.jsx)("span",{className:"text-muted-foreground",children:"â"})})}},{accessorKey:"hsCode",id:"hsCode",header:h("partners.products.hsCode"),size:k.W.hsCode.size,minSize:k.W.hsCode.minSize,cell:e=>{let{row:t}=e;return(0,r.jsx)(S.SU,{value:t.original.hsCode,mono:!0,fallback:"â"})}}
1,{accessorKey:"countryOfOrigin",id:"countryOfOrigin",header:h("partners.products.countryOfOrigin"),size:k.W.countryOfOrigin.size,minSize:k.W.countryOfOrigin.minSize,cell:e=>{let{row:t}=e;return(0,r.jsx)("div",{children:t.original.countryOfOrigin||(0,r.jsx)("span",{className:"text-muted-foreground",children:"â"})})}},{accessorKey:"materialType",id:"materialType",header:h("partners.products.materialType"),size:k.W.status.size,minSize:k.W.status.minSize,cell:e=>{let{row:t}=e,s=t.original.materialType;return s?(0,r.jsx)(p.E,{variant:"outline",className:"text-xs font-normal",children:h("enums.materialType.".concat(s))}):(0,r.jsx)("span",{className:"text-muted-foreground",children:"â"})}},{accessorKey:"createdAt",id:"createdAt",header:h("partners.products.colCreated"),size:k.W.date.size,minSize:k.W.date.minSize,cell:e=>{let{row:t}=e,s=t.original.createdAt;return s?(0,P.GP)(new Date(s),"dd/MM/yy"):"â"}},{id:"actions",header:h("common.actions"),size:k.W.actions.size,minSize:k.W.actions.minSize,enableResizing:!1,cell:e=>{let{row:t}=e,s=t.original;return(0,r.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,r.jsx)(v,{product:s,onEdit:a,onDelete:u,onCopy:m})})}}],[h,a,u,m]),{columnVisibility:y,columnOrder:b,columnSizing:O,columnPinning:D,handleVisibilityChange:R,handleOrderChange:I,handleColumnSizingChange:E}=(0,T.M)("products"),U=(0,l.N4)({data:t,columns:j,getCoreRowModel:(0,o.HT)(),getRowId:e=>e.id,onRowSelectionChange:f,onColumnVisibilityChange:R,onColumnOrderChange:I,enableColumnResizing:!0,columnResizeMode:"onChange",onColumnSizingChange:E,state:{rowSelection:g,columnVisibility:y,columnOrder:b,columnSizing:O,columnPinning:D}});return x?(0,r.jsx)("div",{className:"space-y-4",children:t.map(e=>(0,r.jsx)(w,{product:e,onClick:s,onEdit:a,onDelete:u,onCopy:m},e.id))}):(0,r.jsx)("div",{className:"overflow-x-auto border rounded-lg bg-card",children:(0,r.jsxs)(N.XI,{className:"table-fixed",children:[(0,r.jsx)(N.A0,{children:U.getHeaderGroups().map(e=>(0,r.jsx)(N.Hj,{children:e.headers.map(e=>{let t=e.column.getCanResize(),s=e.column.getIsResizing();return(0,r.jsxs)(N.nd,{className:"relative group/resize",style:{width:e.getSize()},children:[e.isPlaceholder?null:(0,l.Kv)(e.column.columnDef.header,e.getContext()),t&&(0,r.jsx)(z.X,{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),isResizing:s})]},e.id)})},e.id))}),(0,r.jsx)(N.BF,{children:U.getRowModel().rows.map(e=>(0,r.jsx)(N.Hj,{"data-testid":"products-table-row",className:s?"cursor-pointer hover:bg-accent":"",onClick:s?()=>s(e.original):void 0,children:e.getVisibleCells().map(e=>(0,r.jsx)(N.nA,{style:{width:e.column.getSize()},onClick:t=>{("actions"===e.column.id||"select"===e.column.id)&&s&&t.stopPropagation()},children:(0,l.Kv)(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})}var D=s(77615),R=s(19054);function I(){let{t:e}=(0,n.uU)();return(0,r.jsx)(D.O,{rows:5,columns:[{header:e("partners.products.colProductName"),width:k.l.productName,renderCell:()=>(0,r.jsx)(R.rr,{width:"w-[160px]"})},{header:e("partners.products.colSku"),width:k.l.sku,renderCell:()=>(0,r.jsx)(R.rr,{width:"w-[70px]"})},{header:e("partners.products.colSize"),width:k.l.productSize,renderCell:()=>(0,r.jsx)(R.rr,{width:"w-[50px]"})},{header:e("partners.products.colHsCode"),width:k.l.hsCode,renderCell:()=>(0,r.jsx)(R.rr,{width:"w-[80px]"})},{header:e("partners.products.colCountry"),width:k.l.countryOfOrigin,renderCell:()=>(0,r.jsx)(R.rr,{width:"w-[40px]"})},{header:e("partners.products.colType"),width:k.l.status,renderCell:()=>(0,r.jsx)(R.rr,{width:"w-[70px]"})},{header:e("partners.products.colCreated"),width:k.l.date,renderCell:D.L.date},{header:e("partners.products.colActions"),width:k.l.actions,renderCell:D.L.actionButtons}]})}var E=s(27262),U=s(65990),F=s(43735);function L(e){let{data:t,onDelete:s}=e,{t:a}=(0,n.uU)(),{rowSelection:i,setRowSelection:l}=d(),o=t.filter(e=>i[e.id]),c=o.length;return(0,r.jsx)(U.$,{selectedCount:c,onDeselectAll:()=>l({}),actions:(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(E.$,{variant:"destructive",onClick:()=>{0!==o.length&&s(o)},disabled:0===o.length,size:"sm",className:"text-xs sm:text-sm px-2 sm:px-3",children:[(0,r.jsx)(F.u,{className:"h-3 w-3 sm:h-4 sm:w-4"}),(0,r.jsxs)("span",{className:"hidden sm:inline ml-2",children:[a("common.delete")," ",o.length>0?"(".concat(o.length,")"):""]}),(0,r.jsxs)("span",{className:"sm:hidden ml-1",children:["(",o.length,")"]})]})})})}var W=s(81110),M=s(34894),B=s(67358),A=s(97653),_=s(31180),q=s(9872);function K(e){var t;let{filters:s,onFilterChange:a,actions:l}=e,{t:o}=(0,n.uU)(),[d,u]=(0,i.useState)(null!=(t=s.q)?t:""),[p,m]=(0,i.useState)(!1),h=(0,c.a)();(0,i.useEffect)(()=>{var e;u(null!=(e=s.q)?e:"")},[s.q]);let x=(0,B.Y)(e=>{a("q",e||null)},300);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 w-full",children:[(0,r.jsxs)("div",{className:"relative flex-1 min-w-0 sm:flex-none sm:w-[300px]",children:[(0,r.jsx)(M.$,{weight:"regular",className:"absolute pointer-events-none left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,r.jsx)(W.p,{placeholder:o("partners.products.toolbarSearch"),value:d,onChange:e=>{u(e.target.value),x(e.target.value)},className:"pl-9 h-9",autoComplete:"off",autoCapitalize:"none",autoCorrect:"off",spellCheck:"false"})]}),(0,r.jsx)(A.q,{tableId:"products",onClick:()=>m(!0),className:"shrink-0"}),(0,r.jsx)(q.v,{children:l})]}),h?(0,r.jsx)(_.u,{tableId:"products",open:p,onOpenChange:m}):(0,r.jsx)(A.g,{tableId:"products",open:p,onOpenChange:m})]})}var $=s(60006),H=s(454),J=s(57681),V=s(42332),X=s(95958),Q=s(16137),G=s(60062),Y=s(15242);function Z(e){let{value:t,onValueChange:s}=e,a=(0,c.a)(),{t:i}=(0,n.uU)(),l=[{value:"all",label:i("partners.products.tabAll"),shortLabel:i("partners.products.tabAllShort"),Icon:$.j},{value:"raw_material",label:i("enums.materialType.raw_material"),shortLabel:i("partners.products.tabRawShort"),Icon:H.X},{value:"component",label:i("enums.materialType.component"),shortLabel:i("partners.products.tabCompShort"),Icon:J.Q}
1,{value:"semi_finished",label:i("enums.materialType.semi_finished"),shortLabel:i("partners.products.tabSemiShort"),Icon:V.m},{value:"finished_good",label:i("enums.materialType.finished_good"),shortLabel:i("partners.products.tabFinishedShort"),Icon:X.q},{value:"packaging",label:i("enums.materialType.packaging"),shortLabel:i("partners.products.tabPackShort"),Icon:Q.ml}];return a?(0,r.jsx)(Y.F,{tabs:l.map(e=>({value:e.value,label:e.shortLabel,Icon:e.Icon})),value:t,onValueChange:s}):(0,r.jsx)(G.tU,{value:t,onValueChange:s,children:(0,r.jsx)(G.j7,{children:l.map(e=>(0,r.jsx)(G.Xi,{value:e.value,children:e.label},e.value))})})}var ee=s(37515),et=s(70359),es=s(1824),er=s(20220),en=s(92650),ea=s(59485),ei=s(74124),el=s(77786),eo=s(40514),ec=s(50725),ed=s(51531),eu=s(89452),ep=s(39981),em=s(77515),eh=s(97148),ex=s(646),eg=s(63051),ef=s(8402),ej=s(9521),ey=s(63487);let ev=["Name","SKU","Size","HS Code","Country of Origin","Material Type"],eb=["EMT Conduit","B-BC0115",'1/2"',"7306","AE","Finished Good"];function ew(e){let{open:t,onOpenChange:s}=e,{t:a}=(0,n.uU)(),[l,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),m=ey.i.useUtils(),h=(0,i.useCallback)(e=>{let t=e[0];return t?ed.aO.includes(t.type)||t.name.match(/\.(csv|tsv|xlsx|xls)$/i)?t.size>0x1400000?void ej.oR.error(a("products.import.fileSizeLimit",{name:t.name})):void(o(t),p(null)):void ej.oR.error(a("products.import.unsupportedFileType",{name:t.name})):void 0},[a]),x=async()=>{if(l){d(!0),p(null);try{let t=new FormData;t.append("file",l);let s=await fetch("/api/products/bulk-import",{method:"POST",body:t,credentials:"include"});if(!s.ok){var e;let t=await s.json().catch(()=>null);throw Error(null!=(e=null==t?void 0:t.message)?e:a("products.import.uploadFailed",{status:s.status}))}let r=await s.json();p(r),r.created>0&&(ej.oR.success(a("partners.products.importCreated",{n:r.created})),m.products.invalidate())}catch(e){ej.oR.error(e instanceof Error?e.message:a("products.import.importFailed"))}finally{d(!1)}}},g=e=>{e||(o(null),p(null)),s(e)};return(0,r.jsx)(el.lG,{open:t,onOpenChange:g,children:(0,r.jsxs)(el.Cf,{className:"sm:max-w-2xl max-h-modal flex flex-col",children:[(0,r.jsxs)(el.c7,{children:[(0,r.jsxs)(el.L3,{className:"flex items-center gap-2",children:[(0,r.jsx)(eu.L,{className:"h-5 w-5",weight:"duotone"}),a("partners.products.importTitle")]}),(0,r.jsx)(el.rr,{children:a("partners.products.importDesc")})]}),(0,r.jsxs)(eo.BJ,{gap:"xl",className:"flex-1 overflow-hidden py-4",children:[!u&&(0,r.jsx)(ec.y,{accept:ed.V0,label:a("partners.products.dropLabel"),dragLabel:a("partners.products.dropDragLabel"),description:a("partners.products.dropDescription"),onFilesSelected:h,disabled:c}),l&&!u&&(0,r.jsxs)(eo.BJ,{direction:"row",align:"center",gap:"lg",className:"p-3 rounded-lg border bg-card overflow-hidden",children:[(0,r.jsx)(ep.z,{className:"h-8 w-8 text-muted-foreground flex-shrink-0"}),(0,r.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,r.jsx)("p",{className:"text-sm font-medium truncate",children:l.name}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:(0,ef.v)(l.size)})]}),!c&&(0,r.jsx)(E.$,{variant:"ghost",size:"icon",className:"h-7 w-7 flex-shrink-0",onClick:()=>o(null),children:(0,r.jsx)(em.u,{className:"h-4 w-4"})})]}),!u&&(0,r.jsxs)("button",{type:"button",onClick:()=>{let e=new Blob([[ev.join(","),eb.join(",")].join("\n")],{type:"text/csv"}),t=URL.createObjectURL(e),s=document.createElement("a");s.href=t,s.download="product-import-template.csv",s.click(),URL.revokeObjectURL(t)},className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[(0,r.jsx)(eh.e,{className:"h-3.5 w-3.5"}),a("partners.products.downloadTemplate")]}),u&&(0,r.jsxs)("div",{className:"rounded-xl border p-4 space-y-3 text-sm",children:[u.created>0&&(0,r.jsxs)(eo.BJ,{direction:"row",align:"center",gap:"md",className:"text-success-foreground",children:[(0,r.jsx)(ex.C,{className:"h-5 w-5 flex-shrink-0",weight:"fill"}),(0,r.jsx)("span",{className:"font-medium",children:a("partners.products.importCreated",{n:u.created})})]}),u.skipped>0&&(0,r.jsx)(eo.BJ,{direction:"row",align:"center",gap:"md",className:"text-muted-foreground",children:(0,r.jsx)("span",{children:a("partners.products.importSkipped",{n:u.skipped})})}),u.errors.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)(eo.BJ,{direction:"row",align:"center",gap:"md",className:"text-destructive-foreground",children:[(0,r.jsx)(eg.M,{className:"h-5 w-5 flex-shrink-0"}),(0,r.jsx)("span",{className:"font-medium",children:a("partners.products.importErrors",{n:u.errors.length})})]}),(0,r.jsxs)("ul",{className:"text-xs text-muted-foreground max-h-40 overflow-y-auto space-y-1 pl-7",children:[u.errors.slice(0,20).map((e,t)=>{var s;return(0,r.jsx)("li",{children:a("partners.products.importRowError",{n:e.row,field:null!=(s=e.field)?s:"",msg:e.message})},t)}),u.errors.length>20&&(0,r.jsx)("li",{className:"italic",children:a("partners.products.importMoreErrors",{n:u.errors.length-20})})]})]}),0===u.created&&0===u.errors.length&&u.skipped>0&&(0,r.jsx)("p",{className:"text-muted-foreground",children:a("partners.products.importAllExist")})]})]}),(0,r.jsxs)(el.Es,{className:"gap-2 sm:gap-0",children:[(0,r.jsx)(E.$,{variant:"outline",onClick:()=>
1g(!1),disabled:c,children:u?a("common.close"):a("common.cancel")}),!u&&(0,r.jsx)(E.$,{onClick:x,disabled:!l||c,children:c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ei.N,{className:"h-4 w-4 mr-2 animate-spin"}),a("partners.products.importing")]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eu.L,{className:"h-4 w-4 mr-2"}),a("partners.products.importBtn")]})})]})]})})}var eN=s(93297),eC=s(91806),eS=s(6367),ek=s(5111),ez=s(90775),eT=s(58052),eP=s(34276);let eO={entityName:"product",copyRelatedData:!1,prepareForCopy:e=>({productName:e.productName,sku:e.sku,size:e.size,sizeUnit:e.sizeUnit,hsCode:e.hsCode,countryOfOrigin:e.countryOfOrigin,materialType:e.materialType,length:e.length,width:e.width,thickness:e.thickness,dimensionUnit:e.dimensionUnit,grossWeight:e.grossWeight,netWeight:e.netWeight,weightUnit:e.weightUnit})};var eD=s(83898),eR=s(13474),eI=s(71626);function eE(){var e,t;let{chrome:s="full"}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l="embedded"===s,{filters:o,setFilter:u,clearFilters:p}=function(){let e=(0,eS.usePathname)(),t=(0,eS.useSearchParams)(),s=(0,eS.useRouter)(),r=(0,i.useMemo)(()=>{let e=new URLSearchParams(t.toString());return{q:e.get("q"),materialType:e.get("materialType")}},[t]);return{filters:r,setFilter:(0,i.useCallback)((r,n)=>{let a=new URLSearchParams(t.toString());null===n||""===n?a.delete(r):a.set(r,n);let i=a.toString(),l="".concat(e).concat(i?"?".concat(i):"");s.push(l)},[e,s,t]),clearFilters:(0,i.useCallback)(()=>{let r=new URLSearchParams(t.toString());r.delete("q"),r.delete("materialType");let n=r.toString(),a="".concat(e).concat(n?"?".concat(n):"");s.push(a)},[e,s,t])}}(),{sheetType:m,productId:h,copyFrom:x,setParams:j}=function(){let e=(0,eS.usePathname)(),t=(0,eS.useSearchParams)(),s=(0,eS.useRouter)(),r=(0,i.useMemo)(()=>{let e=new URLSearchParams(t.toString()),s=e.get("sheet");return{sheetType:s,productId:e.get("productId"),copyFrom:e.get("copyFrom")}},[t]),n=(0,i.useCallback)(r=>{let n=new URLSearchParams(t.toString());null===r?(n.delete("sheet"),n.delete("productId"),n.delete("copyFrom")):void 0!==r.sheetType&&(null===r.sheetType?(n.delete("sheet"),n.delete("productId")):(n.set("sheet",r.sheetType),"edit"===r.sheetType&&r.productId?n.set("productId",r.productId):n.delete("productId")));let a=n.toString(),i="".concat(e).concat(a?"?".concat(a):"");s.push(i)},[e,s,t]);return{...r,setParams:n}}(),{sort:y}=(0,eD.K)(),v=(0,c.a)(),{data:b=[]}=(0,eR.o)(),w=(0,i.useMemo)(()=>b.map(e=>({value:e.code,label:e.name})),[b]),N=(0,eS.useRouter)(),{t:C}=(0,n.uU)(),[S,k]=(0,i.useState)(!1),[z,T]=(0,i.useState)(!1),[P,D]=(0,i.useState)(null),[R,E]=(0,i.useState)([]),{rowSelection:U,setRowSelection:F}=d(),{copyState:W,handleCopy:M,clearCopyState:B}=function(e){let[t,s]=(0,i.useState)(null),[r,n]=(0,i.useState)(!1),[a,l]=(0,i.useState)(null);return{copyState:t,handleCopy:async t=>{try{let r;n(!0),l(null),r=e.copyRelatedData&&e.fetchDetail&&"id"in t?await e.fetchDetail(t.id):t;let a=e.prepareForCopy(r);e.fieldTransformers&&(a=function(e,t){if(!t)return e;let s={...e};for(let[e,r]of Object.entries(t))r&&"function"==typeof r&&e in s&&
1(s[e]=r(s[e]));return s}(a,e.fieldTransformers)),e.postProcess&&(a=e.postProcess(a)),s(a)}catch(s){let t=s instanceof Error?s:Error("Failed to copy");l(t),eP.v.error("Error copying ".concat(e.entityName),{entityName:e.entityName,error:t.message,stack:t.stack})}finally{n(!1)}},clearCopyState:()=>{s(null),l(null)},isCopying:null!==t,isLoading:r,error:a}}(eO),{data:A}=(0,eT.Bj)(null!=x?x:void 0);(0,i.useEffect)(()=>{x&&A&&!W&&M(A)},[x,A,W,M]);let{ref:_,inView:q}=(0,eC.Wx)({rootMargin:"400px"}),$=(0,i.useMemo)(()=>({limit:20,search:o.q||void 0,materialType:o.materialType||void 0,...y&&{sort:y}}),[o,y]),{data:H,fetchNextPage:J,hasNextPage:V,isFetchingNextPage:X,isLoading:Q,isError:G,error:Y}=(0,eT.QT)($),el=(0,i.useMemo)(()=>{var e;return null!=(e=null==H?void 0:H.pages.flatMap(e=>e.items))?e:[]},[H]);(0,i.useEffect)(()=>{q&&V&&!X&&J()},[q,V,X,J]);let eo=(0,eT.Pg)(),ec=(0,eT.CC)(),ed=(0,eT.W$)(),eu=(0,eT.RZ)();(0,i.useEffect)(()=>{if("edit"===m&&h&&!P){let e=el.find(e=>e.id===h);e&&D(e)}},[m,h,P,el]);let ep=!!o.q||!!o.materialType,em=(0,r.jsxs)(g.Bk,{permission:f.Jj.PRODUCTS_CREATE,hideIfDisabled:!0,children:[(0,r.jsx)(es.n,{variant:"outline",onClick:()=>j({sheetType:"create"}),icon:(0,r.jsx)(en.c,{className:"h-4 w-4"}),text:C("shipments.productsPage.btnNewProduct"),"data-testid":"button-create-product"}),(0,r.jsx)(es.n,{icon:(0,r.jsx)(ea.J,{className:"h-4 w-4"}),text:C("shipments.productsPage.btnImport"),onClick:()=>T(!0)})]}),eh=l?em:void 0;return(0,r.jsxs)("div",{className:"space-y-4 px-6 pb-6 ".concat(l?"pt-3":"pt-6"),children:[(0,r.jsx)(ee.B,{title:l?void 0:C("shipments.productsPage.title"),titleTestId:"heading-products",description:l?void 0:C("shipments.productsPage.description"),titleActions:l?void 0:em,tabs:(0,r.jsx)(Z,{value:null!=(e=o.materialType)?e:"all",onValueChange:e=>u("materialType","all"===e?null:e)}),children:(0,r.jsx)(K,{filters:o,onFilterChange:u,actions:eh})}),Q?(0,r.jsx)(I,{}):G?(0,r.jsxs)("div",{className:"text-center py-8 text-destructive-foreground",children:[(0,r.jsx)("p",{className:"font-medium",children:C("shipments.productsPage.errorLoading")}),(0,r.jsx)("p",{className:"text-sm mt-1",children:(null==Y?void 0:Y.message)||C("shipments.productsPage.errorFailed")})]}):ep&&0===el.length?(0,r.jsx)(er.VH,{onClearFilters:p}):0===el.length?(0,r.jsx)(er.UW,{entityName:"product",entityNamePlural:"products",onCreateClick:()=>j({sheetType:"create"})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(O,{data:el,onRowClick:e=>{let t=new URLSearchParams;o.q&&t.set("q",o.q),o.materialType&&t.set("materialType",o.materialType),y&&t.set("sort","".concat(y[0],",").concat(y[1]));let s=t.toString();N.push("".concat((0,eI.X4)(e.id)).concat(s?"?".concat(s):""))},onEdit:e=>{D(e),j({sheetType:"edit",productId:e.id})},onDelete:e=>{D(e),k(!0)},onCopy:e=>{M(e),j({sheetType:"create"})}}),(0,r.jsx)(eN.N,{children:Object.keys(U).length>0&&(0,r.jsx)(L,{data:el,onDelete:e=>{E(e),k(!0)}})}),V&&(0,r.jsx)("div",{ref:_,className:"flex justify-center py-8",children:X&&(0,r.jsx)(ei.N,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),!V&&el.length>0&&(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:C("shipments.productsPage.allLoaded").replace("{count}",String(el.length))})]}),(0,r.jsx)(ek.cj,{open:"create"===m,onOpenChange:e=>{e||(j(null),B())},children:(0,r.jsxs)(ek.h,{"data-testid":"sheet-create-product",side:v?"bottom":"right",className:v?"h-sheet-mobile overflow-y-auto rounded-t-xl":"sm:max-w-xl overflow-y-auto",children:[(0,r.jsxs)(ek.Fm,{children:[(0,r.jsx)(ek.qp,{children:W?C("shipments.productsPage.copySheetTitle"):C("shipments.productsPage.createSheetTitle")}),(0,r.jsx)(ek.Qs,{children:W?C("shipments.productsPage.copySheetDesc"):C("shipments.productsPage.createSheetDesc")})]}),(0,r.jsx)("div",{className:"mt-6",children:x&&!W?(0,r.jsx)("div",{className:"flex justify-center py-8",children:(0,r.jsx)(ei.N,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):(0,r.jsx)(a.i,{mode:W?"copy":"create",initialData:W||void 0,countryOptions:w,onSubmit:e=>{eo.mutate(e,{onSuccess:()=>{j(null),B(),ej.oR.success(W?C("shipments.productsPage.toastCopied"):C("shipments.productsPage.toastCreated"))},onError:e=>{(0,ez.Ox)(e,W?"Copy product":"Create product")}})},onCancel:()=>{j(null),B()},isPending:eo.isPending})})]})}),(0,r.jsx)(ek.cj,{open:"edit"===m,onOpenChange:e=>{e||(j(null),D(null))},children:(0,r.jsxs)(ek.h,{"data-testid":"sheet-edit-product",side:v?"bottom":"right",className:v?"h-sheet-mobile overflow-y-auto rounded-t-xl":"sm:max-w-xl overflow-y-auto",children:[(0,r.jsxs)(ek.Fm,{children:[(0,r.jsx)(ek.qp,{children:C("shipments.productsPage.editSheetTitle")}),(0,r.jsx)(ek.Qs,{children:C("shipments.productsPage.editSheetDesc")})]}),(0,r.jsx)("div",{className:"mt-6",children:(0,r.jsx)(a.i,{mode:"edit",initialData:null!=P?P:void 0,countryOptions:w,onSubmit:e=>{P&&ec.mutate({id:P.id,data:e},{onSuccess:()=>{j(null),D(null),ej.oR.success(C("shipments.productsPage.toastUpdated"))},onError:e=>{(0,ez.Ox)(e,"Update product")}})},onCancel:()=>j(null),isPending:ec.isPending})})]})}),(0,r.jsx)(ew,{open:z,onOpenChange:T}),(0,r.jsx)(et.s,{open:S,onOpenChange:e=>{k(e),e||E([])},onConfirm:()=>{if(R.length>0){let e=R.map(e=>e.id);eu.mutate({ids:e},{onSuccess:t=>{var s;let r=null!=(s=null==t?void 0:t.count)?s:e.length;ej.oR.success(C("shipments.productsPage.toastBulkDeleted").replace("{count}",String(r))),k(!1),E([]),F({})},onError:e=>{(0,ez.Ox)(e,"Batch delete products")}});return}P&&ed.mutate({id:P.id},{onSuccess:()=>{k(!1),D(null),ej.oR.success(C("shipments.productsPage.toastDeleted"))},onError:e=>{(0,ez.Ox)(e,"Delete product")}})},isPending:ed.isPending||eu.isPending,title:R.length>0?C("shipments.productsPage.deleteTitleBulk"):C("shipments.productsPage.deleteTitle"),description:R.length>0?C("shipments.productsPage.deleteDescBulk").replace("{count}",String(R.length)):C("shipments.productsPage.deleteDesc").replace("{name}",null!=(t=null==P?void 0:P.productName)?t:""),testId:"dialog-delete-product"})]})}},1824:(e,t,s)=>{s.d(t,{n:()=>o});var r=s(24554),n=s(91394),a=s(27262),i=s(51640),l=s(66573);let o=n.forwardRef((e,t)=>
1{let{icon:s,text:n,className:o,...c}=e,d=(0,i.a)();return(0,r.jsxs)(a.$,{ref:t,"aria-label":n,className:(0,l.cn)(!d&&"gap-2",o),...c,children:[s,!d&&n]})});o.displayName="ResponsiveActionButton"},8402:(e,t,s)=>{s.d(t,{I:()=>c,v:()=>d});var r=s(53736),n=s(49344),a=s(34503),i=s(39981),l=s(40685),o=s(37240);function c(e){return e?e.includes("pdf")?n.y:e.includes("word")||e.includes("document")?a.w:e.includes("excel")||e.includes("spreadsheet")?i.z:e.includes("jpeg")||e.includes("jpg")?l.n:e.includes("png")?o.h:r.o:r.o}function d(e){return null==e?"-":e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(1)," MB")}},13169:(e,t,s)=>{s.d(t,{S:()=>o});var r=s(24554),n=s(91394),a=s(49957),i=s(70428),l=s(66573);let o=n.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,r.jsx)(a.bL,{ref:t,className:(0,l.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...n,children:(0,r.jsx)(a.C1,{className:(0,l.cn)("flex items-center justify-center text-current"),children:(0,r.jsx)(i.S,{className:"h-4 w-4"})})})});o.displayName=a.bL.displayName},50725:(e,t,s)=>{s.d(t,{y:()=>o});var r=s(24554),n=s(91394),a=s(83656),i=s(89452),l=s(66573);function o(e){let{accept:t,multiple:s=!1,label:o="Drop files here or click to browse",dragLabel:c="Drop files here",description:d,onFilesSelected:u,disabled:p=!1,testId:m}=e,[h,x]=(0,n.useState)(!1),g=(0,n.useRef)(null),f=(0,n.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!0)},[]),j=(0,n.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget===e.target&&x(!1)},[]),y=(0,n.useCallback)(e=>{e.preventDefault(),e.stopPropagation()},[]),v=(0,n.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0&&u(e.dataTransfer.files)},[u]),b=(0,n.useCallback)(e=>{e.target.files&&e.target.files.length>0&&u(e.target.files),e.target.value=""},[u]);return(0,r.jsxs)("div",{className:(0,l.cn)("relative border-2 border-dashed rounded-xl p-8 transition-all duration-300 ease-out","flex flex-col items-center justify-center gap-4 cursor-pointer","hover:border-primary/50 hover:bg-primary/5",h&&"border-primary bg-primary/10 scale-[1.02]",!h&&"border-muted-foreground/25",p&&"pointer-events-none opacity-75"),onDragEnter:f,onDragLeave:j,onDragOver:y,onDrop:v,onClick:()=>{var e;return!p&&(null==(e=g.current)?void 0:e.click())},children:[(0,r.jsx)("input",{ref:g,type:"file",multiple:s,accept:t,onChange:b,className:"hidden","data-testid":m}),(0,r.jsx)(a.P.div,{animate:{scale:h?1.1:1},transition:{type:"spring",stiffness:400,damping:25},children:(0,r.jsx)(i.L,{className:(0,l.cn)("h-16 w-16 transition-colors duration-300",h?"text-primary":"text-muted-foreground/50"),weight:"duotone"})}),(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("p",{className:(0,l.cn)("text-sm font-medium transition-colors duration-300",h?"text-primary":"text-foreground"),children:h?c:o}),d&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d})]})]})}},63438:(e,t,s)=>{s.d(t,{M:()=>l});var r=s(91394),n=s(18429),a=s(80830);let i={left:[],right:["actions"]};function l(e){let t=(0,a.Nt)((0,n.k)(t=>{var s,r;return null!=(r=null==(s=t.preferences[e])?void 0:s.visibility)?r:{}})),s=(0,a.Nt)((0,n.k)(t=>{var s,r;return null!=(r=null==(s=t.preferences[e])?void 0:s.order)?r:[]})),l=(0,a.Nt)((0,n.k)(t=>{var s,r;return null!=(r=null==(s=t.preferences[e])?void 0:s.columnSizing)?r:{}})),{setVisibility:o,setOrder:c,setColumnSizing:d}=(0,a.Nt)(),u=(0,r.useMemo)(()=>({...(0,a.gD)(e),...t}),[e,t]),p=(0,r.useMemo)(()=>(function(e,t){if(0===t.length)return e;let s=new Set(e),r=t.filter(e=>s.has(e));if(0===r.length)return e;let n=new Set(r),a=e.filter(e=>!n.has(e));if(0===a.length){let e=r.indexOf("actions");if(e>=0&&e!==r.length-1){let e=r.filter(e=>"actions"!==e);return e.push("actions"),e}return r}let i=[...r];for(let t of a){let s=e.indexOf(t),r=i.length,n=i.indexOf("actions");n>=0&&(r=n);for(let t=s-1;t>=0;t--){let s=e[t];if(void 0===s)continue;let n=i.indexOf(s);if(n>=0){r=n+1;break}}i.splice(r,0,t)}let l=i.indexOf("actions");return l>=0&&l!==i.length-1&&(i.splice(l,1),i.push("actions")),i})((0,a.YP)(e),s),[e,s]),m=(0,r.useCallback)(t=>{o(e,"function"==typeof t?t(u):t)},[e,u,o]),h=(0,r.useCallback)(t=>{c(e,"function"==typeof t?t(p):t)},[e,p,c]),x=(0,r.useCallback)(t=>{d(e,"function"==typeof t?t(l):t)},[e,l,d]);return{columnVisibility:u,columnOrder:p,columnSizing:l,columnPinning:i,handleVisibilityChange:m,handleOrderChange:h,handleColumnSizingChange:x}}},63487:(e,t,s)=>{s.d(t,{i:()=>i,r:()=>l});var r=s(84731),n=s(99656),a=s(7085);let i=(0,r.pY)(),l=i.createClient({links:[(0,n.fu)({url:"/api/trpc",transformer:a.Ay,fetch(e,t){var s;return fetch(e,{...t,credentials:"include",signal:null!=(s=null==t?void 0:t.signal)?s:null})}})]})},65046:(e,t,s)=>{s.d(t,{SU:()=>u,i8:()=>d,pb:()=>p,xh:()=>m});var r=s(24554),n=s(91394),a=s(70428),i=s(60345),l=s(27262),o=s(22463),c=s(66573);function d(e){let{value:t,showLabel:s=!1,label:o,size:d="icon",className:u}
1=e,[p,m]=(0,n.useState)(!1),h=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(t),m(!0),setTimeout(()=>m(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]);return(0,r.jsx)(l.$,{variant:"ghost",size:d,onClick:h,className:(0,c.cn)("h-7 w-7 p-0 text-muted-foreground hover:text-foreground",s&&"w-auto px-2 gap-1",u),"aria-label":p?"Copied":"Copy to clipboard",children:p?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.S,{className:"h-3.5 w-3.5 text-success-foreground"}),s&&(0,r.jsx)("span",{className:"text-xs",children:o||"Copied"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.T,{className:"h-3.5 w-3.5"}),s&&(0,r.jsx)("span",{className:"text-xs",children:o||"Copy"})]})})}function u(e){let{value:t,mono:s=!1,fontMedium:l=!1,fallback:o="-",className:d}=e,[u,p]=(0,n.useState)(!1),m=(0,n.useCallback)(async e=>{if(e.stopPropagation(),t)try{await navigator.clipboard.writeText(t),p(!0),setTimeout(()=>p(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]);return t?(0,r.jsxs)("div",{className:"group/copy flex items-center gap-1.5 min-w-0",children:[(0,r.jsx)("span",{className:(0,c.cn)("truncate",s&&"font-mono",l&&"font-medium",d),children:t}),(0,r.jsx)("button",{onClick:m,className:(0,c.cn)("shrink-0 p-0.5 rounded opacity-0 group-hover/copy:opacity-100","text-muted-foreground hover:text-foreground hover:bg-muted/50","transition-opacity duration-150",u&&"opacity-100"),"aria-label":u?"Copied":"Copy to clipboard",children:u?(0,r.jsx)(a.S,{className:"h-3.5 w-3.5 text-success-foreground"}):(0,r.jsx)(i.T,{className:"h-3.5 w-3.5"})})]}):(0,r.jsx)("span",{className:"text-muted-foreground",children:o})}function p(e){let{value:t,mono:s=!1,className:i}=e,[l,d]=(0,n.useState)(!1),u=(0,n.useCallback)(async e=>{e.stopPropagation(),e.preventDefault();try{await navigator.clipboard.writeText(t),d(!0),setTimeout(()=>d(!1),1500)}catch(e){console.error("Failed to copy:",e)}},[t]);return(0,r.jsx)(o.E,{variant:"outline",onClick:u,className:(0,c.cn)("text-xs cursor-pointer select-none","transition-all duration-150 active:scale-95","hover:bg-muted/50",s&&"font-mono",l&&"bg-success/10 border-success/30 text-success-foreground",i),"aria-label":l?"Copied!":"Copy ".concat(t),children:l?(0,r.jsxs)("span",{className:"flex items-center gap-1",children:[(0,r.jsx)(a.S,{className:"h-3 w-3"}),"Copied"]}):t})}function m(e){let{value:t,mono:s=!1,className:l}=e,[o,d]=(0,n.useState)(!1),u=(0,n.useCallback)(async e=>{e.stopPropagation(),e.preventDefault();try{await navigator.clipboard.writeText(t),d(!0),setTimeout(()=>d(!1),1500)}catch(e){console.error("Failed to copy:",e)}},[t]);return(0,r.jsxs)("div",{className:"group/copytext flex items-center gap-1 min-w-0",children:[(0,r.jsx)("span",{className:(0,c.cn)("text-sm truncate",s&&"font-mono",l),children:t}),(0,r.jsx)("button",{onClick:u,className:(0,c.cn)("shrink-0 p-0.5 rounded opacity-0 group-hover/copytext:opacity-100","text-muted-foreground hover:text-foreground hover:bg-muted/50","transition-opacity duration-150",o&&"opacity-100 text-success-foreground"),"aria-label":o?"Copied":"Copy to clipboard",children:o?(0,r.jsx)(a.S,{className:"h-3 w-3"}):(0,r.jsx)(i.T,{className:"h-3 w-3"})})]})}},65364:(e,t,s)=>{s.d(t,{X:()=>a});var r=s(24554),n=s(66573);function a(e){let{onMouseDown:t,onTouchStart:s,isResizing:a}=e;return(0,r.jsx)("div",{onMouseDown:t,onTouchStart:s,className:"absolute right-0 top-0 h-full w-4 -mr-2 cursor-col-resize select-none touch-none flex justify-center",children:(0,r.jsx)("div",{className:(0,n.cn)("h-full w-0.5 transition-colors","bg-transparent group-hover/resize:bg-primary/40",a&&"bg-primary")})})}},65990:(e,t,s)=>{s.d(t,{$:()=>i});var r=s(24554),n=s(27262),a=s(83656);function i(e){let{selectedCount:t,onDeselectAll:s,actions:i}=e;return(0,r.jsx)(a.P.div,{className:"h-14 sm:h-12 fixed bottom-2 sm:bottom-4 left-2 sm:left-4 md:left-[3rem] right-2 sm:right-4 pointer-events-none flex justify-center z-50",initial:{y:100,opacity:0},animate:{y:0,opacity:1},exit:{y:100,opacity:0},transition:{type:"spring",stiffness:400,damping:25},children:(0,r.jsxs)("div",{className:"pointer-events-auto backdrop-filter w-full sm:min-w-[400px] sm:w-auto max-w-full backdrop-blur-lg bg-bottom-bar/80 h-full items-center flex px-3 sm:px-4 border border-bottom-bar-border rounded-lg gap-2 sm:gap-3",children:[(0,r.jsxs)("span",{className:"text-xs sm:text-sm text-bottom-bar-foreground whitespace-nowrap",children:["(",t,")"]}),(0,r.jsx)(n.$,{variant:"ghost",onClick:s,size:"sm",className:"text-xs sm:text-sm px-2 sm:px-3",children:"Clear"}),i]})})}}}]);
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.