1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6086],{96086:function(e,t,r){r.r(t),r.d(t,{default:function(){return m}});var a=r(27573),l=r(7653),n=r(85569),i=r(84537),s=r(59435),o=r(60127),c=r(15574),d=r(72659),u=r(86566),p=r(53276),h=r(71277);function m(e){let{showModal:t,setShowModal:m,listId:x,abortControllerRef:f,sellerId:g}=e,v=(0,p.S)(),j=(0,h.mN)(),w=(0,h.jj)(),[S,N]=(0,l.useState)("100"),[b,y]=(0,l.useState)(""),[_,E]=(0,l.useState)("csv"),[C,F]=(0,l.useState)(!1),k=async()=>{F(!0);try{let e;let t=v.getState();f.current=new AbortController;let r=f.current.signal,a=(x?w:j).filters.map(e=>({value:e.value,condition:e.condition,displayName:e.displayName,field:e.field,displayValue:e.displayValue,exclusive:e.exclusive,cast:e.cast})),l=await fetch("/api/catalog/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({listId:x,sellerId:g,limit:parseInt(S),fileName:b,sorting:t.sorting,filters:t.columnFilters,advancedFilters:a}),signal:r});if(!l.ok)throw Error("Export failed");let n=await l.json();if(!n||0===n.length)throw Error("No data available for export");let i={Id:"productId",Brand:"brand",Name:"name",UPC:"upc","Buybox Price":"buyboxPrice",Rating:"rating",Reviews:"reviews","Verified Reviews":"verifiedReviews",Variations:"variationCount","Referral Fee":"referralFee","Fulfillment Fee":"fulfillmentFee",...n.some(e=>!!e.user_product_data)?{ROI:e=>{var t;return(null===(t=e.user_product_data[0])||void 0===t?void 0:t.roi)||"N/A"},Cost:e=>{var t;return(null===(t=e.user_product_data[0])||void 0===t?void 0:t.cost)||"N/A"},"Net Profit":e=>{var t;return(null===(t=e.user_product_data[0])||void 0===t?void 0:t.netProfit)||"N/A"},"Profit Margin":e=>{var t;return(null===(t=e.user_product_data[0])||void 0===t?void 0:t.profitMargin)||"N/A"}}:{},"Last Updated":"updatedAt"},s="csv";if("csv"===_){let t=R(n,i);e=new Blob([t],{type:"text/csv"})}else if("excel"===_)s=".xlsx",e=await A(n,i);else throw Error("Unsupported file format");let o=window.URL.createObjectURL(e),c=document.createElement("a");c.style.display="none",c.href=o,c.download="".concat(b,".").concat(s),document.body.appendChild(c),c.click(),window.URL.revokeObjectURL(o)}catch(e){console.error("Export error:",e),e instanceof DOMException&&"AbortError"===e.name?(0,n._N)("You have cancelled the export."):(0,n._N)("An error occurred during export. Please try again"+"".concat(e instanceof Error?", Error: "+e.message:null))}finally{F(!1),m(!1)}},R=(e,t)=>e.length?Object.keys(t).join(",")+"\n"+e.map(e=>Object.values(t).map(t=>'"'.concat("string"==typeof t?e[t]:t(e)||"",'"').replaceAll(",","")).map(e=>null==e?"0":e).join(",")).join("\n"):"";(0,l.useEffect)(()=>{if(t){let e=new Date;y("export_".concat(e.getFullYear()).concat((e.getMonth()+1).toString().padStart(2,"0")).concat(e.getDate().toString().padStart(2,"0"),"_").concat(e.getHours().toString().padStart(2,"0")).concat(e.getMinutes().toString().padStart(2,"0")))}else f.current&&f.current.abort()},[t]);let A=async(e,t)=>{let a=new(await r.e(5497).then(r.t.bind(r,24322,23))).default.Workbook,l=a.addWorksheet("Sheet1");return l.addRow(Object.keys(t)),e.forEach(e=>{l.addRow(Object.values(t).map(t=>'"'.concat(("string"==typeof t?e[t]:t(e)||"").toString().replaceAll('"',""),'"').replaceAll(",","")))}),new Blob([await a.xlsx.writeBuffer()],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})};return(0,a.jsx)(d.u,{showModal:t,setShowModal:m,className:"gap-0 sm:max-w-[425px]",children:(0,a.jsx)(i.Zb,{children:(0,a.jsxs)(i.aY,{className:"sm:max-w-[425px]",children:[(0,a.jsx)(i.Ol,{children:(0,a.jsx)(i.ll,{children:"Export Data"})}),(0,a.jsxs)("div",{className:"grid gap-4 py-4",children:[(0,a.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,a.jsx)(s._,{htmlFor:"rows",className:"text-right",children:"Rows"}),(0,a.jsxs)(u.Select,{value:S,onValueChange:N,children:[(0,a.jsx)(u.SelectTrigger,{className:"col-span-3",id:"rows",children:(0,a.jsx)(u.SelectValue,{placeholder:"Select row count"})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:"100",children:"100 rows"}),(0,a.jsx)(u.SelectItem,{value:"500",children:"500 rows"}),(0,a.jsx)(u.SelectItem,{value:"1000",children:"1,000 rows"}),(0,a.jsx)(u.SelectItem,{value:"5000",children:"5,000 rows"})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,a.jsx)(s._,{htmlFor:"fileName",className:"text-right",children:"File name"}),(0,a.jsx)(o.I,{id:"fileName",value:b,onChange:e=>y(e.target.value),className:"col-span-3"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,a.jsx)(s._,{htmlFor:"fileFormat",className:"text-right",children:"Format"}),(0,a.jsxs)(u.Select,{value:_,onValueChange:e=>E(e),children:[(0,a.jsx)(u.SelectTrigger,{className:"col-span-3",id:"fileFormat",children:(0,a.jsx)(u.SelectValue,{placeholder:"Select file format"})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:"csv",children:"CSV"}),(0,a.jsx)(u.SelectItem,{value:"excel",children:"Excel"})]})]})]})]}),(0,a.jsx)(i.eW,{children:(0,a.jsx)(c.Z,{type:"submit",onClick:k,loading:C,children:"Export"})})]})})})}},15574:function(e,t,r){r.d(t,{Z:function(){return i}});var a=r(27573),l=r(95239),n=r(49877);function i(e){let{loading:t,disabled:r}=e;return(0,a.jsxs)(l.z,{...e,loading:void 0,disabled:r||t,children:[!t&&e.children,t&&(0,a.jsx)(n.P.spinner,{className:"animate-spin"})]})}r(7653)}}]);
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.