@attabot/product-app 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1577,7 +1577,7 @@ To suppress this warning, you need to explicitly provide the \`palette.${t}Chann
1577
1577
  <\/script>
1578
1578
  </body>
1579
1579
  </html>
1580
- `},VI=({selectedProducts:e,selectedDesign:t,sheetSize:n,itemsToShow:r,copyPerItem:i=1})=>{if(!e||e.length===0){alert("No products selected for printing");return}const s=window.open("","_blank","width=800,height=600");if(!s){alert("Please allow popups to print promo designs");return}const a=i>0?i:1,c=[];e.forEach(h=>{for(let y=0;y<a;y++)c.push(h)});const d={A4:jI,A7:WI},p=(d[n]||d.A4)({selectedProducts:c,selectedDesign:t,itemsToShow:r});try{s.document.open(),s.document.write(p),s.document.close()}catch(h){console.error("Error writing to print window:",h),alert("Error generating print preview. Please check console for details.")}},sl=l.jsx("span",{style:{display:"inline-block",width:16,height:16,borderRadius:4,border:"0.5px solid #454545",background:"#FFFFFF"}}),al=l.jsx("span",{style:{display:"inline-block",width:16,height:16,borderRadius:4,border:"0.5px solid #2563EB",background:"#FFFFFF",position:"relative"},children:l.jsx("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:l.jsx("path",{d:"M11.6667 3.5L5.25 9.91667L2.33334 7",stroke:"#2563EB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),UI=()=>{const e=new Date,t=e.getFullYear(),n=e.getMonth()+1,r=e.getDate();return{validTo:`${t}-${String(n).padStart(2,"0")}-${String(r).padStart(2,"0")}`,ppd:`${r}/${n}/${t}`}},ly=({open:e,onClose:t,selectedProducts:n=[]})=>{const r=On(),i=z.useMemo(()=>UI(),[]),[s,a]=z.useState({productName:!0,mrp:!0,percentOff:!0,discountPrice:!0}),[c,d]=z.useState("design1"),[u,p]=z.useState(""),[h,y]=z.useState(1),[b,g]=z.useState(!1),[f,m]=z.useState(!1),S=v=>a(w=>({...w,[v]:!w[v]})),C=()=>{if(!n||n.length===0){m(!0);return}if(!u){g(!0);return}g(!1);const v=h>0?h:1;VI({selectedProducts:n,selectedDesign:c,sheetSize:u,itemsToShow:s,copyPerItem:v}),t()};z.useEffect(()=>{(e&&n&&n.length>0||!e)&&queueMicrotask(()=>m(!1))},[e,n]);const x=r.promoPrintModal;return l.jsxs(lo,{open:e,onClose:t,maxWidth:!1,PaperProps:{sx:x.dialog},BackdropProps:{sx:{backdropFilter:"blur(4px)",backgroundColor:"rgba(0, 0, 0, 0.3)"}},children:[l.jsx(co,{sx:{p:0},children:l.jsxs(P,{sx:x.header,children:[l.jsx(j,{sx:x.headerTitle,children:"Promo Print"}),l.jsx(P,{component:"button",onClick:t,sx:x.crossIconCard,"aria-label":"Close",children:l.jsx(oy,{sx:{fontSize:16,color:"#454545"}})})]})}),l.jsx(Oi,{sx:x.content,children:l.jsxs(P,{sx:x.middleCard,children:[l.jsxs(P,{sx:x.itemsToShowSection,children:[l.jsx(j,{sx:x.sectionTitle,children:"Items to show"}),l.jsxs(P,{sx:x.checkboxRow,children:[l.jsx(kn,{control:l.jsx(bt,{checked:s.productName,onChange:()=>S("productName"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"Product Name",sx:x.checkboxLabel}),l.jsx(kn,{control:l.jsx(bt,{checked:s.percentOff,onChange:()=>S("percentOff"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"Percent OFF",sx:x.checkboxLabel}),l.jsx(kn,{control:l.jsx(bt,{checked:s.mrp,onChange:()=>S("mrp"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"MRP",sx:x.checkboxLabel}),l.jsx(kn,{control:l.jsx(bt,{checked:s.discountPrice,onChange:()=>S("discountPrice"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"Discount Price",sx:x.checkboxLabel})]})]}),l.jsxs(P,{sx:x.designSection,children:[l.jsx(j,{sx:x.sectionTitle,children:"Promo Design"}),l.jsxs(P,{sx:x.designContainer,children:[l.jsxs(P,{onClick:()=>d("design1"),sx:{...x.designCard.base,...c==="design1"?x.designCard.selected:x.designCard.unselected},children:[l.jsx(j,{sx:{...x.design1.ourPriceHeader,visibility:s.discountPrice?"visible":"hidden"},children:"SAVE"}),l.jsx(P,{sx:{width:"100%",display:"flex",justifyContent:"center",visibility:s.discountPrice?"visible":"hidden"},children:l.jsxs(P,{sx:{display:"inline-flex",alignItems:"baseline"},children:[l.jsx(j,{component:"span",sx:{...x.design1.rupeeSymbol},children:"₹"}),l.jsx(j,{component:"span",sx:{...x.design1.bigPrice},children:"1387"})]})}),l.jsxs(P,{sx:{...x.design1.bottomInfo,visibility:s.discountPrice||s.mrp?"visible":"hidden"},children:[l.jsxs(j,{sx:{...x.design1.saveAmount,visibility:s.discountPrice?"visible":"hidden"},children:["OUR PRICE: ",l.jsx(j,{component:"span",sx:x.design1.rupeeSymbolSmall,children:"₹"}),"73"]}),l.jsxs(j,{sx:{...x.design1.mrpAmount,visibility:s.mrp?"visible":"hidden"},children:["MRP: ",l.jsx(j,{component:"span",sx:x.design1.rupeeSymbolSmall,children:"₹"}),"1460"]})]}),l.jsx(j,{sx:{...x.design1.productName,visibility:s.productName?"visible":"hidden"},children:"NESCAFE CLASSIC 500g COFFEE BIB"}),l.jsxs(P,{sx:x.design1.dateRow,children:[l.jsxs(j,{sx:x.design1.validFromText,children:["VALID TO: ",i.validTo]}),l.jsxs(j,{sx:x.design1.validToText,children:["PPD: ",i.ppd]})]})]}),l.jsxs(P,{onClick:()=>d("design2"),sx:{...x.designCard.base,...c==="design2"?x.designCard.selected:x.designCard.unselected},children:[l.jsxs(P,{sx:x.design2.mainOfferBlock,children:[l.jsx(j,{sx:{...x.design2.offerLine,visibility:s.percentOff?"visible":"hidden"},children:"Buy 1PC @5.00% Off"}),l.jsx(j,{sx:{...x.design2.offerLine,visibility:s.percentOff?"visible":"hidden"},children:"Buy 2PC @5.00% Off"})]}),l.jsxs(j,{sx:{...x.design2.mrpBlock,visibility:s.mrp?"visible":"hidden"},children:["MRP:",l.jsx(j,{component:"span",sx:x.design2.rupeeSymbolSmall,children:"₹"}),"1460"]}),l.jsx(j,{sx:{...x.design2.productName,visibility:s.productName?"visible":"hidden"},children:"NESCAFE CLASSIC 500G COFFEE BIB"}),l.jsxs(P,{sx:x.design2.dateRow,children:[l.jsxs(j,{sx:x.design2.validFromText,children:["(Valid till: ",i.validTo,")"]}),l.jsxs(j,{sx:x.design2.validToText,children:["(PPD: ",i.ppd,")"]})]})]}),l.jsxs(P,{onClick:()=>d("design3"),sx:{...x.designCard.base,...c==="design3"?x.designCard.selected:x.designCard.unselected},children:[l.jsx(j,{sx:{...x.design3.ourPriceHeader,visibility:s.discountPrice?"visible":"hidden"},children:"OUR PRICE"}),l.jsx(P,{sx:{width:"100%",display:"flex",justifyContent:"center",visibility:s.discountPrice?"visible":"hidden"},children:l.jsxs(P,{sx:{display:"inline-flex",alignItems:"baseline"},children:[l.jsx(j,{component:"span",sx:{...x.design3.rupeeSymbol},children:"₹"}),l.jsx(j,{component:"span",sx:{...x.design3.bigPrice},children:"29"})]})}),l.jsx(j,{sx:{...x.design3.productName,visibility:s.productName?"visible":"hidden"},children:"POTATO BIG KG"}),l.jsxs(P,{sx:x.design3.dateRow,children:[l.jsxs(j,{sx:x.design3.validFromText,children:["[ValidTo: ",i.validTo,"]"]}),l.jsxs(j,{sx:x.design3.validToText,children:["[PPD: ",i.ppd,"]"]})]})]}),l.jsxs(P,{onClick:()=>d("design4"),sx:{...x.designCard.base,...c==="design4"?x.designCard.selected:x.designCard.unselected},children:[l.jsx(j,{sx:{...x.design4.ourPriceHeader,visibility:s.discountPrice?"visible":"hidden"},children:"OUR PRICE"}),l.jsx(P,{sx:{width:"100%",display:"flex",justifyContent:"center",visibility:s.discountPrice?"visible":"hidden"},children:l.jsxs(P,{sx:{display:"inline-flex",alignItems:"baseline"},children:[l.jsx(j,{component:"span",sx:{...x.design4.rupeeSymbol},children:"₹"}),l.jsx(j,{component:"span",sx:{...x.design4.priceWhole},children:"899"}),l.jsx(j,{component:"span",sx:{...x.design4.priceDecimal},children:".70"})]})}),l.jsxs(P,{sx:{...x.design4.saveMrpRow,visibility:s.discountPrice||s.mrp?"visible":"hidden"},children:[l.jsxs(j,{sx:{...x.design4.saveAmount,visibility:s.discountPrice?"visible":"hidden"},children:["SAVE: ",l.jsx(j,{component:"span",sx:x.design4.rupeeSymbolSmall,children:"₹"}),"2099.30"]}),l.jsxs(j,{sx:{...x.design4.mrpAmount,visibility:s.mrp?"visible":"hidden"},children:["MRP:",l.jsx(j,{component:"span",sx:x.design4.rupeeSymbolSmall,children:"₹"}),"2999"]})]}),l.jsx(j,{sx:{...x.design4.productCode,visibility:s.productName?"visible":"hidden"},children:"MCS-SWE-CP-SO-RG-XXL-1402A5-PuLa"}),l.jsxs(P,{sx:x.design4.dateRow,children:[l.jsxs(j,{sx:x.design4.validFromText,children:["[VALIDITY: ",i.validTo,"]"]}),l.jsxs(j,{sx:x.design4.validToText,children:["[PPID: ",i.ppd,"]"]})]})]}),l.jsxs(P,{onClick:()=>d("design5"),sx:{...x.designCard.base,...c==="design5"?x.designCard.selected:x.designCard.unselected},children:[l.jsxs(P,{sx:x.design5.topSection,children:[l.jsxs(P,{sx:x.design5.leftColumn,children:[l.jsxs(P,{sx:x.design5.rewardsLogo,children:[l.jsxs(P,{sx:x.design5.logoLine1,children:[l.jsx(j,{sx:x.design5.logoMy,children:"My"}),l.jsx(j,{sx:x.design5.logoSpencer,children:"spencers"})]}),l.jsxs(j,{sx:x.design5.logoRewards,children:["Rewa",l.jsx(j,{component:"span",sx:x.design5.rupeeSymbol1,children:"₹"}),"ds"]})]}),l.jsxs(j,{sx:{...x.design5.memberPriceLabel,visibility:s.discountPrice?"visible":"hidden"},children:["MEMBER",l.jsx("br",{}),"PRICE"]}),l.jsxs(j,{sx:{...x.design5.memberPriceValue,visibility:s.discountPrice?"visible":"hidden"},children:[l.jsx(j,{component:"span",sx:x.design5.rupeeSymbol,children:"₹"}),"99"]})]}),l.jsx(P,{sx:x.design5.verticalDivider}),l.jsxs(P,{sx:x.design5.rightColumn,children:[l.jsxs(j,{sx:{...x.design5.nonMemberPriceLabel,visibility:s.discountPrice?"visible":"hidden"},children:["NON",l.jsx("br",{}),"MEMBER",l.jsx("br",{}),"PRICE"]}),l.jsxs(j,{sx:{...x.design5.nonMemberPriceValue,visibility:s.discountPrice?"visible":"hidden"},children:[l.jsx(j,{component:"span",sx:x.design5.rupeeSymbol,children:"₹"}),"116"]})]})]}),l.jsxs(P,{sx:x.design5.middleSection,children:[l.jsx(j,{sx:{...x.design5.productName,visibility:s.productName?"visible":"hidden"},children:"MAGGI 2-MINUTE MASALA NOODLES 560G"}),l.jsxs(j,{sx:{...x.design5.mrpText,visibility:s.mrp?"visible":"hidden"},children:["MRP ",l.jsx(j,{component:"span",sx:x.design5.rupeeSymbolSmall,children:"₹"}),"120"]})]}),l.jsx(P,{sx:x.design5.horizontalDivider}),l.jsx(P,{sx:x.design5.bottomSection,children:l.jsx(j,{sx:x.design5.savingsMessage,children:"SAVE UPTO 6% EXTRA MONTHLY WITH MY SPENCERS REWARDS"})})]})]})]}),l.jsxs(P,{sx:x.sheetSizeSection,children:[l.jsx(j,{sx:x.sheetSizeHeader,children:"Sheet Size"}),l.jsxs(P,{sx:x.sheetSizeRow,children:[l.jsx(P,{sx:x.sheetSizeGroup,children:["A4","A7"].map(v=>l.jsx(P,{onClick:()=>{p(v),g(!1)},sx:{...x.sheetSizeBtn,...u===v?x.sheetSizeBtnSelected:{}},children:l.jsx(j,{sx:u===v?{...x.sheetSizeBtnText,...x.sheetSizeBtnTextSelected}:x.sheetSizeBtnText,children:v})},v))}),l.jsxs(P,{sx:x.copyPerItemRow,children:[l.jsx(j,{sx:x.copyPerItemLabel,children:"Enter Copy per item:"}),l.jsx(Ui,{type:"number",value:h,onChange:v=>{const w=parseInt(v.target.value,10);!isNaN(w)&&w>0?y(w):v.target.value===""&&y(1)},inputProps:{min:1,style:{padding:"4px 8px",textAlign:"center",width:"60px"}},sx:{"& .MuiOutlinedInput-root":{height:28,width:"80px",bgcolor:"#F5F5F5"},"& .MuiOutlinedInput-input":{padding:"4px 8px",fontSize:"12px"}},size:"small"})]})]})]})]})}),l.jsxs(yd,{sx:{...x.actions,flexDirection:"column",alignItems:"flex-start"},children:[b&&l.jsx(j,{variant:"body2",sx:{color:"red",mb:.5},children:"Please select a sheet size."}),f&&l.jsx(j,{variant:"body2",sx:{color:"red",mb:.5},children:"No products selected. Please select products first."}),l.jsx(P,{sx:{...x.printButtonWrapper,alignSelf:"stretch",display:"flex",justifyContent:"flex-end"},children:l.jsx(Xe,{type:"button",onClick:C,variant:"contained",sx:x.printButton,children:"Print"})})]})]})},HI=it([l.jsx("path",{d:"M17.59 18 19 16.59 14.42 12 19 7.41 17.59 6l-6 6z"},"0"),l.jsx("path",{d:"m11 18 1.41-1.41L7.83 12l4.58-4.59L11 6l-6 6z"},"1")],"KeyboardDoubleArrowLeft");function Jd(e){return l.jsx(HI,{...e})}const RI=it([l.jsx("path",{d:"M6.41 6 5 7.41 9.58 12 5 16.59 6.41 18l6-6z"},"0"),l.jsx("path",{d:"m13 6-1.41 1.41L16.17 12l-4.58 4.59L13 18l6-6z"},"1")],"KeyboardDoubleArrowRight");function Qd(e){return l.jsx(RI,{...e})}const qI=()=>{const e=on(),t=It(),n=Et(),r=On(),i=n.state?.catalogCreated&&n.state?.catalogSlug?{catalogSlug:n.state.catalogSlug}:null,s=()=>{t(n.pathname,{replace:!0,state:{}})},a=r.categoryDetail,[c,d]=z.useState({category:"all",status:"all",search:"",store:[]}),{integrationData:u,companyId:p,loading:h,categoriesLoading:y,categoriesFetchSettled:b,error:g}=Je(Z=>Z.dashboard),f=z.useMemo(()=>u&&typeof u=="object"&&Object.keys(u).length>0?{matched:!0,error:"",apiResponse:u,loading:!1}:{matched:!1,error:"No active integration found",apiResponse:null,loading:!1},[u]),m=Je(Z=>Z.dashboard),{categoryList:S=[],stores:C=[],categoryPagination:x={}}=m||{},v=S,{currentPage:w=1,limit:A=10,totalCount:O=0,totalPages:L=1,hasNextPage:M=!1}=x,{sharedCatalogues:_=[],sharedCataloguesTotal:I=0,lastStableActiveCatalogsCount:T=null}=Je(Z=>Z.productSettings??{}),F=z.useMemo(()=>Array.isArray(_)?_.filter(Z=>Z.status===!0).length:0,[_]),U=I>0&&_.length>=I?F:T??F,N=Array.isArray(S)&&S.length>0,$=()=>{f.matched?t("/product-setting",{state:{tenantIntegrationMatched:!0}}):t("/product-setting",{state:{tenantIntegrationMatched:!1}})},k=z.useMemo(()=>C.length>0?C:[{id:"all",name:"All Stores",storeCode:"all"}],[C]),V=z.useCallback(Z=>{d(Z)},[d]),B=z.useCallback((Z={})=>{const fe=Array.isArray(c.store)?c.store:[],ye={...Z};if(fe.length>0&&!fe.includes("all")){const K=fe.map(ie=>C.find(ve=>ve.id===ie)?.storeCode).filter(Boolean);K.length>0&&(ye.storeCode=K[0])}return c.search!=null&&String(c.search).trim()!==""&&(ye.search=String(c.search).trim()),c.minOsa!=null&&c.minOsa!==""&&(ye.minOsa=c.minOsa),c.maxOsa!=null&&c.maxOsa!==""&&(ye.maxOsa=c.maxOsa),c.order!=null&&c.order!==""&&(ye.order=c.order),ye},[c.store,c.search,c.minOsa,c.maxOsa,c.order,C]),W=z.useRef(null);z.useEffect(()=>{if(!p)return;const Z=B({page:w,limit:A}),fe=JSON.stringify(Z);W.current!==fe&&(W.current=fe,e(Gn(Z)))},[p,w,A,B,e]);const q=Z=>{const fe=B({page:Z,limit:A});e(Gn(fe))},X=Z=>{const fe=B({page:1,limit:Z});e(Gn(fe))},[G,Q]=z.useState(!1);z.useEffect(()=>{!p&&!G?e(Vo()).finally(()=>{Q(!0)}):p&&queueMicrotask(()=>Q(!0))},[e,p,G]);const ee=z.useRef(null),oe=z.useRef(n.pathname),le=z.useRef(null);z.useEffect(()=>{p&&p!==ee.current&&(ee.current=p,e(zt(p)),e(Gn({page:1,limit:10})),e(Uo()),e(Wo()),e(Yt({page:1})))},[e,p]),z.useEffect(()=>{const Z=oe.current;oe.current=n.pathname;const fe=p&&n.pathname==="/"&&Z!=="/",ye=p&&n.pathname==="/"&&!!n.state?.catalogCreated;(fe||ye)&&(e(Yt({page:1})),e(Gn(B({page:w,limit:A}))),e(Wo()))},[n.pathname,n.state?.catalogCreated,p,e,B,w,A]),z.useEffect(()=>{if(!p||I<=0)return;(Array.isArray(_)?_.length:0)<I&&e(Yt({page:1,limit:I}))},[p,I,_?.length,e,_]);const[ae,re]=z.useState(Array.isArray(n.state?.selectedCategories)?n.state.selectedCategories:[]),[ce,H]=z.useState(Array.isArray(n.state?.selectedProducts)?n.state.selectedProducts:[]),he=Z=>{t(`/category?categoryName=${encodeURIComponent(Z.name||Z.categoryName)}`,{state:{filters:c,selectedCategories:ae,selectedProducts:ce}})},[de,ge]=z.useState(!1),[ze,Ee]=z.useState(!1),[me,De]=z.useState(!1),[Le,Ne]=z.useState([]),[,pe]=z.useState(!1),Ve=z.useCallback((Z,fe={})=>{const ye=Array.isArray(c.store)?c.store:[],K={page:1,limit:5e3,...fe};if(Z&&String(Z).trim()!==""&&(K.categoryName=String(Z).trim()),ye.length>0&&!ye.includes("all")){const ie=ye.map(ue=>C.find(je=>je.id===ue)?.storeCode).filter(Boolean);ie.length>0&&(K.storeCode=ie.join(","))}return c.search!=null&&String(c.search).trim()!==""&&(K.search=String(c.search).trim()),K},[c.store,c.search,C]),Ie=z.useCallback(async()=>{const Z=(Array.isArray(ae)?ae:[]).map(ie=>(ie?.categoryName??ie?.name??"").toString().trim()).filter(Boolean),fe=Array.isArray(ce)?ce:[],ye={};fe.forEach(ie=>{const ue=(ie?.categoryName??ie?.category??"").toString().trim();ue&&(ye[ue]||(ye[ue]=[]),ye[ue].push(ie))});const K=new Set(Object.keys(ye));if(Z.length===0&&fe.length===0){Ne([]),De(!0);return}pe(!0);try{const ie=[];for(const _e of Z){const Ye=ye[_e];if(Ye&&Ye.length>0)ie.push(Ye);else{const Se=Ve(_e),we=await e(Ms(Se)).unwrap().catch(()=>({})),Be=Array.isArray(we?.data)?we.data:Array.isArray(we?.products)?we.products:Array.isArray(we)?we:[];ie.push(Be)}}Z.forEach(_e=>K.delete(_e)),K.forEach(_e=>{ye[_e]?.length&&ie.push(ye[_e])});const ue=ie.flat().filter(Boolean),ve=new Set,je=ue.map(_e=>({..._e,catalogProductId:_e?.productId??_e?.catalogProductId??_e?.id,id:_e?.id||_e?.sku||_e?.productName})).filter(_e=>{const Ye=(_e?.productId||_e?.id||_e?.sku||_e?.productName||"").toString();return!Ye||ve.has(Ye)?!1:(ve.add(Ye),!0)});Ne(je),De(!0)}catch{Ne([]),De(!0)}finally{pe(!1)}},[e,ce,ae,Ve]),se=z.useCallback(Z=>{const fe=Z?.categoryName??Z?.name??"",ye=fe,K=Number(Z?.productCount??0);re(ie=>ie.some(ve=>(ve?.categoryName??ve?.name)===fe)?(H(ve=>{if(!Array.isArray(ve)||!ye)return ve||[];const je=ve.filter(Ye=>(Ye?.categoryName??Ye?.category??"").toString().trim()===ye);return K>0&&je.length>=K?ve.filter(Ye=>(Ye?.categoryName??Ye?.category??"").toString().trim()!==ye):ve}),ie.filter(ve=>(ve?.categoryName??ve?.name)!==fe)):[...ie,Z])},[]),ne=G&&g&&!p,{setTopbarProps:xe}=Yi()||{};return z.useEffect(()=>{if(xe)return ne?(xe({hide:!0}),()=>xe({})):(xe({filters:c,onFilterChange:V,styles:a.topBar,stores:k,tenantStatus:f,hasProducts:N}),()=>xe({}))},[xe,ne,c,V,a.topBar,k,f,N]),l.jsxs(l.Fragment,{children:[i&&l.jsx(SI,{catalogSlug:i.catalogSlug,onClose:s}),l.jsx(P,{sx:ne?{marginTop:0}:N?a.contentWrapper??{marginTop:0,display:"flex",flexDirection:"column",alignItems:"center"}:{marginTop:0},children:ne?l.jsx(Vd,{handleStartSyncing:$,loading:!1,sessionExpired:!0}):!G&&!p?l.jsx(mo,{text:"Fetching",fullScreen:!0}):y?l.jsx(mo,{text:"Fetching Categories",fullScreen:!0}):N?l.jsx(P,{sx:a.root,children:l.jsxs(or,{ref:le,maxWidth:"lg",sx:{px:{xs:1,sm:2,md:4}},children:[l.jsx(ey,{productState:m,categoryCount:S.length,activeCatalogsCount:U,onManageClick:()=>t("/catalogs/manage-shared")}),S.length>0?l.jsxs(l.Fragment,{children:[l.jsx(kI,{categoryData:v,styles:a,onView:he,selectedCategories:ae,onToggleCategory:se}),l.jsx(ry,{containerRef:le,selectedCategories:ae,selectedProducts:ce,onPromoPrint:Ie,onCreateCatalog:()=>ge(!0),onOsaRequest:()=>Ee(!0)}),l.jsx(ly,{open:me,onClose:()=>{De(!1),Ne([])},selectedProducts:Le},me?"open":"closed"),l.jsx(iy,{open:de,onClose:()=>ge(!1),stores:k,selectedProducts:ce,selectedCategories:ae,onCreateSuccess:Z=>{re([]),H([]),ge(!1),Z&&t("/",{state:{catalogCreated:!0,catalogSlug:Z}})}}),l.jsx(sy,{open:ze,onClose:()=>Ee(!1),stores:k,selectedProducts:ce,selectedCategories:ae.map(Z=>Z?.categoryName??Z?.name).filter(Boolean),onSuccess:()=>{re([]),H([])}}),O>0&&(()=>{const Z=a?.categoryTablePagination??{};return l.jsxs(P,{sx:{...Z.wrapper||{},width:"100%",marginLeft:"auto",marginRight:0},children:[l.jsxs(P,{sx:Z.resultsPerPageBox,children:[l.jsx(j,{component:"span",sx:Z.resultsPerPageText,children:"Results per page"}),l.jsx(Pn,{value:A,onChange:fe=>X(Number(fe.target.value)),IconComponent:Nr,variant:"standard",disableUnderline:!0,sx:Z.select,children:[5,10,20,50].map(fe=>l.jsx(We,{value:fe,children:fe},fe))})]}),l.jsxs(P,{sx:Z.navBox,children:[l.jsx(yt,{size:"small",disabled:w<=1,onClick:()=>q(1),sx:Z.iconButton,title:"First page",children:l.jsx(Jd,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:w<=1,onClick:()=>q(w-1),sx:Z.iconButton,title:"Previous page",children:l.jsx(Hi,{sx:{width:16,height:16,opacity:1}})}),l.jsx(j,{component:"span",sx:Z.pageText,children:O===0?"0 of 0":`${(w-1)*A+1}-${Math.min(w*A,O)} of ${O}`}),l.jsx(yt,{size:"small",disabled:!M||w>=L,onClick:()=>q(w+1),sx:Z.iconButton,title:"Next page",children:l.jsx(Ot,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:!M||w>=L,onClick:()=>q(L),sx:Z.iconButton,title:"Last page",children:l.jsx(Qd,{sx:{width:16,height:16,opacity:1}})})]})]})})()]}):l.jsxs(P,{sx:{minHeight:280,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",bgcolor:"#f5f7fa",borderRadius:2,p:3},children:[l.jsx(j,{sx:{fontSize:18,fontWeight:600,color:"#454545",mb:1},children:"No Category"}),l.jsx(j,{sx:{fontSize:14,color:"#808080"},children:c.search&&String(c.search).trim()?"No category found for your search.":"No category available."})]})]})}):l.jsx(Vd,{handleStartSyncing:$,loading:h||y||!b,sessionExpired:!1,hasIntegration:f.matched,showFetchingCategoriesLabel:!0,isHomeCategorySearch:!!(c.search&&String(c.search).trim()),isHomeCategorySearchEmpty:!!(c.search&&String(c.search).trim())&&b&&!y&&!h})})]})};function Fn({icon:e,title:t,subtitle:n,subtitleValue:r,onClick:i,selected:s,highlightStyle:a={},action:c,disabled:d=!1,customStyle:u={},titleColorWhenDisabled:p,titleColor:h,subtitleColor:y}){const b={width:"100%",maxWidth:600,height:58,boxSizing:"border-box",background:"#FFFFFF",borderRadius:2,boxShadow:"none",border:"1px solid #F1F1F1",display:"flex",alignItems:"center",gap:1.5,px:2,py:1.5,mb:0,cursor:i&&!d?"pointer":"default",opacity:d?.5:1,...s?a:{}},g=d?p||"#999999":h||"#000000",f=d?"#bbbbbb":y||"#808080",m={card:{...b,...u},cardInner:{display:"flex",alignItems:"center",flex:1,minWidth:0},icon:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,mr:2},title:{fontWeight:700,fontSize:12,color:g,lineHeight:"16px"},subtitle:{color:f,fontSize:12,fontWeight:400,mt:.5,lineHeight:"16px"}};return l.jsxs(P,{onClick:d?void 0:i,sx:{...m.card,...u||{}},children:[e&&l.jsx(P,{sx:m.icon,children:e}),l.jsxs(P,{sx:m.cardInner,children:[l.jsxs(P,{children:[l.jsx(j,{sx:m.title,children:t}),n&&l.jsx(j,{sx:m.subtitle,children:r?`${r} ${n}`:n})]}),c&&l.jsx(P,{sx:{ml:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:c})]})]})}function Zd({size:e=15,color:t="#454545",...n}){return l.jsx(gI,{size:e,color:t,...n})}const YI="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAASpJREFUeAGVUT1OhGAQ5b/2BPxewhISIHSyJ/AKlnbunsBsZenuCdQOgWQp7VY7C0i+0u2w00DAN2ZNYMOXyCSTGZh5897MJwgcC4Jg7/u+y6tLvELf92bXdeYsIDGJonimKMrFLCBAlwivYI1d1zX/BQzD8AYhlmV5AalrVVV3U2B5KM9xnHsCwb00Td8Nw3iRJOkcQ65R+9R1ncG+flXR9egQtBOcodFLkoQJ452vULs9rsHQv5Ityzrg4w1+wH+XilVVPQ+VINxh4AcAa+RPTdM8isPJURTRE+zQwLIs87BvjPyBGPI8X44OeLo0gdu23YNhQ1eFb09Bo+P8WVmWtW3b30iXkF+DeSFM2OQ7gnFDEbK3AscmgUVR1AgMQDYLeLSVpmkFr/gDCe+DRKwM0doAAAAASUVORK5CYII=",KI="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAAIpJREFUeAFVTsENwyAMxCkPnowQNmgnCB8Qv46QrtNfV+gG/YPUjtABeGSEDIAgPimJEkvnO9ln+YRYyzn38N5/xKG6gx5aa4O1Vm8DwgXzyLgyJoZm07uU8upYjETUY8H8Y4a+K6U04TyE0Ndav2zE4hZj/GN+Qcs5z8YYGFVK6bn9lLuQEklPaRdNCCms4XdYvwAAAABJRU5ErkJggg==";function GI(e){const{sx:t={},...n}=e;return l.jsxs(P,{sx:{width:20,height:20,opacity:1,position:"relative",flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",...t},...n,children:[l.jsx(P,{component:"img",src:YI,alt:"",sx:{position:"absolute",width:12.25,height:12.25,top:1.84,left:1.84,opacity:1,boxSizing:"border-box",objectFit:"contain",display:"block"}}),l.jsx(P,{component:"img",src:KI,alt:"",sx:{position:"absolute",width:5.104,height:5.104,top:13.06,left:13.06,opacity:1,boxSizing:"border-box",objectFit:"contain",display:"block"}})]})}function cy({size:e=15,color:t="#454545",...n}){return l.jsx(pI,{size:e,color:t,...n})}function XI({size:e=15,color:t="#454545",...n}){return l.jsx(fI,{size:e,color:t,...n})}function JI({size:e=15,color:t="#454545",...n}){return l.jsx(hI,{size:e,color:t,...n})}function QI({airaAiEnabled:e,setAiraAiEnabled:t,selectedCard:n,setSelectedCard:r,syncStep:i=0,syncMethod:s="",onSetupSync:a=()=>{},onSyncNow:c=()=>{},integrationData:d={},...u}){const p={bgcolor:"#F3F8FF",border:"1px solid #2D64B8"},h=It(),y=d?.configs?.sync_frequency||"Daily",b=d?.configs?.sync_time||"10:00 AM",g=d?.type||s||"FTP",f={width:600,maxWidth:"100%",minHeight:468,mx:"auto",mt:4,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:3},m=()=>l.jsxs(P,{sx:{width:"100%",minHeight:156,display:"flex",flexDirection:"column",gap:1.5},children:[l.jsx(P,{sx:{width:"100%",height:20,display:"flex",alignItems:"center",justifyContent:"space-between"},children:l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"6px",width:67,height:20},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:14,lineHeight:"20px",color:"#000000"},children:"General"}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:12,lineHeight:"16px",color:"#808080"},children:"2"})]})}),l.jsxs(P,{sx:{width:"100%",minHeight:124,display:"flex",flexDirection:"column",gap:"4px"},children:[l.jsx(Fn,{icon:l.jsx(Zd,{size:15,color:"#454545"}),title:"Manage Shared Catalogs",onClick:()=>h("/catalogs/manage-shared"),selected:n==="catalogs",highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsx(Fn,{icon:l.jsx(GI,{}),title:"Aira AI",subtitle:"Make your workflows faster and smarter",onClick:()=>r&&r("aira-ai"),selected:n==="aira-ai",highlightStyle:p,action:l.jsx(P,{sx:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(_m,{checked:e,onChange:v=>t&&t(v.target.checked),size:"small"})})})]})]}),S=(v,w)=>l.jsxs(P,{sx:{width:"100%",height:20,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"6px",width:48,height:20},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:14,lineHeight:"20px",color:"#000000"},children:"Sync"}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:12,lineHeight:"16px",color:"#808080"},children:"2"})]}),l.jsxs(P,{sx:{width:78,height:16,display:"flex",alignItems:"center",gap:"4px",cursor:v?"not-allowed":"pointer",opacity:v?.5:1},onClick:v?void 0:w,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(Or,{sx:{width:14.66,height:12,color:"#2D64B8"}})}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:12,lineHeight:"16px",color:"#2D64B8",width:62},children:"Sync Now"})]})]}),C=v=>{const w=v?y:"Daily",A=v?b:"10:00 AM",O=!v&&i===0;return l.jsxs(P,{sx:{width:"100%",minHeight:288,display:"flex",flexDirection:"column",gap:"4px"},children:[S(O,c),!v&&i===0&&l.jsx(Fn,{icon:l.jsx(Or,{sx:{width:18.33,height:15,color:"#454545"}}),title:"Setup Sync",subtitle:"Sync products",onClick:a,highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),!v&&i===1&&l.jsxs(l.Fragment,{children:[l.jsx(Fn,{icon:l.jsx(Or,{sx:{width:18.33,height:15,color:"#454545"}}),title:"Sync Method",subtitle:g,highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsx(Fn,{icon:l.jsx(Zd,{size:15,color:"#454545"}),title:`Setup ${g} Details`,subtitle:"Start setup",onClick:()=>{h("/products/settings/ftp-sync",{state:{fromSyncStep:i}})},highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})]}),i===3&&l.jsxs(l.Fragment,{children:[l.jsx(Fn,{icon:l.jsx(Or,{sx:{width:18.33,height:15,color:"#454545"}}),title:"Sync Method",subtitle:s||"FTP",highlightStyle:p,disabled:!0,titleColorWhenDisabled:"#454545",action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsx(Fn,{icon:l.jsx(Zd,{size:15,color:"#454545"}),title:"FTP Details",subtitle:"Sync source",highlightStyle:p,onClick:()=>h("/products/settings/ftp-sync",{state:{fromSyncStep:i}}),action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsxs(P,{sx:{width:"100%",display:"flex",flexWrap:"nowrap",justifyContent:"space-between"},children:[l.jsx(P,{sx:{width:296},children:l.jsx(Fn,{icon:l.jsx(cy,{size:15,color:"#454545"}),title:"Sync Frequency",subtitle:w,highlightStyle:p,customStyle:{mb:0},onClick:()=>h("/products/settings/ftp-sync",{state:{fromProductSetting:!0,fieldToEdit:"syncFrequency",integrationData:d}}),action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})}),l.jsx(P,{sx:{width:296},children:l.jsx(Fn,{icon:l.jsx(XI,{size:15,color:"#454545"}),title:"Sync Time",subtitle:A,highlightStyle:p,customStyle:{mb:0},onClick:()=>h("/products/settings/ftp-sync",{state:{fromProductSetting:!0,fieldToEdit:"syncTime",integrationData:d}}),action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})})]}),l.jsx(Fn,{icon:l.jsx(JI,{size:15,color:"#454545"}),title:"Sync History",subtitle:"12,139 items",highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})]})]})},x=i===3&&d&&Object.keys(d||{}).length>0;return l.jsxs(P,{sx:f,children:[m(),C(x)]})}function ZI({open:e,onClose:t,onSave:n}){vn();const r=On(),[i,s]=z.useState("sftp"),a=[{value:"sftp",label:"SFTP"},{value:"webhook",label:"Webhook"},{value:"aira-api",label:"AIRA API"},{value:"file-upload",label:"File Upload"}],c=h=>s(h.target.value),d=()=>{n&&n(i),t()},u=()=>{},p=r.productSettingModal;return l.jsx(ao,{open:e,onClose:t,"aria-labelledby":"product-sync-setting-modal",sx:p.modal,children:l.jsxs(P,{sx:p.container,children:[l.jsxs(P,{sx:p.header,children:[l.jsx(j,{sx:p.headerTitle,children:"Sync Method"}),l.jsx(yt,{onClick:t,size:"small",sx:p.closeButton,children:l.jsx(mI,{size:20})})]}),l.jsxs(P,{sx:p.content,children:[l.jsx(Ya,{value:i,onChange:c,children:a.map(h=>l.jsx(kn,{value:h.value,control:l.jsx(fo,{icon:l.jsx(P,{sx:p.radioIcon}),checkedIcon:l.jsx(uI,{size:18,color:"#000"}),sx:p.radioChecked}),label:l.jsx(j,{sx:p.radioLabel,children:h.label}),sx:{...p.formControlLabel,...i===h.value&&{backgroundColor:"#F3F8FF"}}},h.value))}),l.jsxs(P,{sx:p.upgradeSection,children:[l.jsx(j,{sx:p.upgradeText,children:"Upgrade for higher sync limits and more features"}),l.jsx(j,{onClick:u,sx:p.managePlanLink,children:"Manage Plan >"})]})]}),l.jsx(P,{sx:p.footer,children:l.jsx(Xe,{fullWidth:!0,variant:"contained",onClick:d,sx:p.saveButton,children:"Save"})})]})})}const eN=({isOpen:e,onClose:t,onConfirm:n})=>{const r=On();let i;return i=r.productSettingModal,l.jsx(ao,{open:e,onClose:t,"aria-labelledby":"sync-now-modal",sx:i.modal,children:l.jsxs(P,{sx:i.container,children:[l.jsx(P,{sx:i.header,children:l.jsx(j,{sx:{...i.headerTitle,fontSize:22},children:"Are you sure to SyncNow ?"})}),l.jsxs(P,{sx:{...i.footer,flexDirection:"row",gap:2,justifyContent:"center"},children:[l.jsx(Xe,{variant:"contained",color:"primary",onClick:n,sx:{minWidth:100,mx:4},children:"Yes"}),l.jsx(Xe,{variant:"outlined",color:"primary",onClick:t,sx:{minWidth:100},children:"No"})]})]})})};function tN(){const e=Et(),t=It(),n=on(),{companyId:r,integrationData:i,loading:s}=Je(D=>D?.dashboard||{}),[a,c]=z.useState(!0),[d,u]=z.useState(),[p,h]=z.useState(0),[y,b]=z.useState(""),[g,f]=z.useState(!1),[m,S]=z.useState(!1),[C,x]=z.useState(!1),[v,w]=z.useState(""),A=z.useRef(null),O=z.useRef(!1);z.useEffect(()=>{const D=e.state?.tenantIntegrationMatched===!0;r&&r!==A.current&&!s&&(i&&(i?.id||i?.channelId||i?.configs||typeof i=="object"&&Object.keys(i).length>0)?A.current=r:(A.current=r,n(zt(r)))),D&&r&&!s&&!O.current&&(O.current=!0,n(zt(r))),D||(O.current=!1)},[r,n,s,i,e.state]),z.useEffect(()=>{let D=!1;e.state&&typeof e.state.tenantIntegrationMatched=="boolean"&&(D=e.state.tenantIntegrationMatched);const U=i&&(i?.id||i?.channelId||i?.configs||Array.isArray(i?.data)&&i.data.length>0||typeof i=="object"&&Object.keys(i).length>0),N=e.state?.fromSyncStep===1?1:D===!0||U?3:0;queueMicrotask(()=>h(N))},[e.state,i]);const L=()=>f(!0),M=D=>{b(D),h(1),f(!1)},_=()=>{t("/products/settings/ftp-sync",{state:{fromSyncStep:p}})},I=async()=>{const D=i?.channelId||i?.id;if(!D){w("Channel ID not found"),x(!0),S(!1);return}S(!1);try{const U=await n(Yo(D));if(Yo.fulfilled.match(U)){const N=U.payload?.message==="Sync started successfully"?"Sync started successfully":"Sync not started successfully";w(N),x(!0),N==="Sync started successfully"&&setTimeout(()=>{n(zt(r)),n(zn()),t("/")},2500)}else w("Sync not started successfully"),x(!0)}catch{w("Sync not started successfully"),x(!0)}},T=z.useCallback(()=>{p===1?(h(0),b("")):t("/")},[p,t]),{setSettingTopbarProps:F}=Yi()||{};return z.useEffect(()=>{if(F)return F({onBack:T}),()=>F({})},[F,T]),l.jsxs(P,{sx:{width:"100%",minHeight:"100vh",background:"#f7f8fa",p:0,pt:"72px",display:"flex",flexDirection:"column",alignItems:"center"},children:[l.jsx(ZI,{open:g,onClose:()=>f(!1),onSave:M}),l.jsx(eN,{isOpen:m,onClose:()=>S(!1),onConfirm:I}),l.jsx(go,{open:C,autoHideDuration:4e3,onClose:()=>x(!1),message:v,anchorOrigin:{vertical:"top",horizontal:"center"}}),l.jsx(QI,{airaAiEnabled:a,setAiraAiEnabled:c,selectedCard:d,setSelectedCard:u,syncStep:p,syncMethod:y,integrationData:i,onSetupSync:L,onSetupFTP:_,onSyncNow:()=>S(!0)})]})}const nN=["Setup FTP","Check data","Start Sync"],rN=e=>l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{maxWidth:800,mx:"auto",pt:2,px:2},children:[l.jsx(P,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",px:2,py:2,mb:1},children:nN.map((t,n)=>l.jsx(j,{component:"span",sx:{fontFamily:"Inter, sans-serif",fontWeight:n===0?600:400,fontSize:"12px",lineHeight:"16px",letterSpacing:"0px",textAlign:"center",verticalAlign:"middle",color:"#454545",opacity:1,width:224,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:1},children:t},t))}),l.jsx(P,{sx:{width:800,height:504,gap:"8px",borderRadius:"16px",padding:"8px",background:"#FFFFFF",opacity:1,display:"flex",justifyContent:"center",alignItems:"center",boxSizing:"border-box"},children:l.jsxs(cn,{elevation:0,sx:{width:400,height:210,gap:"24px",borderRadius:"20px",padding:"24px",background:"#fafafa",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsxs(P,{sx:{width:352,height:98,gap:"12px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:700,fontSize:"16px",lineHeight:"20px",letterSpacing:"0px",verticalAlign:"middle",color:"#000000",opacity:1,width:145,height:20,margin:0},children:"Setup Instructions"}),l.jsxs(P,{component:"ol",sx:{margin:0,paddingLeft:"28px",listStylePosition:"outside",listStyleType:"decimal",fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"22px",letterSpacing:"0px",color:"#454545",opacity:1,width:352,height:66,boxSizing:"border-box","& li":{display:"list-item",marginBottom:"4px"},"& li:last-child":{marginBottom:0}},children:[l.jsx("li",{children:"Directory should have just one file"}),l.jsx("li",{children:"File format must be in CSV (comma separated)"}),l.jsx("li",{children:"File structure should be flat"})]})]}),l.jsx(P,{sx:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none"},onClick:()=>e.onNext&&e.onNext(),children:"Next"})})]})})]})});function oN(e){const{sx:t,fontSize:n,...r}=e;return l.jsxs(er,{viewBox:"0 0 14.666666 10.666666",sx:{fontSize:n||14.666666,color:"#454545",...t},...r,children:[l.jsx("path",{d:"M1 5.333333C2.2 3.2 4.266667 1.666667 7.333333 1.666667C10.4 1.666667 12.466667 3.2 13.666667 5.333333C12.466667 7.466667 10.4 9 7.333333 9C4.266667 9 2.2 7.466667 1 5.333333Z",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"7.333333",cy:"5.333333",r:"2",fill:"none",stroke:"currentColor",strokeWidth:"1"})]})}function iN(e){const{sx:t,fontSize:n,...r}=e;return l.jsxs(er,{viewBox:"0 0 14.666666 10.666666",sx:{fontSize:n||14.666666,color:"#454545",...t},...r,children:[l.jsx("path",{d:"M1 5.333333C2.2 3.2 4.266667 1.666667 7.333333 1.666667C10.4 1.666667 12.466667 3.2 13.666667 5.333333C12.466667 7.466667 10.4 9 7.333333 9C4.266667 9 2.2 7.466667 1 5.333333Z",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"7.333333",cy:"5.333333",r:"2",fill:"none",stroke:"currentColor",strokeWidth:"1"}),l.jsx("path",{d:"M2 9L12.666667 1.666667",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round"})]})}const sN=({active:e,completed:t,showBlue:n})=>{const r=!e&&!t,i=n?"#2D64B8":"#bbb";return l.jsx(P,{sx:{position:"relative",width:16,height:16,borderRadius:"50%",border:"1px solid",borderColor:i,opacity:1,display:"flex",alignItems:"center",justifyContent:"center",background:"#fff",boxSizing:"border-box",flexShrink:0},children:r?l.jsx("svg",{width:10,height:10,viewBox:"0 0 24 24",fill:"none",style:{display:"block"},children:l.jsx("path",{d:"M7 10l5 5 5-5",stroke:i,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):l.jsx("svg",{width:8,height:8,viewBox:"0 0 24 24",fill:"none",style:{display:"block"},children:l.jsx("path",{d:"M7 12.5L11 16L17 9.5",stroke:"#2D64B8",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})},ll=({steps:e=[],activeStep:t=0,showCheckDataBlueTick:n=!1,progressToCheckData:r=!1,showSetupFtpBlueTick:i=!1,showStartSyncBlueTick:s=!1,instantComplete:a=!1,progressSegment:c,filledSegments:d,filledSegmentsStart:u=0,previousStepsComplete:p=!1})=>{const y=vn().transitions?.duration?.standard??400,[b,g]=z.useState(0),[f,m]=z.useState(!1),S=Math.max(1,e.length),C=50/S,x=100*(S-1)/S,v=40/S,w=S>1?100/S:0,A=100,O=z.useMemo(()=>{let L;if(typeof d=="number"){const _=typeof u=="number"?u:0,I=d-_;L=w*(_+b*I)}else typeof c=="number"?L=w*(c+b):s?L=b?x:0:r?L=b?x*.5:0:L=b?v:0;const M=Math.min(L,x)/x;return Math.round(M*A)},[b,d,u,c,s,r,w,x,v]);return z.useEffect(()=>{if(a){setTimeout(()=>{g(1),m(!0)},0);return}if(typeof d=="number"&&typeof u=="number"&&u>0){setTimeout(()=>{g(0),m(!1)},0);const M=setTimeout(()=>{g(1),setTimeout(()=>m(!0),y)},50);return()=>clearTimeout(M)}setTimeout(()=>{g(0),m(!1)},0);const L=setTimeout(()=>{g(1),setTimeout(()=>m(!0),y)},50);return()=>clearTimeout(L)},[t,e.length,r,a,d,u,y]),l.jsxs(P,{sx:{width:800,opacity:1},children:[l.jsx(P,{sx:{width:800,height:44,gap:"16px",opacity:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:e.map((L,M)=>l.jsxs(P,{sx:{width:256,height:44,gap:"12px",opacity:1,paddingLeft:"16px",paddingRight:"16px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:[l.jsx(sN,{active:M===t,completed:M<t,showBlue:M===0&&i||M===1&&n&&(f||p)||M===2&&s}),l.jsx(P,{component:"span",sx:{width:224,height:16,fontFamily:"Inter, sans-serif",fontWeight:M===0?600:400,fontSize:"12px",lineHeight:"16px",letterSpacing:"0px",textAlign:"center",color:"#454545",opacity:1,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:L})]},L))}),l.jsx(P,{sx:{width:"100%",mt:1,mb:0},children:l.jsx(P,{sx:{marginLeft:`${C}%`,width:`${x}%`},children:l.jsx(hm,{variant:"progress",steps:A+1,position:"static",activeStep:O,sx:{maxWidth:"100%",flexGrow:1,background:"transparent",padding:0,"& .MuiMobileStepper-progress":{width:"100%"},"& .MuiLinearProgress-root":{height:4,borderRadius:2,backgroundColor:"#f2f2f2"},"& .MuiLinearProgress-bar":{backgroundColor:"#219653"}},nextButton:null,backButton:null})})})]})},aN=e=>e.dashboard?.companyId||"";function lN(e){try{const t=new URL(e);return{type:t.protocol.replace(":",""),host:t.hostname,port:t.port,path:t.pathname}}catch{return{type:"",host:"",port:"",path:""}}}const cN=e=>{const{ftpDetails:t={},stepperProps:n={}}=e,[r,i]=z.useState(null),s=Et(),a=It(),c=Je(aN),[d,u]=z.useState(!1);z.useEffect(()=>{let M,_;return setTimeout(()=>{u(!1),M=setTimeout(()=>{_=setTimeout(()=>u(!0),600)},100)},0),()=>{M&&clearTimeout(M),_&&clearTimeout(_)}},[]);const[p,h]=z.useState(!1),y=localStorage.getItem("selectedSyncMethod")||"sftp",[b,g]=z.useState(`${y}:`),[f,m]=z.useState(""),[S,C]=z.useState(""),x=on(),v=Je(M=>M.productSettings?.loading||!1),w=Je(M=>M.productSettings?.error||null),A=vn();ht(A.breakpoints.up("lg"));const O=Je(M=>M.productSettings.syncData);z.useEffect(()=>{const M=s.state?.ftpConfig,_=s.state?.tenantIntegrationData;if(O&&O.serverAddress){setTimeout(()=>{g(O.serverAddress||""),m(O.configs&&O.configs.username||""),C(O.configs&&O.configs.password||"")},0);return}if(t&&(t.host||t.username||t.password)){const I=t.type||"sftp",T=t.host||"",F=t.port||"",D=t.path||"",U=`${I}://${T}${F?`:${F}`:""}${D?`/${D}`:""}`;setTimeout(()=>{g(U),m(t.username||""),C(t.password||"")},0);return}if(_&&_.configs){const I=_.configs,T=I.type||_.type||"sftp",F=I.host||"",D=I.port||"",U=I.path||"",N=`${T}://${F}:${D}/${U}`,$=I.username||"",k=I.password||"";setTimeout(()=>{g(N),m($),C(k)},0);return}if(M){const T=`${M.type||"sftp"}://${M.host}:${M.port}/${M.path}`,F=M.username||"",D=M.password||"";setTimeout(()=>{g(T),m(F),C(D)},0)}},[s.state,O,t]);const L=async()=>{if(!c){alert("Company ID is required. Please ensure the app is properly configured.");return}const{type:M,host:_,port:I,path:T}=lN(b),F=await x(Ro({serverAddress:b,username:f,password:S,companyId:c}));if(!Ro.fulfilled.match(F))return;const D=F.payload;if(s.state?.fromSettingsIcon){const $=D?.entity_type||r?.entity_type||"products",k={...r||{},companyId:c,tenantId:c,type:M,serverAddress:b,configs:{host:_,port:Number(I),path:T,username:f,password:S,sync_frequency:r?.configs?.sync_frequency||t?.sync_frequency||"",sync_time:r?.configs?.sync_time||t?.sync_time||""},entity_type:$,mappings:r?.mappings||D?.existing_mapping?.mappings||[]};i(k),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(k)),a("/ftp-sync-2",{state:{fromSettingsIcon:!0,putjson:k}});return}const U=D?.entity_type||"",N={tenantId:c,type:M,serverAddress:b,configs:{host:_,port:Number(I),path:T,username:f,password:S,sync_frequency:"",sync_time:""},entity_type:U||"products",mappings:D?.existing_mapping?.mappings||[]};x(zs(N)),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(N)),e.onNext&&e.onNext({putjson:N})};return l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,minHeight:600,gap:"32px",opacity:1,pt:2,left:"340px",mx:"auto",display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...n,showSetupFtpBlueTick:d})}),l.jsx(P,{sx:{width:800,height:504,minHeight:504,borderRadius:"16px",padding:"8px",paddingBottom:"32px",gap:"8px",opacity:1,display:"flex",justifyContent:"center",alignItems:"center",bgcolor:"#fff",boxSizing:"border-box",marginBottom:"32px"},children:l.jsxs(P,{sx:{width:400,height:380,borderRadius:"20px",padding:"24px",gap:"24px",opacity:1,bgcolor:"#F5F5F5",display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx(P,{sx:{width:352,height:20,justifyContent:"space-between",opacity:1,display:"flex",alignItems:"center"},children:l.jsx(j,{sx:{width:102,height:20,fontFamily:"Inter, sans-serif",fontWeight:700,fontSize:"16px",lineHeight:"20px",letterSpacing:"0px",color:"#000000",opacity:1,margin:0},children:"Login Details"})}),l.jsxs(P,{component:"form",autoComplete:"off",sx:{width:352,height:224,gap:"16px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsxs(P,{sx:{width:352,height:64,gap:"4px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx("label",{style:{width:352,height:18,fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"18px",letterSpacing:"0px",color:"#454545",opacity:1,margin:0,display:"block"},children:"Server Address"}),l.jsx("input",{type:"text",value:b,onChange:M=>g(M.target.value),placeholder:"sftp://234.124.12.34:4432/data/sync",style:{width:352,height:42,boxSizing:"border-box",borderRadius:"6px",padding:"12px",border:"1px solid #F1F1F1",background:"#FFFFFF",opacity:1,fontSize:14,fontFamily:"Inter, sans-serif"}})]}),l.jsxs(P,{sx:{width:352,height:64,gap:"4px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx("label",{style:{width:352,height:18,fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"18px",letterSpacing:"0px",color:"#454545",opacity:1,margin:0,display:"block"},children:"Username"}),l.jsx("input",{type:"text",value:f,onChange:M=>m(M.target.value),placeholder:"Enter username",style:{width:352,height:42,boxSizing:"border-box",borderRadius:"6px",padding:"12px",border:"1px solid #F1F1F1",background:"#FFFFFF",opacity:1,fontSize:14,fontFamily:"Inter, sans-serif"}})]}),l.jsxs(P,{sx:{width:352,height:64,gap:"4px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box",position:"relative"},children:[l.jsx("label",{style:{width:352,height:18,fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"18px",letterSpacing:"0px",color:"#454545",opacity:1,margin:0,display:"block"},children:"Password"}),l.jsx("input",{type:p?"text":"password",value:S,onChange:M=>C(M.target.value),placeholder:"Enter password",style:{width:352,height:42,boxSizing:"border-box",borderRadius:"6px",padding:"12px 44px 12px 12px",border:"1px solid #F1F1F1",background:"#FFFFFF",opacity:1,fontSize:14,fontFamily:"Inter, sans-serif"}}),l.jsx(yt,{"aria-label":"toggle password visibility",onClick:()=>h(M=>!M),tabIndex:-1,size:"small",sx:{position:"absolute",right:11,top:35,color:"#454545",width:16,height:16,padding:0,display:"flex",alignItems:"center",justifyContent:"center","&:hover":{backgroundColor:"rgba(0,0,0,0.04)",color:"#222"},"& .MuiSvgIcon-root":{width:16,height:16,fontSize:16}},children:p?l.jsx(iN,{}):l.jsx(oN,{})})]})]}),l.jsxs(P,{sx:{display:"flex",justifyContent:"flex-end",gap:2,marginTop:"auto"},children:[l.jsx(Xe,{variant:"outlined",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",bgcolor:"#fff"},onClick:e.onBack,children:"Back"}),l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none"},onClick:L,disabled:v,children:v?"Loading...":"Next"})]}),w&&l.jsx(j,{color:"error",sx:{mt:1,fontSize:14},children:"Fill the credentials"})]})})]})})},dN=e=>e.productSettings.ftpColumns||[],pN=e=>e.productSettings.preview||[],uN=e=>e.productSettings.loading,fN=e=>e.productSettings.error,hN=e=>e.productSettings.existingMapping,gN=e=>e.productSettings.entity_type||"products",mN=e=>{const{mapping:t=[],onBack:n,onNext:r,stepperProps:i={}}=e,s=Et(),a=It(),c=s.state?.fromSettingsIcon,[d,u]=z.useState(()=>{if(s.state?.putjson)return s.state.putjson;const N=window.localStorage.getItem("ftpSyncPutjson");return N?JSON.parse(N):t.length>0?{mappings:t}:null}),[p,h]=z.useState([]),[y,b]=z.useState({}),g=Je(dN),f=Je(pN),m=Je(uN),S=Je(fN),C=Je(hN),x=Je(gN),v=z.useRef(m);z.useEffect(()=>{m&&!v.current&&queueMicrotask(()=>b({})),v.current=m},[m]);const w=z.useRef(!1);z.useLayoutEffect(()=>{C==null||!C?.mappings||C.mappings.length===0?w.current||(w.current=!0,queueMicrotask(()=>b({}))):w.current=!1},[C]);const A=on();z.useEffect(()=>{async function N(){try{let $=[];if(C?.mappings?.length>0){const k=C.mappings.map(V=>V.target_field).filter(V=>V&&typeof V=="string");$=[...new Set(k)]}try{const k=await A(Ko(x));Ko.fulfilled.match(k)&&Array.isArray(k.payload)&&k.payload.filter(B=>B&&typeof B=="string").forEach(B=>{$.includes(B)||$.push(B)})}catch{}if(t&&t.length>0){const k=t.map(V=>V.target_field).filter(V=>V&&typeof V=="string"&&!$.includes(V));k.length>0&&($=[...$,...k])}$=$.filter(k=>k&&typeof k=="string"),h($)}catch{if(C?.mappings?.length>0){const $=C.mappings.map(V=>V.target_field).filter(V=>V&&typeof V=="string"),k=[...new Set($)];h(k)}else h([])}}(x||C?.mappings?.length>0||t&&t.length>0)&&N()},[x,C,t,A]);const O=z.useMemo(()=>{if(C?.mappings&&C.mappings.length>0){const N=C.mappings.map($=>$.source_field).filter($=>$);if(N.length>0)return N}return g&&g.length>0?g:[]},[C,g]),L=z.useMemo(()=>f.filter($=>Object.keys($).length>0),[f]),M=z.useMemo(()=>{if(C?.mappings&&C.mappings.length>0){const N={};return C.mappings.forEach($=>{$.source_field&&$.target_field&&(N[$.source_field]=$.target_field)}),N}return{}},[C]),I=C?.mappings?.length>0?{...M,...y}:{...y},T=vn();ht(T.breakpoints.up("lg"));const F=Je(N=>N.productSettings.syncData),D=z.useMemo(()=>{if(F?.serverAddress)return F.serverAddress;const N=F?.configs||{},$=(F?.type||"sftp").toLowerCase(),k=N.host,V=N.port,B=N.path;if(!k)return"";let W=`${$}://${k}`;if(V!=null&&V!==""&&(W+=`:${V}`),B){const q=String(B).replace(/^\/+/,"");W+=`/${q}`}return W},[F]),U=()=>{const N=O.map(B=>({source_field:B||"",target_field:I[B]||""})).filter(B=>B.source_field&&B.target_field);if(N.length===0)return;if(c&&d){const B={...d,tenantId:d.tenantId||d.companyId,type:d.type||F.type||"sftp",entity_type:d.entity_type||F.entity_type||"products",mappings:N};u(B),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),r?r({fromSettingsIcon:!0,putjson:B}):e.onNext&&e.onNext({fromSettingsIcon:!0,putjson:B});return}const $=JSON.parse(window.localStorage.getItem("ftpSyncPutjson")||"{}"),k=F.companyId||$.companyId||$.tenantId||"",V={...$,companyId:k,tenantId:k,type:F.type||$.type||"sftp",integration_type:F.integration_type||$.integration_type||"",entity_type:$.entity_type||F.entity_type||"products",configs:F.configs||$.configs||{},ftp_columns:O,preview:L,mappings:N};A(zs(V)),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(V)),r?r({putjson:V}):e.onNext&&e.onNext({putjson:V})};return l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,mx:"auto",pt:2,display:"flex",flexDirection:"column",gap:"32px"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...i})}),l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:300,mb:4},children:l.jsxs(cn,{elevation:0,sx:{mt:0,p:0,borderRadius:4,width:"100%",maxWidth:800},children:[l.jsxs(P,{sx:{p:3,pb:2,borderBottom:"1px solid #eee",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(P,{children:[l.jsx(j,{variant:"subtitle1",sx:{fontWeight:700},children:"Map data from FTP to AiraOps"}),D&&l.jsx(j,{variant:"body2",sx:{color:"#888",mt:.5},children:D})]}),l.jsxs(P,{children:[l.jsx(Xe,{variant:"outlined",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",mr:2},onClick:n||(()=>a("/products/settings/ftp-sync",{state:{step:1}})),children:"Back"}),l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none"},onClick:U,children:"Next"})]})]}),l.jsx(jm,{sx:{background:"#fafafa",borderRadius:4,mt:0,boxShadow:"none",border:"1px solid #eee"},children:m?l.jsx(P,{sx:{p:3,textAlign:"center"},children:"Loading..."}):S?l.jsx(P,{sx:{p:3,color:"red",textAlign:"center"},children:S}):O.length===0?l.jsx(P,{sx:{p:3,textAlign:"center",color:"#888"},children:"No columns available. Please check your FTP connection and try again."}):l.jsxs(zm,{size:"small",children:[l.jsxs(Vm,{children:[l.jsxs(Vi,{children:[l.jsx(ir,{sx:{fontWeight:700,background:"#fafafa",borderBottom:"none",minWidth:120},children:"Columns in FTP"}),O.map((N,$)=>l.jsx(ir,{sx:{fontWeight:700,background:"#fafafa",borderBottom:"none",minWidth:120},children:N},N+$))]}),l.jsxs(Vi,{children:[l.jsx(ir,{sx:{fontWeight:700,background:"#fafafa",borderBottom:"none"},children:"Columns in Aira"}),O.map((N,$)=>l.jsx(ir,{sx:{background:"#fafafa",borderBottom:"none"},children:l.jsxs(Pn,{value:I[N]||"",onChange:k=>b(V=>({...V,[N]:k.target.value})),variant:"standard",disableUnderline:!0,displayEmpty:!0,sx:{minWidth:120,fontWeight:500},MenuProps:{PaperProps:{sx:{maxHeight:300,boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)","& .MuiList-root":{padding:"0"},"& .MuiMenuItem-root":{padding:"8px 16px",minHeight:"auto",fontSize:"14px",lineHeight:"1.5",margin:0},"& .MuiMenuItem-root:first-of-type":{marginTop:0}}},anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},MenuListProps:{sx:{padding:0}}},children:[l.jsx(We,{value:"",sx:{padding:"8px 16px",minHeight:"auto",fontSize:"14px",margin:0},children:l.jsx("em",{style:{fontStyle:"normal",color:"#888"},children:"Select column"})}),p.map(k=>l.jsx(We,{value:k,sx:{padding:"8px 16px",minHeight:"auto",fontSize:"14px",margin:0},children:k},k))]})},$))]})]}),l.jsx(Bm,{children:L.length>0?L.map((N,$)=>l.jsxs(Vi,{children:[l.jsx(ir,{sx:{fontWeight:700,background:"#fff",borderBottom:"none"},children:$===0?"Data preview":""}),O.map((k,V)=>l.jsx(ir,{sx:{background:"#fff",borderBottom:"none"},children:N[k]||""},V))]},$)):l.jsx(Vi,{children:l.jsx(ir,{colSpan:O.length+1,sx:{textAlign:"center",color:"#888",py:2},children:"No preview data available"})})})]})})]})})]})})},yN=e=>e.dashboard?.companyId||"",bN=e=>e.dashboard?.integrationData||null,xN=e=>{const{syncFrequency:t="",syncTime:n="",stepperProps:r={}}=e,i=Et(),s=It(),a=on(),c=Je(yN),d=Je(bN),u=i.state?.fromSettingsIcon,[p,h]=z.useState(()=>{if(i.state?.putjson){const k=JSON.parse(JSON.stringify(i.state.putjson));return k.mappings&&(k.originalMappings=JSON.parse(JSON.stringify(k.mappings))),k.configs?.sync_frequency&&!k.originalSyncFrequency&&(k.originalSyncFrequency=k.configs.sync_frequency),k.configs?.sync_time&&!k.originalSyncTime&&(k.originalSyncTime=k.configs.sync_time),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(k)),k}const $=window.localStorage.getItem("ftpSyncPutjson");if($){const k=JSON.parse($);return k.mappings&&!k.originalMappings&&(k.originalMappings=JSON.parse(JSON.stringify(k.mappings))),k.configs?.sync_frequency&&!k.originalSyncFrequency&&(k.originalSyncFrequency=k.configs.sync_frequency),k.configs?.sync_time&&!k.originalSyncTime&&(k.originalSyncTime=k.configs.sync_time),k}return null});z.useEffect(()=>{p&&window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(p))},[p]);const[y,b]=z.useState(null),[g,f]=z.useState(null);z.useEffect(()=>{const $=i.state?.fromProductSetting;let k=null;if($&&i.state?.integrationData)k=i.state.integrationData;else if(d&&Object.keys(d).length>0)k=d;else if(c&&!$){a(zt(c)).then(V=>{if(zt.fulfilled.match(V)){const B=V.payload;if(k=B&&B.data&&B.data[0]||null,k){b(k);const W=k.id||k.channelId||null;W&&f(W)}}});return}if(k){b(k);const V=k.id||k.channelId||null;V&&f(V)}},[c,i.state,d,a]);const m=!!u||!!y,S=$=>{if(!$)return"";const k=$.charAt(0).toUpperCase()+$.slice(1).toLowerCase();return k==="Daily"||k==="Day"?"Daily":k==="Weekly"||k==="Week"?"Weekly":k==="Monthly"||k==="Month"?"Monthly":k},[C,x]=z.useState(()=>{if(t)return S(t);const $=p?.configs?.sync_frequency?S(p.configs.sync_frequency):"";return $||"Daily"}),[v,w]=z.useState(n||p&&p.configs?.sync_time||"");z.useEffect(()=>{async function $(){if(c)try{const k=i.state?.fromProductSetting;let V=null;if(k&&i.state?.integrationData)V=i.state.integrationData;else if(d&&Object.keys(d).length>0)V=d;else{const B=await a(zt(c));if(zt.fulfilled.match(B)){const W=B.payload;V=W&&W.data&&W.data[0]||null}}if(V){const B=V.id||V.channelId||null;B&&f(B);const W=p||JSON.parse(window.localStorage.getItem("ftpSyncPutjson")||"null"),q={...V,companyId:V.companyId||c,entity_type:V.entity_type||W?.entity_type||"product",mappings:V.mappings||W?.mappings||[]},X=V.configs?.sync_frequency||"",G=V.configs?.sync_time||"",Q=S(X);if(h(q),k){if(t){const ee=S(t);x(ee)}n&&w(n),h(ee=>({...ee,...q,originalSyncFrequency:t?S(t):ee.originalSyncFrequency||Q,originalSyncTime:n||ee.originalSyncTime||G,configs:{...q.configs,sync_frequency:t?S(t).toLowerCase():q.configs?.sync_frequency,sync_time:n||q.configs?.sync_time}}))}else{const ee=t?S(t):"";if(ee)x(ee);else if(Q)x(Q);else if(W?.configs?.sync_frequency){const oe=S(W.configs.sync_frequency);x(oe)}else x("Daily");n?w(n):G?w(G):W?.configs?.sync_time?w(W.configs.sync_time):w(""),h(q),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(q))}}}catch{const k=JSON.parse(window.localStorage.getItem("ftpSyncPutjson")||"null");!t&&k?.configs?.sync_frequency?x(S(k.configs.sync_frequency)):t&&x(S(t)),!n&&k?.configs?.sync_time?w(k.configs.sync_time):n&&w(n)}}$()},[c]),z.useEffect(()=>{if(t){const $=S(t);x($),p&&p.configs?.sync_frequency!==$&&h(k=>{const V={...k,configs:{...k.configs,sync_frequency:$}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(V)),V})}},[t]),z.useEffect(()=>{n&&(w(n),p&&p.configs?.sync_time!==n&&h($=>{const k={...$,configs:{...$.configs,sync_time:n}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(k)),k}))},[n]),z.useEffect(()=>{if(p&&m&&(C||v)){const $=p.configs?.sync_frequency,k=p.configs?.sync_time;($!==C||k!==v)&&h(V=>{const B={...V,configs:{...V.configs,sync_frequency:C||V.configs?.sync_frequency,sync_time:v||V.configs?.sync_time}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),B})}},[C,v,m]);const A=Je($=>$.productSettings.syncData),O=$=>{const k=$.target.value;x(k),p&&h(V=>{const B={...V,configs:{...V.configs,sync_frequency:k}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),B}),m||a(zs({...A,configs:{...A&&A.configs||{},sync_frequency:k,sync_time:v}}))},L=$=>{const k=$.target.value;w(k),p&&h(V=>{const B={...V,configs:{...V.configs,sync_time:k}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),B}),m||a(zs({...A,configs:{...A&&A.configs||{},sync_frequency:C,sync_time:k}}))};function M($){try{const k=new URL($);return{type:k.protocol.replace(":",""),host:k.hostname,port:k.port,path:k.pathname}}catch{return{type:"",host:"",port:"",path:""}}}const[_,I]=z.useState(!1),[T,F]=z.useState(""),D=async()=>{const $=i.state?.fromProductSetting;if(m){if(!p){F("Update failed: missing data."),I(!0);return}let H={...p};p.originalMappings||(H.originalMappings=p.mappings?JSON.parse(JSON.stringify(p.mappings)):[],h(H)),!p.originalSyncFrequency&&p.configs?.sync_frequency&&(H.originalSyncFrequency=p.configs.sync_frequency||"",h(H)),!p.originalSyncTime&&p.configs?.sync_time&&(H.originalSyncTime=p.configs.sync_time||"",h(H));const he=JSON.parse(JSON.stringify(p.mappings||[])),de=JSON.parse(JSON.stringify(p.originalMappings||[]));let ge,ze;$?(ge=t?S(t):"",ze=n||""):(ge=p.originalSyncFrequency||p.configs?.sync_frequency||"",ze=p.originalSyncTime||p.configs?.sync_time||"",ge=S(ge));const Ee=$?!1:JSON.stringify(he)!==JSON.stringify(de),me=C!==ge,De=v!==ze,Le=(me||De)&&!Ee,Ne=Ee;if(Le){const pe=g||p?.id||p?.channelId||i.state?.integrationData?.id||i.state?.integrationData?.channelId;if(!pe){F("Channel ID is missing. Please try again."),I(!0);return}const Ve={configs:{}};me&&(Ve.configs.sync_frequency=C.toLowerCase()),De&&(Ve.configs.sync_time=v);try{const Ie=await a(Go({channelId:pe,data:Ve}));if(Ie.error||Go.rejected.match(Ie)){const xe=Ie.payload||Ie.error?.message||"Update failed. Please try again.";F(xe),I(!0);return}let se="";me&&!De?se="SyncFrequency Updated":!me&&De?se="SyncTime Updated":me&&De&&(se="SyncTime and SyncFrequency Updated"),F(se),I(!0),h(xe=>{const Z={...xe,configs:{...xe.configs,sync_frequency:C.toLowerCase(),sync_time:v},originalSyncFrequency:C,originalSyncTime:v};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(Z)),Z});const ne=i.state?.fromProductSetting;ne&&c&&await a(zt(c)),setTimeout(()=>{ne&&s("/product-setting",{state:{tenantIntegrationMatched:!0}})},1500);return}catch(Ie){const se=Ie?.message||Ie?.response?.data?.message||"Update failed. Please try again.";F(se),I(!0);return}}if(Ne){const pe={...p,configs:{...p.configs,sync_frequency:C.toLowerCase(),sync_time:v}};h(pe),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(pe));const Ve=pe.tenantId||pe.companyId;if(!pe.configs){F("Configuration error. Please try again."),I(!0);return}const Ie=pe.entity_type||p?.entity_type;if(!Ie){F("Entity type is missing. Please try again."),I(!0);return}const se={tenantId:Ve,type:pe.type,entity_type:Ie,configs:{host:pe.configs.host||"",port:pe.configs.port?Number(pe.configs.port):0,username:pe.configs.username||"",password:pe.configs.password||"",path:pe.configs.path||"",sync_frequency:C.toLowerCase()||"",sync_time:v||""},mappings:(pe.mappings||[]).map(ne=>({source_field:ne.source_field,target_field:ne.target_field}))};if(!se.tenantId){F("Tenant ID is missing. Please try again."),I(!0);return}if(!se.type){F("Sync type is missing. Please try again."),I(!0);return}if(!se.entity_type){F("Entity type is missing. Please try again."),I(!0);return}try{const ne=await a(jr(se));if(jr.rejected.match(ne)){const xe=ne.payload||ne.error?.message||"Update failed. Please try again.";F(xe),I(!0);return}jr.fulfilled.match(ne)?(h(xe=>{const Z={...xe,originalSyncFrequency:C,originalSyncTime:v,originalMappings:JSON.parse(JSON.stringify(xe.mappings||[]))};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(Z)),Z}),F("Sync Update Successfully"),I(!0),setTimeout(()=>{s("/product-setting",{state:{tenantIntegrationMatched:!0}})},1500)):(F("Update failed. Please try again."),I(!0))}catch(ne){const xe=ne?.message||ne?.response?.data?.message||"Update failed. Please try again.";F(xe),I(!0)}}else F("No changes detected."),I(!0);return}const k=A.configs||{},V=M(A.serverAddress||""),B=k.host||V.host,W=k.port!=null?Number(k.port):parseInt(V.port,10),q=(k.path||V.path||"").replace(/^\//,""),X=A.type||V.type||"sftp",G=A.username||k.username||"",Q=A.password||k.password||"",ee=C||k.sync_frequency||"",oe=typeof ee=="string"?ee.toLowerCase():ee;let le=v||k.sync_time||"";if(typeof le=="string"&&/^\d{1,2}:\d{2}\s*[AP]M$/i.test(le.trim())){const[H,he]=le.trim().split(/\s+/),[de,ge]=H.split(":").map(Number),ze=he.toUpperCase()==="PM"&&de!==12?de+12:he.toUpperCase()==="AM"&&de===12?0:de;le=`${String(ze).padStart(2,"0")}:${String(ge).padStart(2,"0")}`}else typeof le=="string"&&(le=le.trim());const ae=(A.mappings||[]).filter(H=>H.source_field&&H.target_field).map(H=>({source_field:H.source_field,target_field:H.target_field}));if(!c){F("Company ID is required. Please ensure the app is properly configured."),I(!0);return}if(!B||!W||!G||!Q||ae.length===0){F("Please fill all required fields and mappings before saving."),I(!0);return}const re=A.entity_type||"products",ce={tenantId:c,type:X,entity_type:re,configs:{host:B,port:Number(W),username:G,password:Q,path:q,sync_frequency:oe,sync_time:le},mappings:ae};try{const H=await a(qo(ce));qo.fulfilled.match(H)?(F("Save and Start Sync Updated Successfully"),I(!0),e.onNext&&e.onNext()):(F(H?.payload||"Save failed. Please try again."),I(!0))}catch{F("Save failed. Please try again."),I(!0)}},[U,N]=z.useState(!1);return z.useEffect(()=>{const $=setTimeout(()=>N(!0),850);return()=>clearTimeout($)},[]),l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,mx:"auto",pt:2,display:"flex",flexDirection:"column",gap:"32px"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...r,showStartSyncBlueTick:U})}),l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:380,bgcolor:"#fff",borderRadius:2,boxShadow:"0 2px 12px #0001"},children:l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:180,mt:4,mb:4},children:l.jsxs(cn,{elevation:0,sx:{p:2.5,borderRadius:4,minWidth:300,maxWidth:340,width:1,display:"flex",flexDirection:"column",alignItems:"center",bgcolor:"#f5f5f5"},children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"row",gap:2,width:"100%",mb:2},children:[l.jsxs(P,{sx:{flex:1},children:[l.jsx(j,{variant:"subtitle2",sx:{mb:1,fontSize:14,color:"#222"},children:"Sync Frequency"}),l.jsxs(Pn,{size:"small",value:C,onChange:O,sx:{minWidth:120,borderRadius:2,background:"#fafbfc",fontSize:15,height:40},children:[l.jsx(We,{value:"Daily",children:"Daily"}),l.jsx(We,{value:"Weekly",children:"Weekly"}),l.jsx(We,{value:"Monthly",children:"Monthly"})]})]}),l.jsxs(P,{sx:{flex:1},children:[l.jsx(j,{variant:"subtitle2",sx:{mb:1,fontSize:14,color:"#222"},children:"Sync Time"}),l.jsx(Ui,{type:"time",size:"small",value:v,onChange:L,sx:{minWidth:80,borderRadius:2,background:"#fafbfc",fontSize:15,height:36},InputLabelProps:{shrink:!0},inputProps:{step:300}})]})]}),l.jsxs(P,{sx:{display:"flex",justifyContent:"center",gap:.5,mt:1,width:"100%"},children:[l.jsx(Xe,{variant:"outlined",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",mr:2},onClick:e.onBack,children:"Back"}),l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none",flex:m?1:"initial"},onClick:D,children:m&&(i.state?.fromSyncSetting||i.state?.editMode)?"Save":m?"Update Sync":"Save and Start Sync"})]}),l.jsx(go,{open:_,autoHideDuration:4e3,onClose:()=>I(!1),message:T,anchorOrigin:{vertical:"top",horizontal:"center"}})]})})})]})})},vN=e=>{const{stepperProps:t={}}=e,n=on(),i=!!Je(d=>d.productSettings.saveResult),[s,a]=z.useState(i),c=It();return z.useEffect(()=>{i&&(a(!0),n(S1()))},[i,n]),l.jsxs(l.Fragment,{children:[l.jsx(go,{open:s,autoHideDuration:4e3,onClose:()=>a(!1),message:"Sync setup successful!",anchorOrigin:{vertical:"top",horizontal:"center"}}),l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,mx:"auto",pt:2,display:"flex",flexDirection:"column",gap:"32px"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...t})}),l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:380,bgcolor:"#fff",borderRadius:2,boxShadow:"0 2px 12px #0001"},children:l.jsxs(P,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:320,py:6,bgcolor:"#f5f5f5",borderRadius:5},children:[l.jsx(P,{sx:{width:48,height:48,borderRadius:"50%",background:"#2563eb",display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:l.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",children:l.jsx("path",{d:"M7 12.5L11 16L17 9.5",stroke:"#fff",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}),l.jsx(j,{sx:{fontSize:17,color:"#222",mb:1,fontWeight:500},children:"Sync Setup Successfully"}),l.jsx(Xe,{variant:"text",sx:{color:"#2563eb",fontWeight:500,fontSize:15,textTransform:"none",mt:1},onClick:()=>c("/"),children:"Back to all products"})]})})]})}),l.jsx(go,{open:s,autoHideDuration:4e3,onClose:()=>a(!1),message:"Integration saved & sync started",anchorOrigin:{vertical:"top",horizontal:"center"}})]})};function SN(e){const t=Et(),n=It(),r=t.state?.fromProductSetting?3:0,[i,s]=z.useState(r),a=on(),{companyId:c,integrationData:d}=Je(O=>O.dashboard),u=t.state?.fromSyncStep;z.useEffect(()=>{const O=t.state?.fromProductSetting;c&&!O&&a(zt(c))},[c,a,t.state]);const p=()=>{s(O=>Math.min(O+1,4))},h=z.useCallback(()=>{if(i===0&&u!==void 0){n("/product-setting",{state:{fromSyncStep:u,tenantIntegrationMatched:u===3}});return}if(t.state?.fromProductSetting&&i===3){n("/product-setting",{state:{tenantIntegrationMatched:!0}});return}s(O=>Math.max(O-1,0))},[i,u,t.state?.fromProductSetting,n]),y=z.useMemo(()=>[{label:"Products",to:"/products"},{label:"Settings",to:"/product-setting"},{label:"FTP Sync",to:"/products/settings/ftp-sync"}],[]),b=z.useMemo(()=>[{label:"Products",to:"/products"},{label:"Settings",to:"/product-setting"}],[]),{setSettingTopbarProps:g}=Yi()||{};z.useEffect(()=>{if(g)return g({onBack:h,breadcrumbs:i===0||i===1?y:b}),()=>g({})},[g,h,i,y,b]);const f=d?.configs||{},m=d?.mappings||d?.dataMappings||[],C=(O=>{if(!O)return"";const L=O.charAt(0).toUpperCase()+O.slice(1).toLowerCase();return L==="Daily"||L==="Day"?"Daily":L==="Weekly"||L==="Week"?"Weekly":L==="Monthly"||L==="Month"?"Monthly":L})(d?.configs?.sync_frequency||""),x=d?.configs?.sync_time||"",v=["Setup FTP","Check data","Start Sync"],w=["Upload File","Check data","Start Sync"],A={0:{steps:v,activeStep:0,showCheckDataBlueTick:!1,progressToCheckData:!1,showSetupFtpBlueTick:!1,showStartSyncBlueTick:!1},1:{steps:v,activeStep:0,showCheckDataBlueTick:!1,progressToCheckData:!1,showSetupFtpBlueTick:!1,filledSegments:.5},2:{steps:v,activeStep:1,showCheckDataBlueTick:!0,progressToCheckData:!0,showSetupFtpBlueTick:!0,filledSegmentsStart:.5,filledSegments:1},3:{steps:w,activeStep:2,showCheckDataBlueTick:!0,progressToCheckData:!1,showSetupFtpBlueTick:!0,showStartSyncBlueTick:!1,filledSegmentsStart:1,filledSegments:2,previousStepsComplete:!0},4:{steps:w,activeStep:2,showCheckDataBlueTick:!0,progressToCheckData:!0,showSetupFtpBlueTick:!0,showStartSyncBlueTick:!0,instantComplete:!0}};switch(i){case 0:return l.jsx(rN,{onNext:p,onBack:h,stepperProps:A[0],...e});case 1:return l.jsx(cN,{onNext:p,onBack:h,ftpDetails:f,stepperProps:A[1],...e});case 2:return l.jsx(mN,{onNext:p,onBack:h,mapping:m,stepperProps:A[2],...e});case 3:return l.jsx(xN,{onNext:p,onBack:h,syncFrequency:C,syncTime:x,stepperProps:A[3],...e});case 4:return l.jsx(vN,{onBack:h,stepperProps:A[4],...e});default:return null}}const wN=it(l.jsx("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2m6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56M12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96M4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56m2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8M12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96M14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2m.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56M16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2z"}),"Language");function CN(e){return l.jsx(P,{sx:{width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",opacity:1,...e.sx},children:l.jsx(P,{component:"span",sx:{width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",opacity:1},children:l.jsx(wN,{sx:{color:"#808080"}})})})}const EN="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAAUlJREFUeAGNUrttwzAQFfWrnS6VIGsCjyAB+rWZIM4EyQZ2Jog2UDJCOkESYGaC2BOIZcr0+uVdYBqyQMM+gCB5997x3R2ZNjPf913LsnI6Yr23bfvKORdTjD4BL+I4fgPhexzHr6qqGPaDbdu7KIpySnZGgvPZNM0GIIbMy7qut+THnum6HuDIkIzIa/Izyg4wXQJk32sXLE1Tt+/7HY7C8DyvYIz94HLvOM5BCPGrqhOYHGuB6+pfXlmWS6mfXpb6Z3V+Eu6sEVI/gnekn8CzOjOJNacyiqIQ2NZH/c2xTj6XqytqlmR6naviStI1I9I+SZKXW8Coc4MOCtMwjIeu63IaMIp+UkkKw9AHeDMMg4bmBEwGaNoUAJHTf0MHG+oa/UP4XRBOCZki6xatfwSZBioA/oCSDJ/2NHSm0k4txysrtJ1PwdL+AHzhuHE1We3IAAAAAElFTkSuQmCC";function TN({sx:e={},...t}){const n=e?.fontSize??12,r=e?.width??n,i=e?.height??n;return l.jsx(P,{component:"img",src:EN,alt:"",role:"presentation",sx:{width:r,height:i,display:"block",objectFit:"contain",...e},...t})}const AN="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAANCAYAAACdKY9CAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAAPtJREFUeAGlUUsOgjAQpSWQuLJHQC6gR4DwCe70Bt5Ab6CewCPIEVwSQmKPoDt3uHQnrPn5SjRpTIkLJ2k6bd+b92ZKNCkcx7EMwzh2XTcjhBRYcZqmexlD5QPAZ2zXuq4nuq67IC58399pqsCDg3X+UmRBEDyVCqjGKKWlohZTEpqm4SBNRR+fO9M019himUDkA+RXIB2gJMgMTVvI3SRJ7kqCiCiKrKqq+illWca1f6NXCMNw27btBlXZAO6Ctz3+5EQEWMwbNlzOeaFCe563AOGIdKnbth3jk+bw+xiykef5DbgRSDMxVkuewqB3QgRmTN/Jz0CPwm75AifwYTaKH5pyAAAAAElFTkSuQmCC",kN={fontSize:10.67,color:"#454545"};function PN({sx:e={},...t}){const n={...kN,...e},r=n.fontSize??10.67,i=n.width??r,s=n.height??r;return l.jsx(P,{component:"img",src:AN,alt:"",role:"presentation",sx:{width:i,height:s,display:"block",objectFit:"contain",...n},...t})}const ON=it(l.jsx("path",{d:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3m3-10H5V5h10z"}),"Save");function IN(e){return l.jsx(ON,{...e})}const NN=it(l.jsx("path",{d:"m14.06 9.02.92.92L5.92 19H5v-.92zM17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"}),"EditOutlined");function FN(e){return l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",...e.sx},children:l.jsx(P,{component:"span",sx:{width:13.22,height:13.22,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(NN,{})})})}const MN=it(l.jsx("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM8 9h8v10H8zm7.5-5-1-1h-5l-1 1H5v2h14V4z"}),"DeleteOutline");function DN(e){return l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",...e.sx},children:l.jsx(P,{component:"span",sx:{width:12,height:13.33,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(MN,{})})})}function _N(e){const{catalogs:t=[],totalCount:n=0,page:r=0,rowsPerPage:i=10,statusById:s={},getStatus:a,onPageChange:c,onRowsPerPageChange:d,onSave:u,onDelete:p,onStatusChange:h,updateCatalogError:y=null,updateCatalogLoading:b=!1}=e,[g,f]=z.useState(null),[m,S]=z.useState({name:"",slug:"",status:!0}),C=_=>{const I=_.slugRaw??(typeof _.slug=="string"?_.slug.replace(/^\//,""):"")??"",T=_.status==="Active"||_.status===!0;f(_.id),S({name:_.name??"",slug:I,status:T})},x=async _=>{if(typeof u!="function")return;const I=m.slug.trim().replace(/^\//,""),T={id:_.id,name:m.name.trim(),slug:I||m.name.trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),status:m.status};await u(T),f(null)},v=()=>{f(null)},w=t,A=Math.max(0,Number(n)||0),O=Math.max(0,Math.ceil(A/Math.max(1,i))-1),L={borderRadius:"4px",padding:"2px 4px",background:"#F5F5F5",display:"inline-flex",alignItems:"center",gap:"4px"},M={wrapper:{width:800,maxWidth:"100%",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:"40px",opacity:1,marginLeft:"auto",marginRight:"auto",paddingLeft:"24px",mt:2},resultsPerPageBox:{width:128,height:16,display:"flex",alignItems:"center",gap:"4px",opacity:1},resultsPerPageText:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545",whiteSpace:"nowrap"},select:{minWidth:32,height:16,"& .MuiSelect-select":{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545",py:0,pr:"20px !important",display:"flex",alignItems:"center"},"& .MuiSelect-icon":{top:"50%",transform:"translateY(-50%)"},"& .MuiSvgIcon-root":{width:16,height:16,right:0,color:"#454545"}},navBox:{width:200,height:16,display:"flex",alignItems:"center",gap:"16px",opacity:1},iconButton:{p:0,width:16,height:16,color:"#454545","&.Mui-disabled":{color:"#c0c0c0"}},pageText:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"}};return l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa"},children:l.jsxs(P,{sx:{width:600,maxWidth:"100%",minHeight:606,pt:2,mx:"auto",pb:4,display:"flex",flexDirection:"column",gap:"24px",opacity:1},children:[l.jsx(P,{sx:{width:"100%",maxWidth:600,height:20,display:"flex",alignItems:"center",gap:"24px",opacity:1},children:l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"6px",height:20,opacity:1},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"14px",lineHeight:"20px",letterSpacing:0,color:"#000000",opacity:1},children:"All Catalogs"}),l.jsx(j,{component:"span",sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#808080",opacity:1},children:n})]})}),y&&l.jsx(j,{color:"error",sx:{mb:0},children:y}),l.jsx(P,{sx:{display:"flex",flexDirection:"column",gap:"8px"},children:w.map(_=>{const I=g===_.id,T=typeof a=="function"?a(_):s[_.id]??_.status??"Active",F=T==="Active";return l.jsxs(cn,{elevation:0,sx:{width:"100%",maxWidth:600,minHeight:106,borderRadius:"12px",border:"1px solid #F1F1F1",padding:"12px 16px",background:"#FFFFFF",display:"flex",alignItems:"flex-start",gap:"16px",opacity:1},children:[l.jsx(P,{sx:{flexShrink:0},children:l.jsx(CN,{})}),l.jsx(P,{sx:{width:368,maxWidth:"100%",minWidth:0,flex:1,display:"flex",flexDirection:"column",gap:"8px",opacity:1},children:I?l.jsxs(l.Fragment,{children:[l.jsx(Ui,{label:"Name",size:"small",value:m.name,onChange:D=>S(U=>({...U,name:D.target.value})),fullWidth:!0,sx:{"& .MuiInputBase-root":{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px"}}}),l.jsx(Ui,{label:"Slug",size:"small",value:m.slug,onChange:D=>S(U=>({...U,slug:D.target.value})),fullWidth:!0,placeholder:"/catalog-slug"})]}):l.jsxs(l.Fragment,{children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"2px"},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#000000",opacity:1},children:_.name}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#808080",opacity:1},children:_.slug})]}),l.jsx(P,{sx:{display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap"},children:l.jsxs(P,{sx:L,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(TN,{sx:{fontSize:12,color:"#454545"}})}),l.jsxs(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"},children:[_.productsCount," Products"]})]})}),l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap"},children:[l.jsxs(P,{sx:L,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(PN,{})}),l.jsxs(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"},children:["By ",_.createdBy]})]}),l.jsxs(P,{sx:L,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(cy,{size:12,color:"#454545"})}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"},children:_.date})]})]})]})}),l.jsx(P,{sx:{flexShrink:0},children:I?l.jsxs(Pn,{size:"small",value:m.status?"Active":"Inactive",onChange:D=>S(U=>({...U,status:D.target.value==="Active"})),IconComponent:Nr,sx:{minWidth:80,height:24,borderRadius:"4px",padding:"6px 6px 6px 8px",background:m.status?"#D8FBE3":"#F5F5F5",fontFamily:"Inter, sans-serif",fontWeight:500,fontSize:"10px",lineHeight:"12px",color:"#454545","& .MuiSelect-select":{py:.75},"& .MuiSelect-icon":{width:12,height:12,top:"50%",transform:"translateY(-50%)"}},children:[l.jsx(We,{value:"Active",children:"Active"}),l.jsx(We,{value:"Inactive",children:"Inactive"})]}):l.jsxs(Pn,{value:T,onChange:D=>{if(typeof h!="function"||b)return;const U=D.target.value==="Active";h(_,U)},disabled:b,IconComponent:Nr,sx:{minWidth:80,height:24,borderRadius:"4px",padding:"6px 6px 6px 8px",background:F?"#D8FBE3":"#F5F5F5",fontFamily:"Inter, sans-serif",fontWeight:500,fontSize:"10px",lineHeight:"12px",color:"#454545","& .MuiSelect-select":{py:.75},"& .MuiSelect-icon":{width:12,height:12,top:"50%",transform:"translateY(-50%)"},"& .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}},variant:"outlined",children:[l.jsx(We,{value:"Active",children:"Active"}),l.jsx(We,{value:"Inactive",children:"Inactive"})]})}),l.jsx(P,{sx:{flexShrink:0},children:I?l.jsxs(l.Fragment,{children:[l.jsx(yt,{size:"small","aria-label":"Save catalog",disabled:b,onClick:()=>x(_),sx:{p:0,color:"#454545"},children:l.jsx(IN,{sx:{fontSize:20}})}),l.jsx(Xe,{size:"small",onClick:v,sx:{minWidth:0,px:1,ml:.5},children:"Cancel"})]}):l.jsx(yt,{size:"small","aria-label":"Edit catalog",onClick:()=>C(_),sx:{p:0,width:16,height:16},children:l.jsx(FN,{})})}),l.jsx(P,{sx:{flexShrink:0},children:l.jsx(yt,{size:"small","aria-label":"Delete catalog",onClick:()=>typeof p=="function"?p(_):null,sx:{p:0,width:16,height:16},children:l.jsx(DN,{})})})]},_.id)})}),l.jsxs(P,{sx:M.wrapper,children:[l.jsxs(P,{sx:M.resultsPerPageBox,children:[l.jsx(j,{component:"span",sx:M.resultsPerPageText,children:"Results per page"}),l.jsxs(Pn,{value:i,onChange:_=>typeof d=="function"?d(_):null,IconComponent:Nr,variant:"standard",disableUnderline:!0,sx:M.select,children:[l.jsx(We,{value:5,children:"5"}),l.jsx(We,{value:10,children:"10"}),l.jsx(We,{value:25,children:"25"})]})]}),l.jsxs(P,{sx:M.navBox,children:[l.jsx(yt,{size:"small",disabled:r===0,onClick:()=>typeof c=="function"?c(0):null,sx:M.iconButton,"aria-label":"First page",children:l.jsx(Jd,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:r===0,onClick:()=>typeof c=="function"?c(Math.max(0,r-1)):null,sx:M.iconButton,"aria-label":"Previous page",children:l.jsx(Hi,{sx:{width:16,height:16,opacity:1}})}),l.jsx(j,{component:"span",sx:M.pageText,children:A===0?"0-0 of 0":`${r*i+1}-${Math.min((r+1)*i,A)} of ${A}`}),l.jsx(yt,{size:"small",disabled:r>=O,onClick:()=>typeof c=="function"?c(r+1):null,sx:M.iconButton,"aria-label":"Next page",children:l.jsx(Ot,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:r>=O,onClick:()=>typeof c=="function"?c(O):null,sx:M.iconButton,"aria-label":"Last page",children:l.jsx(Qd,{sx:{width:16,height:16,opacity:1}})})]})]})]})})}const $N=({isOpen:e,onClose:t,onConfirm:n,catalogName:r})=>{const s=On().productSettingModal;return l.jsx(ao,{open:e,onClose:t,"aria-labelledby":"delete-catalog-modal",sx:s.modal,children:l.jsxs(P,{sx:s.container,children:[l.jsx(P,{sx:s.header,children:l.jsxs(j,{sx:{...s.headerTitle,fontSize:22},children:["Are you sure you want to delete this catalog",r?` "${r}"`:"","?"]})}),l.jsxs(P,{sx:{...s.footer,flexDirection:"row",gap:2,justifyContent:"center"},children:[l.jsx(Xe,{variant:"contained",color:"primary",onClick:n,sx:{minWidth:100,mx:4},children:"Yes"}),l.jsx(Xe,{variant:"outlined",color:"primary",onClick:t,sx:{minWidth:100},children:"No"})]})]})})};function zN(e){if(!e)return"";const t=new Date(e),n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return`${t.getDate()} ${n[t.getMonth()]} ${t.getFullYear()}`}function LN(e){if(!e)return null;const t=e.slug,n=typeof t=="string"&&t.startsWith("/")?t:`/${t||""}`;return{...e,slug:n,slugRaw:typeof t=="string"?t.replace(/^\//,""):t||"",productsCount:e.productCount??e.productsCount??0,createdBy:e.createdByName??e.createdBy??"",date:zN(e.createdAt??e.date),createdAt:e.createdAt??e.date,status:e.status===!0?"Active":e.status===!1?"Inactive":e.status||"Active"}}function BN(e){const t=It(),n=on(),{sharedCatalogues:r=[],sharedCataloguesTotal:i=0,sharedCataloguesLoading:s=!1,sharedCataloguesError:a=null}=Je(V=>V.productSettings??{}),{updateCatalogLoading:c=!1,updateCatalogError:d=null}=Je(V=>V.dashboard??{}),[u,p]=z.useState(0),[h,y]=z.useState(10),[b,g]=z.useState({}),[f,m]=z.useState(!1),[S,C]=z.useState(null),[x,v]=z.useState(!1),[w,A]=z.useState("");z.useEffect(()=>{n(Yt({page:u+1,limit:h}))},[n,u,h]),z.useEffect(()=>()=>n({type:"dashboard/clearUpdateCatalogError"}),[n]);const O=z.useMemo(()=>Array.isArray(r)?r.map(LN).filter(Boolean):[],[r]),L=i,M=V=>p(V),_=V=>{const B=Number(V.target.value);y(B),p(0)},I=V=>b[V.id]??V.status,T=z.useCallback(()=>t(-1),[t]),{setSettingTopbarProps:F}=Yi()||{};z.useEffect(()=>{if(F)return F({onBack:T}),()=>F({})},[F,T]);const D=async V=>{const{id:B,name:W,slug:q,status:X}=V;await n(Ho({id:B,name:W,slug:q,status:X})).unwrap(),n(Yt({page:u+1,limit:h}))},U=async(V,B)=>{const W=V.slugRaw??(typeof V.slug=="string"?V.slug.replace(/^\//,""):"")??"";g(q=>({...q,[V.id]:B?"Active":"Inactive"}));try{await n(Ho({id:V.id,name:V.name??"",slug:W,status:B})).unwrap(),n(Yt({page:u+1,limit:h}))}catch{g(q=>({...q,[V.id]:V.status}))}},N=V=>{C(V),m(!0)},$=()=>{m(!1),C(null)},k=async()=>{if(!S?.id){$();return}try{await n(_s(S.id)).unwrap(),A("Catalog delete Successfully"),v(!0),$(),n(Yt({page:u+1,limit:h}))}catch{A("Failed to delete catalog"),v(!0)}};return s&&O.length===0?l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa"},children:l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"60vh"},children:l.jsx(mi,{})})}):a&&O.length===0?l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa"},children:l.jsx(P,{sx:{textAlign:"center",py:4},children:l.jsx(j,{color:"error",children:a})})}):l.jsxs(l.Fragment,{children:[l.jsx(_N,{catalogs:O,totalCount:L,page:u,rowsPerPage:h,statusById:b,getStatus:I,onBack:T,onPageChange:M,onRowsPerPageChange:_,onStatusChange:U,onSave:D,onDelete:N,updateCatalogError:d,updateCatalogLoading:c,...e}),l.jsx($N,{isOpen:f,onClose:$,onConfirm:k,catalogName:S?.name}),l.jsx(go,{open:x,autoHideDuration:4e3,onClose:()=>v(!1),message:w,anchorOrigin:{vertical:"top",horizontal:"center"}})]})}const cl=it(l.jsx("path",{d:"M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"}),"ErrorOutline"),jN=it([l.jsx("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"},"0"),l.jsx("path",{d:"M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"},"1")],"AccessTime");function ep(e){return l.jsx(jN,{...e})}function WN({styles:e={},selectedProducts:t=[],data:n,onSelectProduct:r,categoryName:i,showLimitedColumns:s=!1,pagination:a=null,onPageChange:c,onLimitChange:d}){const u=e?.categoryTableAllStore??{},p=e?.categoryTableSingleStore??{},h=e?.categoryTablePagination??{},y=e?.categoryTableShared??{},b=ht("(max-width:900px)"),g=ht("(max-width:400px)"),f=ht("(max-width:550px)"),m=ht("(max-width:770px)"),S=ht("(max-width:650px)"),C=ht("(max-width:500px)"),x=ht("(max-width:400px)"),v=!s,w=v&&m,A=N=>t.some($=>$.id===N.id),[O,L]=z.useState(null),[M,_]=z.useState([]),I=(N,$)=>{L(N.currentTarget),_($)},T=()=>{L(null),_([])},F=!!O,D=v?p.outerCard:u.outerCard,U=v?"6px":"4px";return l.jsx(or,{maxWidth:!1,sx:e.categoryTableContainer,children:l.jsxs(La,{sx:{...e.categoryTable,...D},children:[l.jsx(P,{sx:{...u.categoryNameBox,display:"flex",alignItems:"center",mb:U,boxSizing:"border-box",overflow:"hidden"},children:l.jsx(j,{sx:{...u.categoryNameText,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})}),!(v&&!g)&&l.jsxs(P,{sx:{display:"flex",flexWrap:g&&v?"wrap":"nowrap",alignItems:"center",width:"100%",minWidth:0,...v?p.tableHeader:u.tableHeader,boxSizing:"border-box",gap:g?"8px":v&&b?"12px":"16px"},children:[s?l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",flexShrink:0},children:l.jsx(bt,{checked:n.length>0&&n.every(A),indeterminate:n.some(A)&&!n.every(A),onChange:()=>{n.every(A)?n.forEach(N=>r(N,i,!1)):n.forEach(N=>{A(N)||r(N,i,!0)})},size:"small",sx:y.checkboxHeaderSx,icon:l.jsx("span",{style:y.checkboxIconSpanHeader}),checkedIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})}),indeterminateIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})})})}),l.jsx(P,{sx:{display:"flex",alignItems:"center",minWidth:0,flex:"1 1 0"},children:l.jsx(j,{component:"span",sx:u.headerProduct,children:"Product"})})]}):l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:g?"8px":b?"12px":"16px",flex:"1 1 0",minWidth:0,...v&&!g&&{maxWidth:"40%"}},children:[l.jsx(bt,{checked:n.length>0&&n.every(A),indeterminate:n.some(A)&&!n.every(A),onChange:()=>{n.every(A)?n.forEach(N=>r(N,i,!1)):n.forEach(N=>{A(N)||r(N,i,!0)})},size:"small",sx:y.checkboxHeaderSx,icon:l.jsx("span",{style:y.checkboxIconSpanHeader}),checkedIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})}),indeterminateIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})})}),l.jsx(j,{component:"span",sx:{...p.headerLabel,...p.headerProduct},children:"Product"})]}),!g&&(v?l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{...p.headerStatus,display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0,flex:"0 1 auto"},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Status"})}),l.jsx(P,{sx:{...p.headerPrice,display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0,flex:"0 1 auto"},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Price"})}),l.jsx(P,{sx:{...p.headerStock,display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0,flex:"0 1 auto"},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Stock"})}),l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"12px",minWidth:0,flex:"0 1 auto",...p.headerOffer},children:[l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Offer"}),l.jsx(ol,{sx:{...u.arrowDown,fontSize:12,marginTop:"8px"}})]})]}):l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",flexShrink:0,mr:1,minWidth:64},children:l.jsx(j,{component:"span",sx:u.headerStatusText,children:"Status"})}),!f&&l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",flexShrink:0,mr:2,minWidth:88},children:l.jsx(j,{component:"span",sx:u.headerOsaText,children:"Stock / OSA"})}),l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",flexShrink:0,mr:0,width:20,minWidth:20},children:l.jsx(ol,{sx:{...u.arrowDownAllStore}})})]})]}))]}),(function(){const N=v&&!g,$=n.map((k,V)=>{let B=[];k.offers&&Array.isArray(k.offers)?B=k.offers:k.offer&&typeof k.offer=="string"&&k.offer.includes(`
1580
+ `},VI=({selectedProducts:e,selectedDesign:t,sheetSize:n,itemsToShow:r,copyPerItem:i=1})=>{if(!e||e.length===0){alert("No products selected for printing");return}const s=window.open("","_blank","width=800,height=600");if(!s){alert("Please allow popups to print promo designs");return}const a=i>0?i:1,c=[];e.forEach(h=>{for(let y=0;y<a;y++)c.push(h)});const d={A4:jI,A7:WI},p=(d[n]||d.A4)({selectedProducts:c,selectedDesign:t,itemsToShow:r});try{s.document.open(),s.document.write(p),s.document.close()}catch(h){console.error("Error writing to print window:",h),alert("Error generating print preview. Please check console for details.")}},sl=l.jsx("span",{style:{display:"inline-block",width:16,height:16,borderRadius:4,border:"0.5px solid #454545",background:"#FFFFFF"}}),al=l.jsx("span",{style:{display:"inline-block",width:16,height:16,borderRadius:4,border:"0.5px solid #2563EB",background:"#FFFFFF",position:"relative"},children:l.jsx("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:l.jsx("path",{d:"M11.6667 3.5L5.25 9.91667L2.33334 7",stroke:"#2563EB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),UI=()=>{const e=new Date,t=e.getFullYear(),n=e.getMonth()+1,r=e.getDate();return{validTo:`${t}-${String(n).padStart(2,"0")}-${String(r).padStart(2,"0")}`,ppd:`${r}/${n}/${t}`}},ly=({open:e,onClose:t,selectedProducts:n=[]})=>{const r=On(),i=z.useMemo(()=>UI(),[]),[s,a]=z.useState({productName:!0,mrp:!0,percentOff:!0,discountPrice:!0}),[c,d]=z.useState("design1"),[u,p]=z.useState(""),[h,y]=z.useState(1),[b,g]=z.useState(!1),[f,m]=z.useState(!1),S=v=>a(w=>({...w,[v]:!w[v]})),C=()=>{if(!n||n.length===0){m(!0);return}if(!u){g(!0);return}g(!1);const v=h>0?h:1;VI({selectedProducts:n,selectedDesign:c,sheetSize:u,itemsToShow:s,copyPerItem:v}),t()};z.useEffect(()=>{(e&&n&&n.length>0||!e)&&queueMicrotask(()=>m(!1))},[e,n]);const x=r.promoPrintModal;return l.jsxs(lo,{open:e,onClose:t,maxWidth:!1,PaperProps:{sx:x.dialog},BackdropProps:{sx:{backdropFilter:"blur(4px)",backgroundColor:"rgba(0, 0, 0, 0.3)"}},children:[l.jsx(co,{sx:{p:0},children:l.jsxs(P,{sx:x.header,children:[l.jsx(j,{sx:x.headerTitle,children:"Promo Print"}),l.jsx(P,{component:"button",onClick:t,sx:x.crossIconCard,"aria-label":"Close",children:l.jsx(oy,{sx:{fontSize:16,color:"#454545"}})})]})}),l.jsx(Oi,{sx:x.content,children:l.jsxs(P,{sx:x.middleCard,children:[l.jsxs(P,{sx:x.itemsToShowSection,children:[l.jsx(j,{sx:x.sectionTitle,children:"Items to show"}),l.jsxs(P,{sx:x.checkboxRow,children:[l.jsx(kn,{control:l.jsx(bt,{checked:s.productName,onChange:()=>S("productName"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"Product Name",sx:x.checkboxLabel}),l.jsx(kn,{control:l.jsx(bt,{checked:s.percentOff,onChange:()=>S("percentOff"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"Percent OFF",sx:x.checkboxLabel}),l.jsx(kn,{control:l.jsx(bt,{checked:s.mrp,onChange:()=>S("mrp"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"MRP",sx:x.checkboxLabel}),l.jsx(kn,{control:l.jsx(bt,{checked:s.discountPrice,onChange:()=>S("discountPrice"),size:"small",sx:x.checkboxSx,icon:sl,checkedIcon:al}),label:"Discount Price",sx:x.checkboxLabel})]})]}),l.jsxs(P,{sx:x.designSection,children:[l.jsx(j,{sx:x.sectionTitle,children:"Promo Design"}),l.jsxs(P,{sx:x.designContainer,children:[l.jsxs(P,{onClick:()=>d("design1"),sx:{...x.designCard.base,...c==="design1"?x.designCard.selected:x.designCard.unselected},children:[l.jsx(j,{sx:{...x.design1.ourPriceHeader,visibility:s.discountPrice?"visible":"hidden"},children:"SAVE"}),l.jsx(P,{sx:{width:"100%",display:"flex",justifyContent:"center",visibility:s.discountPrice?"visible":"hidden"},children:l.jsxs(P,{sx:{display:"inline-flex",alignItems:"baseline"},children:[l.jsx(j,{component:"span",sx:{...x.design1.rupeeSymbol},children:"₹"}),l.jsx(j,{component:"span",sx:{...x.design1.bigPrice},children:"1387"})]})}),l.jsxs(P,{sx:{...x.design1.bottomInfo,visibility:s.discountPrice||s.mrp?"visible":"hidden"},children:[l.jsxs(j,{sx:{...x.design1.saveAmount,visibility:s.discountPrice?"visible":"hidden"},children:["OUR PRICE: ",l.jsx(j,{component:"span",sx:x.design1.rupeeSymbolSmall,children:"₹"}),"73"]}),l.jsxs(j,{sx:{...x.design1.mrpAmount,visibility:s.mrp?"visible":"hidden"},children:["MRP: ",l.jsx(j,{component:"span",sx:x.design1.rupeeSymbolSmall,children:"₹"}),"1460"]})]}),l.jsx(j,{sx:{...x.design1.productName,visibility:s.productName?"visible":"hidden"},children:"NESCAFE CLASSIC 500g COFFEE BIB"}),l.jsxs(P,{sx:x.design1.dateRow,children:[l.jsxs(j,{sx:x.design1.validFromText,children:["VALID TO: ",i.validTo]}),l.jsxs(j,{sx:x.design1.validToText,children:["PPD: ",i.ppd]})]})]}),l.jsxs(P,{onClick:()=>d("design2"),sx:{...x.designCard.base,...c==="design2"?x.designCard.selected:x.designCard.unselected},children:[l.jsxs(P,{sx:x.design2.mainOfferBlock,children:[l.jsx(j,{sx:{...x.design2.offerLine,visibility:s.percentOff?"visible":"hidden"},children:"Buy 1PC @5.00% Off"}),l.jsx(j,{sx:{...x.design2.offerLine,visibility:s.percentOff?"visible":"hidden"},children:"Buy 2PC @5.00% Off"})]}),l.jsxs(j,{sx:{...x.design2.mrpBlock,visibility:s.mrp?"visible":"hidden"},children:["MRP:",l.jsx(j,{component:"span",sx:x.design2.rupeeSymbolSmall,children:"₹"}),"1460"]}),l.jsx(j,{sx:{...x.design2.productName,visibility:s.productName?"visible":"hidden"},children:"NESCAFE CLASSIC 500G COFFEE BIB"}),l.jsxs(P,{sx:x.design2.dateRow,children:[l.jsxs(j,{sx:x.design2.validFromText,children:["(Valid till: ",i.validTo,")"]}),l.jsxs(j,{sx:x.design2.validToText,children:["(PPD: ",i.ppd,")"]})]})]}),l.jsxs(P,{onClick:()=>d("design3"),sx:{...x.designCard.base,...c==="design3"?x.designCard.selected:x.designCard.unselected},children:[l.jsx(j,{sx:{...x.design3.ourPriceHeader,visibility:s.discountPrice?"visible":"hidden"},children:"OUR PRICE"}),l.jsx(P,{sx:{width:"100%",display:"flex",justifyContent:"center",visibility:s.discountPrice?"visible":"hidden"},children:l.jsxs(P,{sx:{display:"inline-flex",alignItems:"baseline"},children:[l.jsx(j,{component:"span",sx:{...x.design3.rupeeSymbol},children:"₹"}),l.jsx(j,{component:"span",sx:{...x.design3.bigPrice},children:"29"})]})}),l.jsx(j,{sx:{...x.design3.productName,visibility:s.productName?"visible":"hidden"},children:"POTATO BIG KG"}),l.jsxs(P,{sx:x.design3.dateRow,children:[l.jsxs(j,{sx:x.design3.validFromText,children:["[ValidTo: ",i.validTo,"]"]}),l.jsxs(j,{sx:x.design3.validToText,children:["[PPD: ",i.ppd,"]"]})]})]}),l.jsxs(P,{onClick:()=>d("design4"),sx:{...x.designCard.base,...c==="design4"?x.designCard.selected:x.designCard.unselected},children:[l.jsx(j,{sx:{...x.design4.ourPriceHeader,visibility:s.discountPrice?"visible":"hidden"},children:"OUR PRICE"}),l.jsx(P,{sx:{width:"100%",display:"flex",justifyContent:"center",visibility:s.discountPrice?"visible":"hidden"},children:l.jsxs(P,{sx:{display:"inline-flex",alignItems:"baseline"},children:[l.jsx(j,{component:"span",sx:{...x.design4.rupeeSymbol},children:"₹"}),l.jsx(j,{component:"span",sx:{...x.design4.priceWhole},children:"899"}),l.jsx(j,{component:"span",sx:{...x.design4.priceDecimal},children:".70"})]})}),l.jsxs(P,{sx:{...x.design4.saveMrpRow,visibility:s.discountPrice||s.mrp?"visible":"hidden"},children:[l.jsxs(j,{sx:{...x.design4.saveAmount,visibility:s.discountPrice?"visible":"hidden"},children:["SAVE: ",l.jsx(j,{component:"span",sx:x.design4.rupeeSymbolSmall,children:"₹"}),"2099.30"]}),l.jsxs(j,{sx:{...x.design4.mrpAmount,visibility:s.mrp?"visible":"hidden"},children:["MRP:",l.jsx(j,{component:"span",sx:x.design4.rupeeSymbolSmall,children:"₹"}),"2999"]})]}),l.jsx(j,{sx:{...x.design4.productCode,visibility:s.productName?"visible":"hidden"},children:"MCS-SWE-CP-SO-RG-XXL-1402A5-PuLa"}),l.jsxs(P,{sx:x.design4.dateRow,children:[l.jsxs(j,{sx:x.design4.validFromText,children:["[VALIDITY: ",i.validTo,"]"]}),l.jsxs(j,{sx:x.design4.validToText,children:["[PPID: ",i.ppd,"]"]})]})]}),l.jsxs(P,{onClick:()=>d("design5"),sx:{...x.designCard.base,...c==="design5"?x.designCard.selected:x.designCard.unselected},children:[l.jsxs(P,{sx:x.design5.topSection,children:[l.jsxs(P,{sx:x.design5.leftColumn,children:[l.jsxs(P,{sx:x.design5.rewardsLogo,children:[l.jsxs(P,{sx:x.design5.logoLine1,children:[l.jsx(j,{sx:x.design5.logoMy,children:"My"}),l.jsx(j,{sx:x.design5.logoSpencer,children:"spencers"})]}),l.jsxs(j,{sx:x.design5.logoRewards,children:["Rewa",l.jsx(j,{component:"span",sx:x.design5.rupeeSymbol1,children:"₹"}),"ds"]})]}),l.jsxs(j,{sx:{...x.design5.memberPriceLabel,visibility:s.discountPrice?"visible":"hidden"},children:["MEMBER",l.jsx("br",{}),"PRICE"]}),l.jsxs(j,{sx:{...x.design5.memberPriceValue,visibility:s.discountPrice?"visible":"hidden"},children:[l.jsx(j,{component:"span",sx:x.design5.rupeeSymbol,children:"₹"}),"99"]})]}),l.jsx(P,{sx:x.design5.verticalDivider}),l.jsxs(P,{sx:x.design5.rightColumn,children:[l.jsxs(j,{sx:{...x.design5.nonMemberPriceLabel,visibility:s.discountPrice?"visible":"hidden"},children:["NON",l.jsx("br",{}),"MEMBER",l.jsx("br",{}),"PRICE"]}),l.jsxs(j,{sx:{...x.design5.nonMemberPriceValue,visibility:s.discountPrice?"visible":"hidden"},children:[l.jsx(j,{component:"span",sx:x.design5.rupeeSymbol,children:"₹"}),"116"]})]})]}),l.jsxs(P,{sx:x.design5.middleSection,children:[l.jsx(j,{sx:{...x.design5.productName,visibility:s.productName?"visible":"hidden"},children:"MAGGI 2-MINUTE MASALA NOODLES 560G"}),l.jsxs(j,{sx:{...x.design5.mrpText,visibility:s.mrp?"visible":"hidden"},children:["MRP ",l.jsx(j,{component:"span",sx:x.design5.rupeeSymbolSmall,children:"₹"}),"120"]})]}),l.jsx(P,{sx:x.design5.horizontalDivider}),l.jsx(P,{sx:x.design5.bottomSection,children:l.jsx(j,{sx:x.design5.savingsMessage,children:"SAVE UPTO 6% EXTRA MONTHLY WITH MY SPENCERS REWARDS"})})]})]})]}),l.jsxs(P,{sx:x.sheetSizeSection,children:[l.jsx(j,{sx:x.sheetSizeHeader,children:"Sheet Size"}),l.jsxs(P,{sx:x.sheetSizeRow,children:[l.jsx(P,{sx:x.sheetSizeGroup,children:["A4","A7"].map(v=>l.jsx(P,{onClick:()=>{p(v),g(!1)},sx:{...x.sheetSizeBtn,...u===v?x.sheetSizeBtnSelected:{}},children:l.jsx(j,{sx:u===v?{...x.sheetSizeBtnText,...x.sheetSizeBtnTextSelected}:x.sheetSizeBtnText,children:v})},v))}),l.jsxs(P,{sx:x.copyPerItemRow,children:[l.jsx(j,{sx:x.copyPerItemLabel,children:"Enter Copy per item:"}),l.jsx(Ui,{type:"number",value:h,onChange:v=>{const w=parseInt(v.target.value,10);!isNaN(w)&&w>0?y(w):v.target.value===""&&y(1)},inputProps:{min:1,style:{padding:"4px 8px",textAlign:"center",width:"60px"}},sx:{"& .MuiOutlinedInput-root":{height:28,width:"80px",bgcolor:"#F5F5F5"},"& .MuiOutlinedInput-input":{padding:"4px 8px",fontSize:"12px"}},size:"small"})]})]})]})]})}),l.jsxs(yd,{sx:{...x.actions,flexDirection:"column",alignItems:"flex-start"},children:[b&&l.jsx(j,{variant:"body2",sx:{color:"red",mb:.5},children:"Please select a sheet size."}),f&&l.jsx(j,{variant:"body2",sx:{color:"red",mb:.5},children:"No products selected. Please select products first."}),l.jsx(P,{sx:{...x.printButtonWrapper,alignSelf:"stretch",display:"flex",justifyContent:"flex-end"},children:l.jsx(Xe,{type:"button",onClick:C,variant:"contained",sx:x.printButton,children:"Print"})})]})]})},HI=it([l.jsx("path",{d:"M17.59 18 19 16.59 14.42 12 19 7.41 17.59 6l-6 6z"},"0"),l.jsx("path",{d:"m11 18 1.41-1.41L7.83 12l4.58-4.59L11 6l-6 6z"},"1")],"KeyboardDoubleArrowLeft");function Jd(e){return l.jsx(HI,{...e})}const RI=it([l.jsx("path",{d:"M6.41 6 5 7.41 9.58 12 5 16.59 6.41 18l6-6z"},"0"),l.jsx("path",{d:"m13 6-1.41 1.41L16.17 12l-4.58 4.59L13 18l6-6z"},"1")],"KeyboardDoubleArrowRight");function Qd(e){return l.jsx(RI,{...e})}const qI=()=>{const e=on(),t=It(),n=Et(),r=On(),i=n.state?.catalogCreated&&n.state?.catalogSlug?{catalogSlug:n.state.catalogSlug}:null,s=()=>{t(n.pathname,{replace:!0,state:{}})},a=r.categoryDetail,[c,d]=z.useState({category:"all",status:"all",search:"",store:[]}),{integrationData:u,companyId:p,loading:h,categoriesLoading:y,categoriesFetchSettled:b,error:g}=Je(Z=>Z.dashboard),f=z.useMemo(()=>u&&typeof u=="object"&&Object.keys(u).length>0?{matched:!0,error:"",apiResponse:u,loading:!1}:{matched:!1,error:"No active integration found",apiResponse:null,loading:!1},[u]),m=Je(Z=>Z.dashboard),{categoryList:S=[],stores:C=[],categoryPagination:x={}}=m||{},v=S,{currentPage:w=1,limit:A=10,totalCount:O=0,totalPages:L=1,hasNextPage:M=!1}=x,{sharedCatalogues:_=[],sharedCataloguesTotal:I=0,lastStableActiveCatalogsCount:T=null}=Je(Z=>Z.productSettings??{}),F=z.useMemo(()=>Array.isArray(_)?_.filter(Z=>Z.status===!0).length:0,[_]),U=I>0&&_.length>=I?F:T??F,N=Array.isArray(S)&&S.length>0,$=()=>{f.matched?t("/product-setting",{state:{tenantIntegrationMatched:!0}}):t("/product-setting",{state:{tenantIntegrationMatched:!1}})},k=z.useMemo(()=>C.length>0?C:[{id:"all",name:"All Stores",storeCode:"all"}],[C]),V=z.useCallback(Z=>{d(Z)},[d]),B=z.useCallback((Z={})=>{const fe=Array.isArray(c.store)?c.store:[],ye={...Z};if(fe.length>0&&!fe.includes("all")){const K=fe.map(ie=>C.find(ve=>ve.id===ie)?.storeCode).filter(Boolean);K.length>0&&(ye.storeCode=K[0])}return c.search!=null&&String(c.search).trim()!==""&&(ye.search=String(c.search).trim()),c.minOsa!=null&&c.minOsa!==""&&(ye.minOsa=c.minOsa),c.maxOsa!=null&&c.maxOsa!==""&&(ye.maxOsa=c.maxOsa),c.order!=null&&c.order!==""&&(ye.order=c.order),ye},[c.store,c.search,c.minOsa,c.maxOsa,c.order,C]),W=z.useRef(null);z.useEffect(()=>{if(!p)return;const Z=B({page:w,limit:A}),fe=JSON.stringify(Z);W.current!==fe&&(W.current=fe,e(Gn(Z)))},[p,w,A,B,e]);const q=Z=>{const fe=B({page:Z,limit:A});e(Gn(fe))},X=Z=>{const fe=B({page:1,limit:Z});e(Gn(fe))},[G,Q]=z.useState(!1);z.useEffect(()=>{!p&&!G?e(Vo()).finally(()=>{Q(!0)}):p&&queueMicrotask(()=>Q(!0))},[e,p,G]);const ee=z.useRef(null),oe=z.useRef(n.pathname),le=z.useRef(null);z.useEffect(()=>{p&&p!==ee.current&&(ee.current=p,e(zt(p)),e(Gn({page:1,limit:10})),e(Uo()),e(Wo()),e(Yt({page:1})))},[e,p]),z.useEffect(()=>{const Z=oe.current;oe.current=n.pathname;const fe=p&&n.pathname==="/"&&Z!=="/",ye=p&&n.pathname==="/"&&!!n.state?.catalogCreated;(fe||ye)&&(e(Yt({page:1})),e(Gn(B({page:w,limit:A}))),e(Wo()))},[n.pathname,n.state?.catalogCreated,p,e,B,w,A]),z.useEffect(()=>{if(!p||I<=0)return;(Array.isArray(_)?_.length:0)<I&&e(Yt({page:1,limit:I}))},[p,I,_?.length,e,_]);const[ae,re]=z.useState(Array.isArray(n.state?.selectedCategories)?n.state.selectedCategories:[]),[ce,H]=z.useState(Array.isArray(n.state?.selectedProducts)?n.state.selectedProducts:[]),he=Z=>{t(`/category?categoryName=${encodeURIComponent(Z.name||Z.categoryName)}`,{state:{filters:c,selectedCategories:ae,selectedProducts:ce}})},[de,ge]=z.useState(!1),[ze,Ee]=z.useState(!1),[me,De]=z.useState(!1),[Le,Ne]=z.useState([]),[,pe]=z.useState(!1),Ve=z.useCallback((Z,fe={})=>{const ye=Array.isArray(c.store)?c.store:[],K={page:1,limit:5e3,...fe};if(Z&&String(Z).trim()!==""&&(K.categoryName=String(Z).trim()),ye.length>0&&!ye.includes("all")){const ie=ye.map(ue=>C.find(je=>je.id===ue)?.storeCode).filter(Boolean);ie.length>0&&(K.storeCode=ie.join(","))}return c.search!=null&&String(c.search).trim()!==""&&(K.search=String(c.search).trim()),K},[c.store,c.search,C]),Ie=z.useCallback(async()=>{const Z=(Array.isArray(ae)?ae:[]).map(ie=>(ie?.categoryName??ie?.name??"").toString().trim()).filter(Boolean),fe=Array.isArray(ce)?ce:[],ye={};fe.forEach(ie=>{const ue=(ie?.categoryName??ie?.category??"").toString().trim();ue&&(ye[ue]||(ye[ue]=[]),ye[ue].push(ie))});const K=new Set(Object.keys(ye));if(Z.length===0&&fe.length===0){Ne([]),De(!0);return}pe(!0);try{const ie=[];for(const _e of Z){const Ye=ye[_e];if(Ye&&Ye.length>0)ie.push(Ye);else{const Se=Ve(_e),we=await e(Ms(Se)).unwrap().catch(()=>({})),Be=Array.isArray(we?.data)?we.data:Array.isArray(we?.products)?we.products:Array.isArray(we)?we:[];ie.push(Be)}}Z.forEach(_e=>K.delete(_e)),K.forEach(_e=>{ye[_e]?.length&&ie.push(ye[_e])});const ue=ie.flat().filter(Boolean),ve=new Set,je=ue.map(_e=>({..._e,catalogProductId:_e?.productId??_e?.catalogProductId??_e?.id,id:_e?.id||_e?.sku||_e?.productName})).filter(_e=>{const Ye=(_e?.productId||_e?.id||_e?.sku||_e?.productName||"").toString();return!Ye||ve.has(Ye)?!1:(ve.add(Ye),!0)});Ne(je),De(!0)}catch{Ne([]),De(!0)}finally{pe(!1)}},[e,ce,ae,Ve]),se=z.useCallback(Z=>{const fe=Z?.categoryName??Z?.name??"",ye=fe,K=Number(Z?.productCount??0);re(ie=>ie.some(ve=>(ve?.categoryName??ve?.name)===fe)?(H(ve=>{if(!Array.isArray(ve)||!ye)return ve||[];const je=ve.filter(Ye=>(Ye?.categoryName??Ye?.category??"").toString().trim()===ye);return K>0&&je.length>=K?ve.filter(Ye=>(Ye?.categoryName??Ye?.category??"").toString().trim()!==ye):ve}),ie.filter(ve=>(ve?.categoryName??ve?.name)!==fe)):[...ie,Z])},[]),ne=G&&g&&!p,{setTopbarProps:xe}=Yi()||{};return z.useEffect(()=>{if(xe)return ne?(xe({hide:!0}),()=>xe({})):(xe({filters:c,onFilterChange:V,styles:a.topBar,stores:k,tenantStatus:f,hasProducts:N}),()=>xe({}))},[xe,ne,c,V,a.topBar,k,f,N]),l.jsxs(l.Fragment,{children:[i&&l.jsx(SI,{catalogSlug:i.catalogSlug,onClose:s}),l.jsx(P,{sx:ne?{marginTop:0}:N?a.contentWrapper??{marginTop:0,display:"flex",flexDirection:"column",alignItems:"center"}:{marginTop:0},children:ne?l.jsx(Vd,{handleStartSyncing:$,loading:!1,sessionExpired:!0}):!G&&!p?l.jsx(mo,{text:"Fetching",fullScreen:!0}):y?l.jsx(mo,{text:"Fetching Categories",fullScreen:!0}):N?l.jsx(P,{sx:a.root,children:l.jsxs(or,{ref:le,maxWidth:"lg",sx:{px:{xs:1,sm:2,md:4}},children:[l.jsx(ey,{productState:m,categoryCount:S.length,activeCatalogsCount:U,onManageClick:()=>t("/catalogs/manage-shared")}),S.length>0?l.jsxs(l.Fragment,{children:[l.jsx(kI,{categoryData:v,styles:a,onView:he,selectedCategories:ae,onToggleCategory:se}),l.jsx(ry,{containerRef:le,selectedCategories:ae,selectedProducts:ce,onPromoPrint:Ie,onCreateCatalog:()=>ge(!0),onOsaRequest:()=>Ee(!0)}),l.jsx(ly,{open:me,onClose:()=>{De(!1),Ne([])},selectedProducts:Le},me?"open":"closed"),l.jsx(iy,{open:de,onClose:()=>ge(!1),stores:k,selectedProducts:ce,selectedCategories:ae,onCreateSuccess:Z=>{re([]),H([]),ge(!1),Z&&t("/",{state:{catalogCreated:!0,catalogSlug:Z}})}}),l.jsx(sy,{open:ze,onClose:()=>Ee(!1),stores:k,selectedProducts:ce,selectedCategories:ae.map(Z=>Z?.categoryName??Z?.name).filter(Boolean),onSuccess:()=>{re([]),H([])}}),O>0&&(()=>{const Z=a?.categoryTablePagination??{};return l.jsxs(P,{sx:{...Z.wrapper||{},width:"100%",marginLeft:"auto",marginRight:0},children:[l.jsxs(P,{sx:Z.resultsPerPageBox,children:[l.jsx(j,{component:"span",sx:Z.resultsPerPageText,children:"Results per page"}),l.jsx(Pn,{value:A,onChange:fe=>X(Number(fe.target.value)),IconComponent:Nr,variant:"standard",disableUnderline:!0,sx:Z.select,children:[5,10,20,50].map(fe=>l.jsx(We,{value:fe,children:fe},fe))})]}),l.jsxs(P,{sx:Z.navBox,children:[l.jsx(yt,{size:"small",disabled:w<=1,onClick:()=>q(1),sx:Z.iconButton,title:"First page",children:l.jsx(Jd,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:w<=1,onClick:()=>q(w-1),sx:Z.iconButton,title:"Previous page",children:l.jsx(Hi,{sx:{width:16,height:16,opacity:1}})}),l.jsx(j,{component:"span",sx:Z.pageText,children:O===0?"0 of 0":`${(w-1)*A+1}-${Math.min(w*A,O)} of ${O}`}),l.jsx(yt,{size:"small",disabled:!M||w>=L,onClick:()=>q(w+1),sx:Z.iconButton,title:"Next page",children:l.jsx(Ot,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:!M||w>=L,onClick:()=>q(L),sx:Z.iconButton,title:"Last page",children:l.jsx(Qd,{sx:{width:16,height:16,opacity:1}})})]})]})})()]}):l.jsxs(P,{sx:{minHeight:280,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",bgcolor:"#f5f7fa",borderRadius:2,p:3},children:[l.jsx(j,{sx:{fontSize:18,fontWeight:600,color:"#454545",mb:1},children:"No Category"}),l.jsx(j,{sx:{fontSize:14,color:"#808080"},children:c.search&&String(c.search).trim()?"No category found for your search.":"No category available."})]})]})}):l.jsx(Vd,{handleStartSyncing:$,loading:h||y||!b,sessionExpired:!1,hasIntegration:f.matched,showFetchingCategoriesLabel:!0,isHomeCategorySearch:!!(c.search&&String(c.search).trim()),isHomeCategorySearchEmpty:!!(c.search&&String(c.search).trim())&&b&&!y&&!h})})]})};function Fn({icon:e,title:t,subtitle:n,subtitleValue:r,onClick:i,selected:s,highlightStyle:a={},action:c,disabled:d=!1,customStyle:u={},titleColorWhenDisabled:p,titleColor:h,subtitleColor:y}){const b={width:"100%",maxWidth:"100%",height:58,boxSizing:"border-box",background:"#FFFFFF",borderRadius:2,boxShadow:"none",border:"1px solid #F1F1F1",display:"flex",alignItems:"center",gap:1.5,px:2,py:1.5,mb:0,cursor:i&&!d?"pointer":"default",opacity:d?.5:1,...s?a:{}},g=d?p||"#999999":h||"#000000",f=d?"#bbbbbb":y||"#808080",m={card:{...b,...u},cardInner:{display:"flex",alignItems:"center",flex:1,minWidth:0},icon:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,mr:2},title:{fontWeight:700,fontSize:12,color:g,lineHeight:"16px"},subtitle:{color:f,fontSize:12,fontWeight:400,mt:.5,lineHeight:"16px"}};return l.jsxs(P,{onClick:d?void 0:i,sx:{...m.card,...u||{}},children:[e&&l.jsx(P,{sx:m.icon,children:e}),l.jsxs(P,{sx:m.cardInner,children:[l.jsxs(P,{children:[l.jsx(j,{sx:m.title,children:t}),n&&l.jsx(j,{sx:m.subtitle,children:r?`${r} ${n}`:n})]}),c&&l.jsx(P,{sx:{ml:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:c})]})]})}function Zd({size:e=15,color:t="#454545",...n}){return l.jsx(gI,{size:e,color:t,...n})}const YI="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAASpJREFUeAGVUT1OhGAQ5b/2BPxewhISIHSyJ/AKlnbunsBsZenuCdQOgWQp7VY7C0i+0u2w00DAN2ZNYMOXyCSTGZh5897MJwgcC4Jg7/u+y6tLvELf92bXdeYsIDGJonimKMrFLCBAlwivYI1d1zX/BQzD8AYhlmV5AalrVVV3U2B5KM9xnHsCwb00Td8Nw3iRJOkcQ65R+9R1ncG+flXR9egQtBOcodFLkoQJ452vULs9rsHQv5Ityzrg4w1+wH+XilVVPQ+VINxh4AcAa+RPTdM8isPJURTRE+zQwLIs87BvjPyBGPI8X44OeLo0gdu23YNhQ1eFb09Bo+P8WVmWtW3b30iXkF+DeSFM2OQ7gnFDEbK3AscmgUVR1AgMQDYLeLSVpmkFr/gDCe+DRKwM0doAAAAASUVORK5CYII=",KI="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAAIpJREFUeAFVTsENwyAMxCkPnowQNmgnCB8Qv46QrtNfV+gG/YPUjtABeGSEDIAgPimJEkvnO9ln+YRYyzn38N5/xKG6gx5aa4O1Vm8DwgXzyLgyJoZm07uU8upYjETUY8H8Y4a+K6U04TyE0Ndav2zE4hZj/GN+Qcs5z8YYGFVK6bn9lLuQEklPaRdNCCms4XdYvwAAAABJRU5ErkJggg==";function GI(e){const{sx:t={},...n}=e;return l.jsxs(P,{sx:{width:20,height:20,opacity:1,position:"relative",flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",...t},...n,children:[l.jsx(P,{component:"img",src:YI,alt:"",sx:{position:"absolute",width:12.25,height:12.25,top:1.84,left:1.84,opacity:1,boxSizing:"border-box",objectFit:"contain",display:"block"}}),l.jsx(P,{component:"img",src:KI,alt:"",sx:{position:"absolute",width:5.104,height:5.104,top:13.06,left:13.06,opacity:1,boxSizing:"border-box",objectFit:"contain",display:"block"}})]})}function cy({size:e=15,color:t="#454545",...n}){return l.jsx(pI,{size:e,color:t,...n})}function XI({size:e=15,color:t="#454545",...n}){return l.jsx(fI,{size:e,color:t,...n})}function JI({size:e=15,color:t="#454545",...n}){return l.jsx(hI,{size:e,color:t,...n})}function QI({airaAiEnabled:e,setAiraAiEnabled:t,selectedCard:n,setSelectedCard:r,syncStep:i=0,syncMethod:s="",onSetupSync:a=()=>{},onSyncNow:c=()=>{},integrationData:d={},...u}){const p={bgcolor:"#F3F8FF",border:"1px solid #2D64B8"},h=It(),y=d?.configs?.sync_frequency||"Daily",b=d?.configs?.sync_time||"10:00 AM",g=d?.type||s||"FTP",f={width:"100%",maxWidth:900,minHeight:468,mx:"auto",mt:4,px:"20px",boxSizing:"border-box",display:"flex",flexDirection:"column",gap:3},m=()=>l.jsxs(P,{sx:{width:"100%",minHeight:156,display:"flex",flexDirection:"column",gap:1.5},children:[l.jsx(P,{sx:{width:"100%",height:20,display:"flex",alignItems:"center",justifyContent:"space-between"},children:l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"6px",width:67,height:20},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:14,lineHeight:"20px",color:"#000000"},children:"General"}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:12,lineHeight:"16px",color:"#808080"},children:"2"})]})}),l.jsxs(P,{sx:{width:"100%",minHeight:124,display:"flex",flexDirection:"column",gap:"4px"},children:[l.jsx(Fn,{icon:l.jsx(Zd,{size:15,color:"#454545"}),title:"Manage Shared Catalogs",onClick:()=>h("/catalogs/manage-shared"),selected:n==="catalogs",highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsx(Fn,{icon:l.jsx(GI,{}),title:"Aira AI",subtitle:"Make your workflows faster and smarter",onClick:()=>r&&r("aira-ai"),selected:n==="aira-ai",highlightStyle:p,action:l.jsx(P,{sx:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(_m,{checked:e,onChange:v=>t&&t(v.target.checked),size:"small"})})})]})]}),S=(v,w)=>l.jsxs(P,{sx:{width:"100%",height:20,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"6px",width:48,height:20},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:14,lineHeight:"20px",color:"#000000"},children:"Sync"}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:12,lineHeight:"16px",color:"#808080"},children:"2"})]}),l.jsxs(P,{sx:{width:78,height:16,display:"flex",alignItems:"center",gap:"4px",cursor:v?"not-allowed":"pointer",opacity:v?.5:1},onClick:v?void 0:w,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(Or,{sx:{width:14.66,height:12,color:"#2D64B8"}})}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:12,lineHeight:"16px",color:"#2D64B8",width:62},children:"Sync Now"})]})]}),C=v=>{const w=v?y:"Daily",A=v?b:"10:00 AM",O=!v&&i===0;return l.jsxs(P,{sx:{width:"100%",minHeight:288,display:"flex",flexDirection:"column",gap:"4px"},children:[S(O,c),!v&&i===0&&l.jsx(Fn,{icon:l.jsx(Or,{sx:{width:18.33,height:15,color:"#454545"}}),title:"Setup Sync",subtitle:"Sync products",onClick:a,highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),!v&&i===1&&l.jsxs(l.Fragment,{children:[l.jsx(Fn,{icon:l.jsx(Or,{sx:{width:18.33,height:15,color:"#454545"}}),title:"Sync Method",subtitle:g,highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsx(Fn,{icon:l.jsx(Zd,{size:15,color:"#454545"}),title:`Setup ${g} Details`,subtitle:"Start setup",onClick:()=>{h("/products/settings/ftp-sync",{state:{fromSyncStep:i}})},highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})]}),i===3&&l.jsxs(l.Fragment,{children:[l.jsx(Fn,{icon:l.jsx(Or,{sx:{width:18.33,height:15,color:"#454545"}}),title:"Sync Method",subtitle:s||"FTP",highlightStyle:p,disabled:!0,titleColorWhenDisabled:"#454545",action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsx(Fn,{icon:l.jsx(Zd,{size:15,color:"#454545"}),title:"FTP Details",subtitle:"Sync source",highlightStyle:p,onClick:()=>h("/products/settings/ftp-sync",{state:{fromSyncStep:i}}),action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})}),l.jsxs(P,{sx:{width:"100%",display:"flex",flexWrap:"nowrap",justifyContent:"space-between","@media (max-width:450px)":{flexDirection:"column",gap:"4px"}},children:[l.jsx(P,{sx:{width:"50%","@media (max-width:450px)":{width:"100%"}},children:l.jsx(Fn,{icon:l.jsx(cy,{size:15,color:"#454545"}),title:"Sync Frequency",subtitle:w,highlightStyle:p,customStyle:{mb:0},onClick:()=>h("/products/settings/ftp-sync",{state:{fromProductSetting:!0,fieldToEdit:"syncFrequency",integrationData:d}}),action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})}),l.jsx(P,{sx:{width:"50%","@media (max-width:450px)":{width:"100%"}},children:l.jsx(Fn,{icon:l.jsx(XI,{size:15,color:"#454545"}),title:"Sync Time",subtitle:A,highlightStyle:p,customStyle:{mb:0},onClick:()=>h("/products/settings/ftp-sync",{state:{fromProductSetting:!0,fieldToEdit:"syncTime",integrationData:d}}),action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})})]}),l.jsx(Fn,{icon:l.jsx(JI,{size:15,color:"#454545"}),title:"Sync History",subtitle:"12,139 items",highlightStyle:p,action:l.jsx(Ot,{sx:{width:16,height:16,color:"#454545"}})})]})]})},x=i===3&&d&&Object.keys(d||{}).length>0;return l.jsxs(P,{sx:f,children:[m(),C(x)]})}function ZI({open:e,onClose:t,onSave:n}){vn();const r=On(),[i,s]=z.useState("sftp"),a=[{value:"sftp",label:"SFTP"},{value:"webhook",label:"Webhook"},{value:"aira-api",label:"AIRA API"},{value:"file-upload",label:"File Upload"}],c=h=>s(h.target.value),d=()=>{n&&n(i),t()},u=()=>{},p=r.productSettingModal;return l.jsx(ao,{open:e,onClose:t,"aria-labelledby":"product-sync-setting-modal",sx:p.modal,children:l.jsxs(P,{sx:p.container,children:[l.jsxs(P,{sx:p.header,children:[l.jsx(j,{sx:p.headerTitle,children:"Sync Method"}),l.jsx(yt,{onClick:t,size:"small",sx:p.closeButton,children:l.jsx(mI,{size:20})})]}),l.jsxs(P,{sx:p.content,children:[l.jsx(Ya,{value:i,onChange:c,children:a.map(h=>l.jsx(kn,{value:h.value,control:l.jsx(fo,{icon:l.jsx(P,{sx:p.radioIcon}),checkedIcon:l.jsx(uI,{size:18,color:"#000"}),sx:p.radioChecked}),label:l.jsx(j,{sx:p.radioLabel,children:h.label}),sx:{...p.formControlLabel,...i===h.value&&{backgroundColor:"#F3F8FF"}}},h.value))}),l.jsxs(P,{sx:p.upgradeSection,children:[l.jsx(j,{sx:p.upgradeText,children:"Upgrade for higher sync limits and more features"}),l.jsx(j,{onClick:u,sx:p.managePlanLink,children:"Manage Plan >"})]})]}),l.jsx(P,{sx:p.footer,children:l.jsx(Xe,{fullWidth:!0,variant:"contained",onClick:d,sx:p.saveButton,children:"Save"})})]})})}const eN=({isOpen:e,onClose:t,onConfirm:n})=>{const r=On();let i;return i=r.productSettingModal,l.jsx(ao,{open:e,onClose:t,"aria-labelledby":"sync-now-modal",sx:i.modal,children:l.jsxs(P,{sx:i.container,children:[l.jsx(P,{sx:i.header,children:l.jsx(j,{sx:{...i.headerTitle,fontSize:22},children:"Are you sure to SyncNow ?"})}),l.jsxs(P,{sx:{...i.footer,flexDirection:"row",gap:2,justifyContent:"center"},children:[l.jsx(Xe,{variant:"contained",color:"primary",onClick:n,sx:{minWidth:100,mx:4},children:"Yes"}),l.jsx(Xe,{variant:"outlined",color:"primary",onClick:t,sx:{minWidth:100},children:"No"})]})]})})};function tN(){const e=Et(),t=It(),n=on(),{companyId:r,integrationData:i,loading:s}=Je(D=>D?.dashboard||{}),[a,c]=z.useState(!0),[d,u]=z.useState(),[p,h]=z.useState(0),[y,b]=z.useState(""),[g,f]=z.useState(!1),[m,S]=z.useState(!1),[C,x]=z.useState(!1),[v,w]=z.useState(""),A=z.useRef(null),O=z.useRef(!1);z.useEffect(()=>{const D=e.state?.tenantIntegrationMatched===!0;r&&r!==A.current&&!s&&(i&&(i?.id||i?.channelId||i?.configs||typeof i=="object"&&Object.keys(i).length>0)?A.current=r:(A.current=r,n(zt(r)))),D&&r&&!s&&!O.current&&(O.current=!0,n(zt(r))),D||(O.current=!1)},[r,n,s,i,e.state]),z.useEffect(()=>{let D=!1;e.state&&typeof e.state.tenantIntegrationMatched=="boolean"&&(D=e.state.tenantIntegrationMatched);const U=i&&(i?.id||i?.channelId||i?.configs||Array.isArray(i?.data)&&i.data.length>0||typeof i=="object"&&Object.keys(i).length>0),N=e.state?.fromSyncStep===1?1:D===!0||U?3:0;queueMicrotask(()=>h(N))},[e.state,i]);const L=()=>f(!0),M=D=>{b(D),h(1),f(!1)},_=()=>{t("/products/settings/ftp-sync",{state:{fromSyncStep:p}})},I=async()=>{const D=i?.channelId||i?.id;if(!D){w("Channel ID not found"),x(!0),S(!1);return}S(!1);try{const U=await n(Yo(D));if(Yo.fulfilled.match(U)){const N=U.payload?.message==="Sync started successfully"?"Sync started successfully":"Sync not started successfully";w(N),x(!0),N==="Sync started successfully"&&setTimeout(()=>{n(zt(r)),n(zn()),t("/")},2500)}else w("Sync not started successfully"),x(!0)}catch{w("Sync not started successfully"),x(!0)}},T=z.useCallback(()=>{p===1?(h(0),b("")):t("/")},[p,t]),{setSettingTopbarProps:F}=Yi()||{};return z.useEffect(()=>{if(F)return F({onBack:T}),()=>F({})},[F,T]),l.jsxs(P,{sx:{width:"100%",minHeight:"100vh",background:"#f7f8fa",p:0,display:"flex",flexDirection:"column",alignItems:"center"},children:[l.jsx(ZI,{open:g,onClose:()=>f(!1),onSave:M}),l.jsx(eN,{isOpen:m,onClose:()=>S(!1),onConfirm:I}),l.jsx(go,{open:C,autoHideDuration:4e3,onClose:()=>x(!1),message:v,anchorOrigin:{vertical:"top",horizontal:"center"}}),l.jsx(QI,{airaAiEnabled:a,setAiraAiEnabled:c,selectedCard:d,setSelectedCard:u,syncStep:p,syncMethod:y,integrationData:i,onSetupSync:L,onSetupFTP:_,onSyncNow:()=>S(!0)})]})}const nN=["Setup FTP","Check data","Start Sync"],rN=e=>l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{maxWidth:800,mx:"auto",pt:2,px:2},children:[l.jsx(P,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",px:2,py:2,mb:1},children:nN.map((t,n)=>l.jsx(j,{component:"span",sx:{fontFamily:"Inter, sans-serif",fontWeight:n===0?600:400,fontSize:"12px",lineHeight:"16px",letterSpacing:"0px",textAlign:"center",verticalAlign:"middle",color:"#454545",opacity:1,width:224,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:1},children:t},t))}),l.jsx(P,{sx:{width:800,height:504,gap:"8px",borderRadius:"16px",padding:"8px",background:"#FFFFFF",opacity:1,display:"flex",justifyContent:"center",alignItems:"center",boxSizing:"border-box"},children:l.jsxs(cn,{elevation:0,sx:{width:400,height:210,gap:"24px",borderRadius:"20px",padding:"24px",background:"#fafafa",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsxs(P,{sx:{width:352,height:98,gap:"12px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:700,fontSize:"16px",lineHeight:"20px",letterSpacing:"0px",verticalAlign:"middle",color:"#000000",opacity:1,width:145,height:20,margin:0},children:"Setup Instructions"}),l.jsxs(P,{component:"ol",sx:{margin:0,paddingLeft:"28px",listStylePosition:"outside",listStyleType:"decimal",fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"22px",letterSpacing:"0px",color:"#454545",opacity:1,width:352,height:66,boxSizing:"border-box","& li":{display:"list-item",marginBottom:"4px"},"& li:last-child":{marginBottom:0}},children:[l.jsx("li",{children:"Directory should have just one file"}),l.jsx("li",{children:"File format must be in CSV (comma separated)"}),l.jsx("li",{children:"File structure should be flat"})]})]}),l.jsx(P,{sx:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none"},onClick:()=>e.onNext&&e.onNext(),children:"Next"})})]})})]})});function oN(e){const{sx:t,fontSize:n,...r}=e;return l.jsxs(er,{viewBox:"0 0 14.666666 10.666666",sx:{fontSize:n||14.666666,color:"#454545",...t},...r,children:[l.jsx("path",{d:"M1 5.333333C2.2 3.2 4.266667 1.666667 7.333333 1.666667C10.4 1.666667 12.466667 3.2 13.666667 5.333333C12.466667 7.466667 10.4 9 7.333333 9C4.266667 9 2.2 7.466667 1 5.333333Z",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"7.333333",cy:"5.333333",r:"2",fill:"none",stroke:"currentColor",strokeWidth:"1"})]})}function iN(e){const{sx:t,fontSize:n,...r}=e;return l.jsxs(er,{viewBox:"0 0 14.666666 10.666666",sx:{fontSize:n||14.666666,color:"#454545",...t},...r,children:[l.jsx("path",{d:"M1 5.333333C2.2 3.2 4.266667 1.666667 7.333333 1.666667C10.4 1.666667 12.466667 3.2 13.666667 5.333333C12.466667 7.466667 10.4 9 7.333333 9C4.266667 9 2.2 7.466667 1 5.333333Z",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("circle",{cx:"7.333333",cy:"5.333333",r:"2",fill:"none",stroke:"currentColor",strokeWidth:"1"}),l.jsx("path",{d:"M2 9L12.666667 1.666667",fill:"none",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round"})]})}const sN=({active:e,completed:t,showBlue:n})=>{const r=!e&&!t,i=n?"#2D64B8":"#bbb";return l.jsx(P,{sx:{position:"relative",width:16,height:16,borderRadius:"50%",border:"1px solid",borderColor:i,opacity:1,display:"flex",alignItems:"center",justifyContent:"center",background:"#fff",boxSizing:"border-box",flexShrink:0},children:r?l.jsx("svg",{width:10,height:10,viewBox:"0 0 24 24",fill:"none",style:{display:"block"},children:l.jsx("path",{d:"M7 10l5 5 5-5",stroke:i,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):l.jsx("svg",{width:8,height:8,viewBox:"0 0 24 24",fill:"none",style:{display:"block"},children:l.jsx("path",{d:"M7 12.5L11 16L17 9.5",stroke:"#2D64B8",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})},ll=({steps:e=[],activeStep:t=0,showCheckDataBlueTick:n=!1,progressToCheckData:r=!1,showSetupFtpBlueTick:i=!1,showStartSyncBlueTick:s=!1,instantComplete:a=!1,progressSegment:c,filledSegments:d,filledSegmentsStart:u=0,previousStepsComplete:p=!1})=>{const y=vn().transitions?.duration?.standard??400,[b,g]=z.useState(0),[f,m]=z.useState(!1),S=Math.max(1,e.length),C=50/S,x=100*(S-1)/S,v=40/S,w=S>1?100/S:0,A=100,O=z.useMemo(()=>{let L;if(typeof d=="number"){const _=typeof u=="number"?u:0,I=d-_;L=w*(_+b*I)}else typeof c=="number"?L=w*(c+b):s?L=b?x:0:r?L=b?x*.5:0:L=b?v:0;const M=Math.min(L,x)/x;return Math.round(M*A)},[b,d,u,c,s,r,w,x,v]);return z.useEffect(()=>{if(a){setTimeout(()=>{g(1),m(!0)},0);return}if(typeof d=="number"&&typeof u=="number"&&u>0){setTimeout(()=>{g(0),m(!1)},0);const M=setTimeout(()=>{g(1),setTimeout(()=>m(!0),y)},50);return()=>clearTimeout(M)}setTimeout(()=>{g(0),m(!1)},0);const L=setTimeout(()=>{g(1),setTimeout(()=>m(!0),y)},50);return()=>clearTimeout(L)},[t,e.length,r,a,d,u,y]),l.jsxs(P,{sx:{width:800,opacity:1},children:[l.jsx(P,{sx:{width:800,height:44,gap:"16px",opacity:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:e.map((L,M)=>l.jsxs(P,{sx:{width:256,height:44,gap:"12px",opacity:1,paddingLeft:"16px",paddingRight:"16px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:[l.jsx(sN,{active:M===t,completed:M<t,showBlue:M===0&&i||M===1&&n&&(f||p)||M===2&&s}),l.jsx(P,{component:"span",sx:{width:224,height:16,fontFamily:"Inter, sans-serif",fontWeight:M===0?600:400,fontSize:"12px",lineHeight:"16px",letterSpacing:"0px",textAlign:"center",color:"#454545",opacity:1,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:L})]},L))}),l.jsx(P,{sx:{width:"100%",mt:1,mb:0},children:l.jsx(P,{sx:{marginLeft:`${C}%`,width:`${x}%`},children:l.jsx(hm,{variant:"progress",steps:A+1,position:"static",activeStep:O,sx:{maxWidth:"100%",flexGrow:1,background:"transparent",padding:0,"& .MuiMobileStepper-progress":{width:"100%"},"& .MuiLinearProgress-root":{height:4,borderRadius:2,backgroundColor:"#f2f2f2"},"& .MuiLinearProgress-bar":{backgroundColor:"#219653"}},nextButton:null,backButton:null})})})]})},aN=e=>e.dashboard?.companyId||"";function lN(e){try{const t=new URL(e);return{type:t.protocol.replace(":",""),host:t.hostname,port:t.port,path:t.pathname}}catch{return{type:"",host:"",port:"",path:""}}}const cN=e=>{const{ftpDetails:t={},stepperProps:n={}}=e,[r,i]=z.useState(null),s=Et(),a=It(),c=Je(aN),[d,u]=z.useState(!1);z.useEffect(()=>{let M,_;return setTimeout(()=>{u(!1),M=setTimeout(()=>{_=setTimeout(()=>u(!0),600)},100)},0),()=>{M&&clearTimeout(M),_&&clearTimeout(_)}},[]);const[p,h]=z.useState(!1),y=localStorage.getItem("selectedSyncMethod")||"sftp",[b,g]=z.useState(`${y}:`),[f,m]=z.useState(""),[S,C]=z.useState(""),x=on(),v=Je(M=>M.productSettings?.loading||!1),w=Je(M=>M.productSettings?.error||null),A=vn();ht(A.breakpoints.up("lg"));const O=Je(M=>M.productSettings.syncData);z.useEffect(()=>{const M=s.state?.ftpConfig,_=s.state?.tenantIntegrationData;if(O&&O.serverAddress){setTimeout(()=>{g(O.serverAddress||""),m(O.configs&&O.configs.username||""),C(O.configs&&O.configs.password||"")},0);return}if(t&&(t.host||t.username||t.password)){const I=t.type||"sftp",T=t.host||"",F=t.port||"",D=t.path||"",U=`${I}://${T}${F?`:${F}`:""}${D?`/${D}`:""}`;setTimeout(()=>{g(U),m(t.username||""),C(t.password||"")},0);return}if(_&&_.configs){const I=_.configs,T=I.type||_.type||"sftp",F=I.host||"",D=I.port||"",U=I.path||"",N=`${T}://${F}:${D}/${U}`,$=I.username||"",k=I.password||"";setTimeout(()=>{g(N),m($),C(k)},0);return}if(M){const T=`${M.type||"sftp"}://${M.host}:${M.port}/${M.path}`,F=M.username||"",D=M.password||"";setTimeout(()=>{g(T),m(F),C(D)},0)}},[s.state,O,t]);const L=async()=>{if(!c){alert("Company ID is required. Please ensure the app is properly configured.");return}const{type:M,host:_,port:I,path:T}=lN(b),F=await x(Ro({serverAddress:b,username:f,password:S,companyId:c}));if(!Ro.fulfilled.match(F))return;const D=F.payload;if(s.state?.fromSettingsIcon){const $=D?.entity_type||r?.entity_type||"products",k={...r||{},companyId:c,tenantId:c,type:M,serverAddress:b,configs:{host:_,port:Number(I),path:T,username:f,password:S,sync_frequency:r?.configs?.sync_frequency||t?.sync_frequency||"",sync_time:r?.configs?.sync_time||t?.sync_time||""},entity_type:$,mappings:r?.mappings||D?.existing_mapping?.mappings||[]};i(k),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(k)),a("/ftp-sync-2",{state:{fromSettingsIcon:!0,putjson:k}});return}const U=D?.entity_type||"",N={tenantId:c,type:M,serverAddress:b,configs:{host:_,port:Number(I),path:T,username:f,password:S,sync_frequency:"",sync_time:""},entity_type:U||"products",mappings:D?.existing_mapping?.mappings||[]};x(zs(N)),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(N)),e.onNext&&e.onNext({putjson:N})};return l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,minHeight:600,gap:"32px",opacity:1,pt:2,left:"340px",mx:"auto",display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...n,showSetupFtpBlueTick:d})}),l.jsx(P,{sx:{width:800,height:504,minHeight:504,borderRadius:"16px",padding:"8px",paddingBottom:"32px",gap:"8px",opacity:1,display:"flex",justifyContent:"center",alignItems:"center",bgcolor:"#fff",boxSizing:"border-box",marginBottom:"32px"},children:l.jsxs(P,{sx:{width:400,height:380,borderRadius:"20px",padding:"24px",gap:"24px",opacity:1,bgcolor:"#F5F5F5",display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx(P,{sx:{width:352,height:20,justifyContent:"space-between",opacity:1,display:"flex",alignItems:"center"},children:l.jsx(j,{sx:{width:102,height:20,fontFamily:"Inter, sans-serif",fontWeight:700,fontSize:"16px",lineHeight:"20px",letterSpacing:"0px",color:"#000000",opacity:1,margin:0},children:"Login Details"})}),l.jsxs(P,{component:"form",autoComplete:"off",sx:{width:352,height:224,gap:"16px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsxs(P,{sx:{width:352,height:64,gap:"4px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx("label",{style:{width:352,height:18,fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"18px",letterSpacing:"0px",color:"#454545",opacity:1,margin:0,display:"block"},children:"Server Address"}),l.jsx("input",{type:"text",value:b,onChange:M=>g(M.target.value),placeholder:"sftp://234.124.12.34:4432/data/sync",style:{width:352,height:42,boxSizing:"border-box",borderRadius:"6px",padding:"12px",border:"1px solid #F1F1F1",background:"#FFFFFF",opacity:1,fontSize:14,fontFamily:"Inter, sans-serif"}})]}),l.jsxs(P,{sx:{width:352,height:64,gap:"4px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box"},children:[l.jsx("label",{style:{width:352,height:18,fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"18px",letterSpacing:"0px",color:"#454545",opacity:1,margin:0,display:"block"},children:"Username"}),l.jsx("input",{type:"text",value:f,onChange:M=>m(M.target.value),placeholder:"Enter username",style:{width:352,height:42,boxSizing:"border-box",borderRadius:"6px",padding:"12px",border:"1px solid #F1F1F1",background:"#FFFFFF",opacity:1,fontSize:14,fontFamily:"Inter, sans-serif"}})]}),l.jsxs(P,{sx:{width:352,height:64,gap:"4px",opacity:1,display:"flex",flexDirection:"column",boxSizing:"border-box",position:"relative"},children:[l.jsx("label",{style:{width:352,height:18,fontFamily:"Inter, sans-serif",fontWeight:400,fontStyle:"normal",fontSize:"14px",lineHeight:"18px",letterSpacing:"0px",color:"#454545",opacity:1,margin:0,display:"block"},children:"Password"}),l.jsx("input",{type:p?"text":"password",value:S,onChange:M=>C(M.target.value),placeholder:"Enter password",style:{width:352,height:42,boxSizing:"border-box",borderRadius:"6px",padding:"12px 44px 12px 12px",border:"1px solid #F1F1F1",background:"#FFFFFF",opacity:1,fontSize:14,fontFamily:"Inter, sans-serif"}}),l.jsx(yt,{"aria-label":"toggle password visibility",onClick:()=>h(M=>!M),tabIndex:-1,size:"small",sx:{position:"absolute",right:11,top:35,color:"#454545",width:16,height:16,padding:0,display:"flex",alignItems:"center",justifyContent:"center","&:hover":{backgroundColor:"rgba(0,0,0,0.04)",color:"#222"},"& .MuiSvgIcon-root":{width:16,height:16,fontSize:16}},children:p?l.jsx(iN,{}):l.jsx(oN,{})})]})]}),l.jsxs(P,{sx:{display:"flex",justifyContent:"flex-end",gap:2,marginTop:"auto"},children:[l.jsx(Xe,{variant:"outlined",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",bgcolor:"#fff"},onClick:e.onBack,children:"Back"}),l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none"},onClick:L,disabled:v,children:v?"Loading...":"Next"})]}),w&&l.jsx(j,{color:"error",sx:{mt:1,fontSize:14},children:"Fill the credentials"})]})})]})})},dN=e=>e.productSettings.ftpColumns||[],pN=e=>e.productSettings.preview||[],uN=e=>e.productSettings.loading,fN=e=>e.productSettings.error,hN=e=>e.productSettings.existingMapping,gN=e=>e.productSettings.entity_type||"products",mN=e=>{const{mapping:t=[],onBack:n,onNext:r,stepperProps:i={}}=e,s=Et(),a=It(),c=s.state?.fromSettingsIcon,[d,u]=z.useState(()=>{if(s.state?.putjson)return s.state.putjson;const N=window.localStorage.getItem("ftpSyncPutjson");return N?JSON.parse(N):t.length>0?{mappings:t}:null}),[p,h]=z.useState([]),[y,b]=z.useState({}),g=Je(dN),f=Je(pN),m=Je(uN),S=Je(fN),C=Je(hN),x=Je(gN),v=z.useRef(m);z.useEffect(()=>{m&&!v.current&&queueMicrotask(()=>b({})),v.current=m},[m]);const w=z.useRef(!1);z.useLayoutEffect(()=>{C==null||!C?.mappings||C.mappings.length===0?w.current||(w.current=!0,queueMicrotask(()=>b({}))):w.current=!1},[C]);const A=on();z.useEffect(()=>{async function N(){try{let $=[];if(C?.mappings?.length>0){const k=C.mappings.map(V=>V.target_field).filter(V=>V&&typeof V=="string");$=[...new Set(k)]}try{const k=await A(Ko(x));Ko.fulfilled.match(k)&&Array.isArray(k.payload)&&k.payload.filter(B=>B&&typeof B=="string").forEach(B=>{$.includes(B)||$.push(B)})}catch{}if(t&&t.length>0){const k=t.map(V=>V.target_field).filter(V=>V&&typeof V=="string"&&!$.includes(V));k.length>0&&($=[...$,...k])}$=$.filter(k=>k&&typeof k=="string"),h($)}catch{if(C?.mappings?.length>0){const $=C.mappings.map(V=>V.target_field).filter(V=>V&&typeof V=="string"),k=[...new Set($)];h(k)}else h([])}}(x||C?.mappings?.length>0||t&&t.length>0)&&N()},[x,C,t,A]);const O=z.useMemo(()=>{if(C?.mappings&&C.mappings.length>0){const N=C.mappings.map($=>$.source_field).filter($=>$);if(N.length>0)return N}return g&&g.length>0?g:[]},[C,g]),L=z.useMemo(()=>f.filter($=>Object.keys($).length>0),[f]),M=z.useMemo(()=>{if(C?.mappings&&C.mappings.length>0){const N={};return C.mappings.forEach($=>{$.source_field&&$.target_field&&(N[$.source_field]=$.target_field)}),N}return{}},[C]),I=C?.mappings?.length>0?{...M,...y}:{...y},T=vn();ht(T.breakpoints.up("lg"));const F=Je(N=>N.productSettings.syncData),D=z.useMemo(()=>{if(F?.serverAddress)return F.serverAddress;const N=F?.configs||{},$=(F?.type||"sftp").toLowerCase(),k=N.host,V=N.port,B=N.path;if(!k)return"";let W=`${$}://${k}`;if(V!=null&&V!==""&&(W+=`:${V}`),B){const q=String(B).replace(/^\/+/,"");W+=`/${q}`}return W},[F]),U=()=>{const N=O.map(B=>({source_field:B||"",target_field:I[B]||""})).filter(B=>B.source_field&&B.target_field);if(N.length===0)return;if(c&&d){const B={...d,tenantId:d.tenantId||d.companyId,type:d.type||F.type||"sftp",entity_type:d.entity_type||F.entity_type||"products",mappings:N};u(B),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),r?r({fromSettingsIcon:!0,putjson:B}):e.onNext&&e.onNext({fromSettingsIcon:!0,putjson:B});return}const $=JSON.parse(window.localStorage.getItem("ftpSyncPutjson")||"{}"),k=F.companyId||$.companyId||$.tenantId||"",V={...$,companyId:k,tenantId:k,type:F.type||$.type||"sftp",integration_type:F.integration_type||$.integration_type||"",entity_type:$.entity_type||F.entity_type||"products",configs:F.configs||$.configs||{},ftp_columns:O,preview:L,mappings:N};A(zs(V)),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(V)),r?r({putjson:V}):e.onNext&&e.onNext({putjson:V})};return l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,mx:"auto",pt:2,display:"flex",flexDirection:"column",gap:"32px"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...i})}),l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:300,mb:4},children:l.jsxs(cn,{elevation:0,sx:{mt:0,p:0,borderRadius:4,width:"100%",maxWidth:800},children:[l.jsxs(P,{sx:{p:3,pb:2,borderBottom:"1px solid #eee",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(P,{children:[l.jsx(j,{variant:"subtitle1",sx:{fontWeight:700},children:"Map data from FTP to AiraOps"}),D&&l.jsx(j,{variant:"body2",sx:{color:"#888",mt:.5},children:D})]}),l.jsxs(P,{children:[l.jsx(Xe,{variant:"outlined",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",mr:2},onClick:n||(()=>a("/products/settings/ftp-sync",{state:{step:1}})),children:"Back"}),l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none"},onClick:U,children:"Next"})]})]}),l.jsx(jm,{sx:{background:"#fafafa",borderRadius:4,mt:0,boxShadow:"none",border:"1px solid #eee"},children:m?l.jsx(P,{sx:{p:3,textAlign:"center"},children:"Loading..."}):S?l.jsx(P,{sx:{p:3,color:"red",textAlign:"center"},children:S}):O.length===0?l.jsx(P,{sx:{p:3,textAlign:"center",color:"#888"},children:"No columns available. Please check your FTP connection and try again."}):l.jsxs(zm,{size:"small",children:[l.jsxs(Vm,{children:[l.jsxs(Vi,{children:[l.jsx(ir,{sx:{fontWeight:700,background:"#fafafa",borderBottom:"none",minWidth:120},children:"Columns in FTP"}),O.map((N,$)=>l.jsx(ir,{sx:{fontWeight:700,background:"#fafafa",borderBottom:"none",minWidth:120},children:N},N+$))]}),l.jsxs(Vi,{children:[l.jsx(ir,{sx:{fontWeight:700,background:"#fafafa",borderBottom:"none"},children:"Columns in Aira"}),O.map((N,$)=>l.jsx(ir,{sx:{background:"#fafafa",borderBottom:"none"},children:l.jsxs(Pn,{value:I[N]||"",onChange:k=>b(V=>({...V,[N]:k.target.value})),variant:"standard",disableUnderline:!0,displayEmpty:!0,sx:{minWidth:120,fontWeight:500},MenuProps:{PaperProps:{sx:{maxHeight:300,boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)","& .MuiList-root":{padding:"0"},"& .MuiMenuItem-root":{padding:"8px 16px",minHeight:"auto",fontSize:"14px",lineHeight:"1.5",margin:0},"& .MuiMenuItem-root:first-of-type":{marginTop:0}}},anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},MenuListProps:{sx:{padding:0}}},children:[l.jsx(We,{value:"",sx:{padding:"8px 16px",minHeight:"auto",fontSize:"14px",margin:0},children:l.jsx("em",{style:{fontStyle:"normal",color:"#888"},children:"Select column"})}),p.map(k=>l.jsx(We,{value:k,sx:{padding:"8px 16px",minHeight:"auto",fontSize:"14px",margin:0},children:k},k))]})},$))]})]}),l.jsx(Bm,{children:L.length>0?L.map((N,$)=>l.jsxs(Vi,{children:[l.jsx(ir,{sx:{fontWeight:700,background:"#fff",borderBottom:"none"},children:$===0?"Data preview":""}),O.map((k,V)=>l.jsx(ir,{sx:{background:"#fff",borderBottom:"none"},children:N[k]||""},V))]},$)):l.jsx(Vi,{children:l.jsx(ir,{colSpan:O.length+1,sx:{textAlign:"center",color:"#888",py:2},children:"No preview data available"})})})]})})]})})]})})},yN=e=>e.dashboard?.companyId||"",bN=e=>e.dashboard?.integrationData||null,xN=e=>{const{syncFrequency:t="",syncTime:n="",stepperProps:r={}}=e,i=Et(),s=It(),a=on(),c=Je(yN),d=Je(bN),u=i.state?.fromSettingsIcon,[p,h]=z.useState(()=>{if(i.state?.putjson){const k=JSON.parse(JSON.stringify(i.state.putjson));return k.mappings&&(k.originalMappings=JSON.parse(JSON.stringify(k.mappings))),k.configs?.sync_frequency&&!k.originalSyncFrequency&&(k.originalSyncFrequency=k.configs.sync_frequency),k.configs?.sync_time&&!k.originalSyncTime&&(k.originalSyncTime=k.configs.sync_time),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(k)),k}const $=window.localStorage.getItem("ftpSyncPutjson");if($){const k=JSON.parse($);return k.mappings&&!k.originalMappings&&(k.originalMappings=JSON.parse(JSON.stringify(k.mappings))),k.configs?.sync_frequency&&!k.originalSyncFrequency&&(k.originalSyncFrequency=k.configs.sync_frequency),k.configs?.sync_time&&!k.originalSyncTime&&(k.originalSyncTime=k.configs.sync_time),k}return null});z.useEffect(()=>{p&&window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(p))},[p]);const[y,b]=z.useState(null),[g,f]=z.useState(null);z.useEffect(()=>{const $=i.state?.fromProductSetting;let k=null;if($&&i.state?.integrationData)k=i.state.integrationData;else if(d&&Object.keys(d).length>0)k=d;else if(c&&!$){a(zt(c)).then(V=>{if(zt.fulfilled.match(V)){const B=V.payload;if(k=B&&B.data&&B.data[0]||null,k){b(k);const W=k.id||k.channelId||null;W&&f(W)}}});return}if(k){b(k);const V=k.id||k.channelId||null;V&&f(V)}},[c,i.state,d,a]);const m=!!u||!!y,S=$=>{if(!$)return"";const k=$.charAt(0).toUpperCase()+$.slice(1).toLowerCase();return k==="Daily"||k==="Day"?"Daily":k==="Weekly"||k==="Week"?"Weekly":k==="Monthly"||k==="Month"?"Monthly":k},[C,x]=z.useState(()=>{if(t)return S(t);const $=p?.configs?.sync_frequency?S(p.configs.sync_frequency):"";return $||"Daily"}),[v,w]=z.useState(n||p&&p.configs?.sync_time||"");z.useEffect(()=>{async function $(){if(c)try{const k=i.state?.fromProductSetting;let V=null;if(k&&i.state?.integrationData)V=i.state.integrationData;else if(d&&Object.keys(d).length>0)V=d;else{const B=await a(zt(c));if(zt.fulfilled.match(B)){const W=B.payload;V=W&&W.data&&W.data[0]||null}}if(V){const B=V.id||V.channelId||null;B&&f(B);const W=p||JSON.parse(window.localStorage.getItem("ftpSyncPutjson")||"null"),q={...V,companyId:V.companyId||c,entity_type:V.entity_type||W?.entity_type||"product",mappings:V.mappings||W?.mappings||[]},X=V.configs?.sync_frequency||"",G=V.configs?.sync_time||"",Q=S(X);if(h(q),k){if(t){const ee=S(t);x(ee)}n&&w(n),h(ee=>({...ee,...q,originalSyncFrequency:t?S(t):ee.originalSyncFrequency||Q,originalSyncTime:n||ee.originalSyncTime||G,configs:{...q.configs,sync_frequency:t?S(t).toLowerCase():q.configs?.sync_frequency,sync_time:n||q.configs?.sync_time}}))}else{const ee=t?S(t):"";if(ee)x(ee);else if(Q)x(Q);else if(W?.configs?.sync_frequency){const oe=S(W.configs.sync_frequency);x(oe)}else x("Daily");n?w(n):G?w(G):W?.configs?.sync_time?w(W.configs.sync_time):w(""),h(q),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(q))}}}catch{const k=JSON.parse(window.localStorage.getItem("ftpSyncPutjson")||"null");!t&&k?.configs?.sync_frequency?x(S(k.configs.sync_frequency)):t&&x(S(t)),!n&&k?.configs?.sync_time?w(k.configs.sync_time):n&&w(n)}}$()},[c]),z.useEffect(()=>{if(t){const $=S(t);x($),p&&p.configs?.sync_frequency!==$&&h(k=>{const V={...k,configs:{...k.configs,sync_frequency:$}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(V)),V})}},[t]),z.useEffect(()=>{n&&(w(n),p&&p.configs?.sync_time!==n&&h($=>{const k={...$,configs:{...$.configs,sync_time:n}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(k)),k}))},[n]),z.useEffect(()=>{if(p&&m&&(C||v)){const $=p.configs?.sync_frequency,k=p.configs?.sync_time;($!==C||k!==v)&&h(V=>{const B={...V,configs:{...V.configs,sync_frequency:C||V.configs?.sync_frequency,sync_time:v||V.configs?.sync_time}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),B})}},[C,v,m]);const A=Je($=>$.productSettings.syncData),O=$=>{const k=$.target.value;x(k),p&&h(V=>{const B={...V,configs:{...V.configs,sync_frequency:k}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),B}),m||a(zs({...A,configs:{...A&&A.configs||{},sync_frequency:k,sync_time:v}}))},L=$=>{const k=$.target.value;w(k),p&&h(V=>{const B={...V,configs:{...V.configs,sync_time:k}};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(B)),B}),m||a(zs({...A,configs:{...A&&A.configs||{},sync_frequency:C,sync_time:k}}))};function M($){try{const k=new URL($);return{type:k.protocol.replace(":",""),host:k.hostname,port:k.port,path:k.pathname}}catch{return{type:"",host:"",port:"",path:""}}}const[_,I]=z.useState(!1),[T,F]=z.useState(""),D=async()=>{const $=i.state?.fromProductSetting;if(m){if(!p){F("Update failed: missing data."),I(!0);return}let H={...p};p.originalMappings||(H.originalMappings=p.mappings?JSON.parse(JSON.stringify(p.mappings)):[],h(H)),!p.originalSyncFrequency&&p.configs?.sync_frequency&&(H.originalSyncFrequency=p.configs.sync_frequency||"",h(H)),!p.originalSyncTime&&p.configs?.sync_time&&(H.originalSyncTime=p.configs.sync_time||"",h(H));const he=JSON.parse(JSON.stringify(p.mappings||[])),de=JSON.parse(JSON.stringify(p.originalMappings||[]));let ge,ze;$?(ge=t?S(t):"",ze=n||""):(ge=p.originalSyncFrequency||p.configs?.sync_frequency||"",ze=p.originalSyncTime||p.configs?.sync_time||"",ge=S(ge));const Ee=$?!1:JSON.stringify(he)!==JSON.stringify(de),me=C!==ge,De=v!==ze,Le=(me||De)&&!Ee,Ne=Ee;if(Le){const pe=g||p?.id||p?.channelId||i.state?.integrationData?.id||i.state?.integrationData?.channelId;if(!pe){F("Channel ID is missing. Please try again."),I(!0);return}const Ve={configs:{}};me&&(Ve.configs.sync_frequency=C.toLowerCase()),De&&(Ve.configs.sync_time=v);try{const Ie=await a(Go({channelId:pe,data:Ve}));if(Ie.error||Go.rejected.match(Ie)){const xe=Ie.payload||Ie.error?.message||"Update failed. Please try again.";F(xe),I(!0);return}let se="";me&&!De?se="SyncFrequency Updated":!me&&De?se="SyncTime Updated":me&&De&&(se="SyncTime and SyncFrequency Updated"),F(se),I(!0),h(xe=>{const Z={...xe,configs:{...xe.configs,sync_frequency:C.toLowerCase(),sync_time:v},originalSyncFrequency:C,originalSyncTime:v};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(Z)),Z});const ne=i.state?.fromProductSetting;ne&&c&&await a(zt(c)),setTimeout(()=>{ne&&s("/product-setting",{state:{tenantIntegrationMatched:!0}})},1500);return}catch(Ie){const se=Ie?.message||Ie?.response?.data?.message||"Update failed. Please try again.";F(se),I(!0);return}}if(Ne){const pe={...p,configs:{...p.configs,sync_frequency:C.toLowerCase(),sync_time:v}};h(pe),window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(pe));const Ve=pe.tenantId||pe.companyId;if(!pe.configs){F("Configuration error. Please try again."),I(!0);return}const Ie=pe.entity_type||p?.entity_type;if(!Ie){F("Entity type is missing. Please try again."),I(!0);return}const se={tenantId:Ve,type:pe.type,entity_type:Ie,configs:{host:pe.configs.host||"",port:pe.configs.port?Number(pe.configs.port):0,username:pe.configs.username||"",password:pe.configs.password||"",path:pe.configs.path||"",sync_frequency:C.toLowerCase()||"",sync_time:v||""},mappings:(pe.mappings||[]).map(ne=>({source_field:ne.source_field,target_field:ne.target_field}))};if(!se.tenantId){F("Tenant ID is missing. Please try again."),I(!0);return}if(!se.type){F("Sync type is missing. Please try again."),I(!0);return}if(!se.entity_type){F("Entity type is missing. Please try again."),I(!0);return}try{const ne=await a(jr(se));if(jr.rejected.match(ne)){const xe=ne.payload||ne.error?.message||"Update failed. Please try again.";F(xe),I(!0);return}jr.fulfilled.match(ne)?(h(xe=>{const Z={...xe,originalSyncFrequency:C,originalSyncTime:v,originalMappings:JSON.parse(JSON.stringify(xe.mappings||[]))};return window.localStorage.setItem("ftpSyncPutjson",JSON.stringify(Z)),Z}),F("Sync Update Successfully"),I(!0),setTimeout(()=>{s("/product-setting",{state:{tenantIntegrationMatched:!0}})},1500)):(F("Update failed. Please try again."),I(!0))}catch(ne){const xe=ne?.message||ne?.response?.data?.message||"Update failed. Please try again.";F(xe),I(!0)}}else F("No changes detected."),I(!0);return}const k=A.configs||{},V=M(A.serverAddress||""),B=k.host||V.host,W=k.port!=null?Number(k.port):parseInt(V.port,10),q=(k.path||V.path||"").replace(/^\//,""),X=A.type||V.type||"sftp",G=A.username||k.username||"",Q=A.password||k.password||"",ee=C||k.sync_frequency||"",oe=typeof ee=="string"?ee.toLowerCase():ee;let le=v||k.sync_time||"";if(typeof le=="string"&&/^\d{1,2}:\d{2}\s*[AP]M$/i.test(le.trim())){const[H,he]=le.trim().split(/\s+/),[de,ge]=H.split(":").map(Number),ze=he.toUpperCase()==="PM"&&de!==12?de+12:he.toUpperCase()==="AM"&&de===12?0:de;le=`${String(ze).padStart(2,"0")}:${String(ge).padStart(2,"0")}`}else typeof le=="string"&&(le=le.trim());const ae=(A.mappings||[]).filter(H=>H.source_field&&H.target_field).map(H=>({source_field:H.source_field,target_field:H.target_field}));if(!c){F("Company ID is required. Please ensure the app is properly configured."),I(!0);return}if(!B||!W||!G||!Q||ae.length===0){F("Please fill all required fields and mappings before saving."),I(!0);return}const re=A.entity_type||"products",ce={tenantId:c,type:X,entity_type:re,configs:{host:B,port:Number(W),username:G,password:Q,path:q,sync_frequency:oe,sync_time:le},mappings:ae};try{const H=await a(qo(ce));qo.fulfilled.match(H)?(F("Save and Start Sync Updated Successfully"),I(!0),e.onNext&&e.onNext()):(F(H?.payload||"Save failed. Please try again."),I(!0))}catch{F("Save failed. Please try again."),I(!0)}},[U,N]=z.useState(!1);return z.useEffect(()=>{const $=setTimeout(()=>N(!0),850);return()=>clearTimeout($)},[]),l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,mx:"auto",pt:2,display:"flex",flexDirection:"column",gap:"32px"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...r,showStartSyncBlueTick:U})}),l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:380,bgcolor:"#fff",borderRadius:2,boxShadow:"0 2px 12px #0001"},children:l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:180,mt:4,mb:4},children:l.jsxs(cn,{elevation:0,sx:{p:2.5,borderRadius:4,minWidth:300,maxWidth:340,width:1,display:"flex",flexDirection:"column",alignItems:"center",bgcolor:"#f5f5f5"},children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"row",gap:2,width:"100%",mb:2},children:[l.jsxs(P,{sx:{flex:1},children:[l.jsx(j,{variant:"subtitle2",sx:{mb:1,fontSize:14,color:"#222"},children:"Sync Frequency"}),l.jsxs(Pn,{size:"small",value:C,onChange:O,sx:{minWidth:120,borderRadius:2,background:"#fafbfc",fontSize:15,height:40},children:[l.jsx(We,{value:"Daily",children:"Daily"}),l.jsx(We,{value:"Weekly",children:"Weekly"}),l.jsx(We,{value:"Monthly",children:"Monthly"})]})]}),l.jsxs(P,{sx:{flex:1},children:[l.jsx(j,{variant:"subtitle2",sx:{mb:1,fontSize:14,color:"#222"},children:"Sync Time"}),l.jsx(Ui,{type:"time",size:"small",value:v,onChange:L,sx:{minWidth:80,borderRadius:2,background:"#fafbfc",fontSize:15,height:36},InputLabelProps:{shrink:!0},inputProps:{step:300}})]})]}),l.jsxs(P,{sx:{display:"flex",justifyContent:"center",gap:.5,mt:1,width:"100%"},children:[l.jsx(Xe,{variant:"outlined",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",mr:2},onClick:e.onBack,children:"Back"}),l.jsx(Xe,{variant:"contained",color:"primary",sx:{borderRadius:2,minWidth:100,fontWeight:500,textTransform:"none",boxShadow:"none",flex:m?1:"initial"},onClick:D,children:m&&(i.state?.fromSyncSetting||i.state?.editMode)?"Save":m?"Update Sync":"Save and Start Sync"})]}),l.jsx(go,{open:_,autoHideDuration:4e3,onClose:()=>I(!1),message:T,anchorOrigin:{vertical:"top",horizontal:"center"}})]})})})]})})},vN=e=>{const{stepperProps:t={}}=e,n=on(),i=!!Je(d=>d.productSettings.saveResult),[s,a]=z.useState(i),c=It();return z.useEffect(()=>{i&&(a(!0),n(S1()))},[i,n]),l.jsxs(l.Fragment,{children:[l.jsx(go,{open:s,autoHideDuration:4e3,onClose:()=>a(!1),message:"Sync setup successful!",anchorOrigin:{vertical:"top",horizontal:"center"}}),l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa",p:0},children:l.jsxs(P,{sx:{width:800,mx:"auto",pt:2,display:"flex",flexDirection:"column",gap:"32px"},children:[l.jsx(P,{sx:{width:800,height:64,gap:"16px",opacity:1,display:"flex",flexDirection:"column",justifyContent:"center"},children:l.jsx(ll,{...t})}),l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:380,bgcolor:"#fff",borderRadius:2,boxShadow:"0 2px 12px #0001"},children:l.jsxs(P,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:320,py:6,bgcolor:"#f5f5f5",borderRadius:5},children:[l.jsx(P,{sx:{width:48,height:48,borderRadius:"50%",background:"#2563eb",display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:l.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",children:l.jsx("path",{d:"M7 12.5L11 16L17 9.5",stroke:"#fff",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})})}),l.jsx(j,{sx:{fontSize:17,color:"#222",mb:1,fontWeight:500},children:"Sync Setup Successfully"}),l.jsx(Xe,{variant:"text",sx:{color:"#2563eb",fontWeight:500,fontSize:15,textTransform:"none",mt:1},onClick:()=>c("/"),children:"Back to all products"})]})})]})}),l.jsx(go,{open:s,autoHideDuration:4e3,onClose:()=>a(!1),message:"Integration saved & sync started",anchorOrigin:{vertical:"top",horizontal:"center"}})]})};function SN(e){const t=Et(),n=It(),r=t.state?.fromProductSetting?3:0,[i,s]=z.useState(r),a=on(),{companyId:c,integrationData:d}=Je(O=>O.dashboard),u=t.state?.fromSyncStep;z.useEffect(()=>{const O=t.state?.fromProductSetting;c&&!O&&a(zt(c))},[c,a,t.state]);const p=()=>{s(O=>Math.min(O+1,4))},h=z.useCallback(()=>{if(i===0&&u!==void 0){n("/product-setting",{state:{fromSyncStep:u,tenantIntegrationMatched:u===3}});return}if(t.state?.fromProductSetting&&i===3){n("/product-setting",{state:{tenantIntegrationMatched:!0}});return}s(O=>Math.max(O-1,0))},[i,u,t.state?.fromProductSetting,n]),y=z.useMemo(()=>[{label:"Products",to:"/products"},{label:"Settings",to:"/product-setting"},{label:"FTP Sync",to:"/products/settings/ftp-sync"}],[]),b=z.useMemo(()=>[{label:"Products",to:"/products"},{label:"Settings",to:"/product-setting"}],[]),{setSettingTopbarProps:g}=Yi()||{};z.useEffect(()=>{if(g)return g({onBack:h,breadcrumbs:i===0||i===1?y:b}),()=>g({})},[g,h,i,y,b]);const f=d?.configs||{},m=d?.mappings||d?.dataMappings||[],C=(O=>{if(!O)return"";const L=O.charAt(0).toUpperCase()+O.slice(1).toLowerCase();return L==="Daily"||L==="Day"?"Daily":L==="Weekly"||L==="Week"?"Weekly":L==="Monthly"||L==="Month"?"Monthly":L})(d?.configs?.sync_frequency||""),x=d?.configs?.sync_time||"",v=["Setup FTP","Check data","Start Sync"],w=["Upload File","Check data","Start Sync"],A={0:{steps:v,activeStep:0,showCheckDataBlueTick:!1,progressToCheckData:!1,showSetupFtpBlueTick:!1,showStartSyncBlueTick:!1},1:{steps:v,activeStep:0,showCheckDataBlueTick:!1,progressToCheckData:!1,showSetupFtpBlueTick:!1,filledSegments:.5},2:{steps:v,activeStep:1,showCheckDataBlueTick:!0,progressToCheckData:!0,showSetupFtpBlueTick:!0,filledSegmentsStart:.5,filledSegments:1},3:{steps:w,activeStep:2,showCheckDataBlueTick:!0,progressToCheckData:!1,showSetupFtpBlueTick:!0,showStartSyncBlueTick:!1,filledSegmentsStart:1,filledSegments:2,previousStepsComplete:!0},4:{steps:w,activeStep:2,showCheckDataBlueTick:!0,progressToCheckData:!0,showSetupFtpBlueTick:!0,showStartSyncBlueTick:!0,instantComplete:!0}};switch(i){case 0:return l.jsx(rN,{onNext:p,onBack:h,stepperProps:A[0],...e});case 1:return l.jsx(cN,{onNext:p,onBack:h,ftpDetails:f,stepperProps:A[1],...e});case 2:return l.jsx(mN,{onNext:p,onBack:h,mapping:m,stepperProps:A[2],...e});case 3:return l.jsx(xN,{onNext:p,onBack:h,syncFrequency:C,syncTime:x,stepperProps:A[3],...e});case 4:return l.jsx(vN,{onBack:h,stepperProps:A[4],...e});default:return null}}const wN=it(l.jsx("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2m6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56M12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96M4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56m2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8M12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96M14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2m.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56M16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2z"}),"Language");function CN(e){return l.jsx(P,{sx:{width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",opacity:1,...e.sx},children:l.jsx(P,{component:"span",sx:{width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",opacity:1},children:l.jsx(wN,{sx:{color:"#808080"}})})})}const EN="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAAUlJREFUeAGNUrttwzAQFfWrnS6VIGsCjyAB+rWZIM4EyQZ2Jog2UDJCOkESYGaC2BOIZcr0+uVdYBqyQMM+gCB5997x3R2ZNjPf913LsnI6Yr23bfvKORdTjD4BL+I4fgPhexzHr6qqGPaDbdu7KIpySnZGgvPZNM0GIIbMy7qut+THnum6HuDIkIzIa/Izyg4wXQJk32sXLE1Tt+/7HY7C8DyvYIz94HLvOM5BCPGrqhOYHGuB6+pfXlmWS6mfXpb6Z3V+Eu6sEVI/gnekn8CzOjOJNacyiqIQ2NZH/c2xTj6XqytqlmR6naviStI1I9I+SZKXW8Coc4MOCtMwjIeu63IaMIp+UkkKw9AHeDMMg4bmBEwGaNoUAJHTf0MHG+oa/UP4XRBOCZki6xatfwSZBioA/oCSDJ/2NHSm0k4txysrtJ1PwdL+AHzhuHE1We3IAAAAAElFTkSuQmCC";function TN({sx:e={},...t}){const n=e?.fontSize??12,r=e?.width??n,i=e?.height??n;return l.jsx(P,{component:"img",src:EN,alt:"",role:"presentation",sx:{width:r,height:i,display:"block",objectFit:"contain",...e},...t})}const AN="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAANCAYAAACdKY9CAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAOdEVYdFNvZnR3YXJlAEZpZ21hnrGWYwAAAPtJREFUeAGlUUsOgjAQpSWQuLJHQC6gR4DwCe70Bt5Ab6CewCPIEVwSQmKPoDt3uHQnrPn5SjRpTIkLJ2k6bd+b92ZKNCkcx7EMwzh2XTcjhBRYcZqmexlD5QPAZ2zXuq4nuq67IC58399pqsCDg3X+UmRBEDyVCqjGKKWlohZTEpqm4SBNRR+fO9M019himUDkA+RXIB2gJMgMTVvI3SRJ7kqCiCiKrKqq+illWca1f6NXCMNw27btBlXZAO6Ctz3+5EQEWMwbNlzOeaFCe563AOGIdKnbth3jk+bw+xiykef5DbgRSDMxVkuewqB3QgRmTN/Jz0CPwm75AifwYTaKH5pyAAAAAElFTkSuQmCC",kN={fontSize:10.67,color:"#454545"};function PN({sx:e={},...t}){const n={...kN,...e},r=n.fontSize??10.67,i=n.width??r,s=n.height??r;return l.jsx(P,{component:"img",src:AN,alt:"",role:"presentation",sx:{width:i,height:s,display:"block",objectFit:"contain",...n},...t})}const ON=it(l.jsx("path",{d:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3m3-10H5V5h10z"}),"Save");function IN(e){return l.jsx(ON,{...e})}const NN=it(l.jsx("path",{d:"m14.06 9.02.92.92L5.92 19H5v-.92zM17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"}),"EditOutlined");function FN(e){return l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",...e.sx},children:l.jsx(P,{component:"span",sx:{width:13.22,height:13.22,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(NN,{})})})}const MN=it(l.jsx("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM8 9h8v10H8zm7.5-5-1-1h-5l-1 1H5v2h14V4z"}),"DeleteOutline");function DN(e){return l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",...e.sx},children:l.jsx(P,{component:"span",sx:{width:12,height:13.33,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(MN,{})})})}function _N(e){const{catalogs:t=[],totalCount:n=0,page:r=0,rowsPerPage:i=10,statusById:s={},getStatus:a,onPageChange:c,onRowsPerPageChange:d,onSave:u,onDelete:p,onStatusChange:h,updateCatalogError:y=null,updateCatalogLoading:b=!1}=e,[g,f]=z.useState(null),[m,S]=z.useState({name:"",slug:"",status:!0}),C=_=>{const I=_.slugRaw??(typeof _.slug=="string"?_.slug.replace(/^\//,""):"")??"",T=_.status==="Active"||_.status===!0;f(_.id),S({name:_.name??"",slug:I,status:T})},x=async _=>{if(typeof u!="function")return;const I=m.slug.trim().replace(/^\//,""),T={id:_.id,name:m.name.trim(),slug:I||m.name.trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),status:m.status};await u(T),f(null)},v=()=>{f(null)},w=t,A=Math.max(0,Number(n)||0),O=Math.max(0,Math.ceil(A/Math.max(1,i))-1),L={borderRadius:"4px",padding:"2px 4px",background:"#F5F5F5",display:"inline-flex",alignItems:"center",gap:"4px"},M={wrapper:{width:800,maxWidth:"100%",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:"40px",opacity:1,marginLeft:"auto",marginRight:"auto",paddingLeft:"24px",mt:2},resultsPerPageBox:{width:128,height:16,display:"flex",alignItems:"center",gap:"4px",opacity:1},resultsPerPageText:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545",whiteSpace:"nowrap"},select:{minWidth:32,height:16,"& .MuiSelect-select":{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545",py:0,pr:"20px !important",display:"flex",alignItems:"center"},"& .MuiSelect-icon":{top:"50%",transform:"translateY(-50%)"},"& .MuiSvgIcon-root":{width:16,height:16,right:0,color:"#454545"}},navBox:{width:200,height:16,display:"flex",alignItems:"center",gap:"16px",opacity:1},iconButton:{p:0,width:16,height:16,color:"#454545","&.Mui-disabled":{color:"#c0c0c0"}},pageText:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"}};return l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa"},children:l.jsxs(P,{sx:{width:600,maxWidth:"100%",minHeight:606,pt:2,mx:"auto",pb:4,display:"flex",flexDirection:"column",gap:"24px",opacity:1},children:[l.jsx(P,{sx:{width:"100%",maxWidth:600,height:20,display:"flex",alignItems:"center",gap:"24px",opacity:1},children:l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"6px",height:20,opacity:1},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"14px",lineHeight:"20px",letterSpacing:0,color:"#000000",opacity:1},children:"All Catalogs"}),l.jsx(j,{component:"span",sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#808080",opacity:1},children:n})]})}),y&&l.jsx(j,{color:"error",sx:{mb:0},children:y}),l.jsx(P,{sx:{display:"flex",flexDirection:"column",gap:"8px"},children:w.map(_=>{const I=g===_.id,T=typeof a=="function"?a(_):s[_.id]??_.status??"Active",F=T==="Active";return l.jsxs(cn,{elevation:0,sx:{width:"100%",maxWidth:600,minHeight:106,borderRadius:"12px",border:"1px solid #F1F1F1",padding:"12px 16px",background:"#FFFFFF",display:"flex",alignItems:"flex-start",gap:"16px",opacity:1},children:[l.jsx(P,{sx:{flexShrink:0},children:l.jsx(CN,{})}),l.jsx(P,{sx:{width:368,maxWidth:"100%",minWidth:0,flex:1,display:"flex",flexDirection:"column",gap:"8px",opacity:1},children:I?l.jsxs(l.Fragment,{children:[l.jsx(Ui,{label:"Name",size:"small",value:m.name,onChange:D=>S(U=>({...U,name:D.target.value})),fullWidth:!0,sx:{"& .MuiInputBase-root":{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px"}}}),l.jsx(Ui,{label:"Slug",size:"small",value:m.slug,onChange:D=>S(U=>({...U,slug:D.target.value})),fullWidth:!0,placeholder:"/catalog-slug"})]}):l.jsxs(l.Fragment,{children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"2px"},children:[l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#000000",opacity:1},children:_.name}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:600,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#808080",opacity:1},children:_.slug})]}),l.jsx(P,{sx:{display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap"},children:l.jsxs(P,{sx:L,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(TN,{sx:{fontSize:12,color:"#454545"}})}),l.jsxs(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"},children:[_.productsCount," Products"]})]})}),l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap"},children:[l.jsxs(P,{sx:L,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(PN,{})}),l.jsxs(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"},children:["By ",_.createdBy]})]}),l.jsxs(P,{sx:L,children:[l.jsx(P,{sx:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(cy,{size:12,color:"#454545"})}),l.jsx(j,{sx:{fontFamily:"Inter, sans-serif",fontWeight:400,fontSize:"12px",lineHeight:"16px",letterSpacing:0,color:"#454545"},children:_.date})]})]})]})}),l.jsx(P,{sx:{flexShrink:0},children:I?l.jsxs(Pn,{size:"small",value:m.status?"Active":"Inactive",onChange:D=>S(U=>({...U,status:D.target.value==="Active"})),IconComponent:Nr,sx:{minWidth:80,height:24,borderRadius:"4px",padding:"6px 6px 6px 8px",background:m.status?"#D8FBE3":"#F5F5F5",fontFamily:"Inter, sans-serif",fontWeight:500,fontSize:"10px",lineHeight:"12px",color:"#454545","& .MuiSelect-select":{py:.75},"& .MuiSelect-icon":{width:12,height:12,top:"50%",transform:"translateY(-50%)"}},children:[l.jsx(We,{value:"Active",children:"Active"}),l.jsx(We,{value:"Inactive",children:"Inactive"})]}):l.jsxs(Pn,{value:T,onChange:D=>{if(typeof h!="function"||b)return;const U=D.target.value==="Active";h(_,U)},disabled:b,IconComponent:Nr,sx:{minWidth:80,height:24,borderRadius:"4px",padding:"6px 6px 6px 8px",background:F?"#D8FBE3":"#F5F5F5",fontFamily:"Inter, sans-serif",fontWeight:500,fontSize:"10px",lineHeight:"12px",color:"#454545","& .MuiSelect-select":{py:.75},"& .MuiSelect-icon":{width:12,height:12,top:"50%",transform:"translateY(-50%)"},"& .MuiOutlinedInput-notchedOutline":{border:"none"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}},variant:"outlined",children:[l.jsx(We,{value:"Active",children:"Active"}),l.jsx(We,{value:"Inactive",children:"Inactive"})]})}),l.jsx(P,{sx:{flexShrink:0},children:I?l.jsxs(l.Fragment,{children:[l.jsx(yt,{size:"small","aria-label":"Save catalog",disabled:b,onClick:()=>x(_),sx:{p:0,color:"#454545"},children:l.jsx(IN,{sx:{fontSize:20}})}),l.jsx(Xe,{size:"small",onClick:v,sx:{minWidth:0,px:1,ml:.5},children:"Cancel"})]}):l.jsx(yt,{size:"small","aria-label":"Edit catalog",onClick:()=>C(_),sx:{p:0,width:16,height:16},children:l.jsx(FN,{})})}),l.jsx(P,{sx:{flexShrink:0},children:l.jsx(yt,{size:"small","aria-label":"Delete catalog",onClick:()=>typeof p=="function"?p(_):null,sx:{p:0,width:16,height:16},children:l.jsx(DN,{})})})]},_.id)})}),l.jsxs(P,{sx:M.wrapper,children:[l.jsxs(P,{sx:M.resultsPerPageBox,children:[l.jsx(j,{component:"span",sx:M.resultsPerPageText,children:"Results per page"}),l.jsxs(Pn,{value:i,onChange:_=>typeof d=="function"?d(_):null,IconComponent:Nr,variant:"standard",disableUnderline:!0,sx:M.select,children:[l.jsx(We,{value:5,children:"5"}),l.jsx(We,{value:10,children:"10"}),l.jsx(We,{value:25,children:"25"})]})]}),l.jsxs(P,{sx:M.navBox,children:[l.jsx(yt,{size:"small",disabled:r===0,onClick:()=>typeof c=="function"?c(0):null,sx:M.iconButton,"aria-label":"First page",children:l.jsx(Jd,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:r===0,onClick:()=>typeof c=="function"?c(Math.max(0,r-1)):null,sx:M.iconButton,"aria-label":"Previous page",children:l.jsx(Hi,{sx:{width:16,height:16,opacity:1}})}),l.jsx(j,{component:"span",sx:M.pageText,children:A===0?"0-0 of 0":`${r*i+1}-${Math.min((r+1)*i,A)} of ${A}`}),l.jsx(yt,{size:"small",disabled:r>=O,onClick:()=>typeof c=="function"?c(r+1):null,sx:M.iconButton,"aria-label":"Next page",children:l.jsx(Ot,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:r>=O,onClick:()=>typeof c=="function"?c(O):null,sx:M.iconButton,"aria-label":"Last page",children:l.jsx(Qd,{sx:{width:16,height:16,opacity:1}})})]})]})]})})}const $N=({isOpen:e,onClose:t,onConfirm:n,catalogName:r})=>{const s=On().productSettingModal;return l.jsx(ao,{open:e,onClose:t,"aria-labelledby":"delete-catalog-modal",sx:s.modal,children:l.jsxs(P,{sx:s.container,children:[l.jsx(P,{sx:s.header,children:l.jsxs(j,{sx:{...s.headerTitle,fontSize:22},children:["Are you sure you want to delete this catalog",r?` "${r}"`:"","?"]})}),l.jsxs(P,{sx:{...s.footer,flexDirection:"row",gap:2,justifyContent:"center"},children:[l.jsx(Xe,{variant:"contained",color:"primary",onClick:n,sx:{minWidth:100,mx:4},children:"Yes"}),l.jsx(Xe,{variant:"outlined",color:"primary",onClick:t,sx:{minWidth:100},children:"No"})]})]})})};function zN(e){if(!e)return"";const t=new Date(e),n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return`${t.getDate()} ${n[t.getMonth()]} ${t.getFullYear()}`}function LN(e){if(!e)return null;const t=e.slug,n=typeof t=="string"&&t.startsWith("/")?t:`/${t||""}`;return{...e,slug:n,slugRaw:typeof t=="string"?t.replace(/^\//,""):t||"",productsCount:e.productCount??e.productsCount??0,createdBy:e.createdByName??e.createdBy??"",date:zN(e.createdAt??e.date),createdAt:e.createdAt??e.date,status:e.status===!0?"Active":e.status===!1?"Inactive":e.status||"Active"}}function BN(e){const t=It(),n=on(),{sharedCatalogues:r=[],sharedCataloguesTotal:i=0,sharedCataloguesLoading:s=!1,sharedCataloguesError:a=null}=Je(V=>V.productSettings??{}),{updateCatalogLoading:c=!1,updateCatalogError:d=null}=Je(V=>V.dashboard??{}),[u,p]=z.useState(0),[h,y]=z.useState(10),[b,g]=z.useState({}),[f,m]=z.useState(!1),[S,C]=z.useState(null),[x,v]=z.useState(!1),[w,A]=z.useState("");z.useEffect(()=>{n(Yt({page:u+1,limit:h}))},[n,u,h]),z.useEffect(()=>()=>n({type:"dashboard/clearUpdateCatalogError"}),[n]);const O=z.useMemo(()=>Array.isArray(r)?r.map(LN).filter(Boolean):[],[r]),L=i,M=V=>p(V),_=V=>{const B=Number(V.target.value);y(B),p(0)},I=V=>b[V.id]??V.status,T=z.useCallback(()=>t(-1),[t]),{setSettingTopbarProps:F}=Yi()||{};z.useEffect(()=>{if(F)return F({onBack:T}),()=>F({})},[F,T]);const D=async V=>{const{id:B,name:W,slug:q,status:X}=V;await n(Ho({id:B,name:W,slug:q,status:X})).unwrap(),n(Yt({page:u+1,limit:h}))},U=async(V,B)=>{const W=V.slugRaw??(typeof V.slug=="string"?V.slug.replace(/^\//,""):"")??"";g(q=>({...q,[V.id]:B?"Active":"Inactive"}));try{await n(Ho({id:V.id,name:V.name??"",slug:W,status:B})).unwrap(),n(Yt({page:u+1,limit:h}))}catch{g(q=>({...q,[V.id]:V.status}))}},N=V=>{C(V),m(!0)},$=()=>{m(!1),C(null)},k=async()=>{if(!S?.id){$();return}try{await n(_s(S.id)).unwrap(),A("Catalog delete Successfully"),v(!0),$(),n(Yt({page:u+1,limit:h}))}catch{A("Failed to delete catalog"),v(!0)}};return s&&O.length===0?l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa"},children:l.jsx(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"60vh"},children:l.jsx(mi,{})})}):a&&O.length===0?l.jsx(P,{sx:{minHeight:"100vh",background:"#f7f8fa"},children:l.jsx(P,{sx:{textAlign:"center",py:4},children:l.jsx(j,{color:"error",children:a})})}):l.jsxs(l.Fragment,{children:[l.jsx(_N,{catalogs:O,totalCount:L,page:u,rowsPerPage:h,statusById:b,getStatus:I,onBack:T,onPageChange:M,onRowsPerPageChange:_,onStatusChange:U,onSave:D,onDelete:N,updateCatalogError:d,updateCatalogLoading:c,...e}),l.jsx($N,{isOpen:f,onClose:$,onConfirm:k,catalogName:S?.name}),l.jsx(go,{open:x,autoHideDuration:4e3,onClose:()=>v(!1),message:w,anchorOrigin:{vertical:"top",horizontal:"center"}})]})}const cl=it(l.jsx("path",{d:"M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"}),"ErrorOutline"),jN=it([l.jsx("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"},"0"),l.jsx("path",{d:"M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"},"1")],"AccessTime");function ep(e){return l.jsx(jN,{...e})}function WN({styles:e={},selectedProducts:t=[],data:n,onSelectProduct:r,categoryName:i,showLimitedColumns:s=!1,pagination:a=null,onPageChange:c,onLimitChange:d}){const u=e?.categoryTableAllStore??{},p=e?.categoryTableSingleStore??{},h=e?.categoryTablePagination??{},y=e?.categoryTableShared??{},b=ht("(max-width:900px)"),g=ht("(max-width:400px)"),f=ht("(max-width:550px)"),m=ht("(max-width:770px)"),S=ht("(max-width:650px)"),C=ht("(max-width:500px)"),x=ht("(max-width:400px)"),v=!s,w=v&&m,A=N=>t.some($=>$.id===N.id),[O,L]=z.useState(null),[M,_]=z.useState([]),I=(N,$)=>{L(N.currentTarget),_($)},T=()=>{L(null),_([])},F=!!O,D=v?p.outerCard:u.outerCard,U=v?"6px":"4px";return l.jsx(or,{maxWidth:!1,sx:e.categoryTableContainer,children:l.jsxs(La,{sx:{...e.categoryTable,...D},children:[l.jsx(P,{sx:{...u.categoryNameBox,display:"flex",alignItems:"center",mb:U,boxSizing:"border-box",overflow:"hidden"},children:l.jsx(j,{sx:{...u.categoryNameText,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})}),!(v&&!g)&&l.jsxs(P,{sx:{display:"flex",flexWrap:g&&v?"wrap":"nowrap",alignItems:"center",width:"100%",minWidth:0,...v?p.tableHeader:u.tableHeader,boxSizing:"border-box",gap:g?"8px":v&&b?"12px":"16px"},children:[s?l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",flexShrink:0},children:l.jsx(bt,{checked:n.length>0&&n.every(A),indeterminate:n.some(A)&&!n.every(A),onChange:()=>{n.every(A)?n.forEach(N=>r(N,i,!1)):n.forEach(N=>{A(N)||r(N,i,!0)})},size:"small",sx:y.checkboxHeaderSx,icon:l.jsx("span",{style:y.checkboxIconSpanHeader}),checkedIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})}),indeterminateIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})})})}),l.jsx(P,{sx:{display:"flex",alignItems:"center",minWidth:0,flex:"1 1 0"},children:l.jsx(j,{component:"span",sx:u.headerProduct,children:"Product"})})]}):l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:g?"8px":b?"12px":"16px",flex:"1 1 0",minWidth:0,...v&&!g&&{maxWidth:"40%"}},children:[l.jsx(bt,{checked:n.length>0&&n.every(A),indeterminate:n.some(A)&&!n.every(A),onChange:()=>{n.every(A)?n.forEach(N=>r(N,i,!1)):n.forEach(N=>{A(N)||r(N,i,!0)})},size:"small",sx:y.checkboxHeaderSx,icon:l.jsx("span",{style:y.checkboxIconSpanHeader}),checkedIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})}),indeterminateIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})})}),l.jsx(j,{component:"span",sx:{...p.headerLabel,...p.headerProduct},children:"Product"})]}),!g&&(v?l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{...p.headerStatus,display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0,flex:"0 1 auto"},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Status"})}),l.jsx(P,{sx:{...p.headerPrice,display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0,flex:"0 1 auto"},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Price"})}),l.jsx(P,{sx:{...p.headerStock,display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0,flex:"0 1 auto"},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Stock"})}),l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"12px",minWidth:0,flex:"0 1 auto",...p.headerOffer},children:[l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Offer"}),l.jsx(ol,{sx:{...u.arrowDown,fontSize:12,marginTop:"8px"}})]})]}):l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",flexShrink:0,mr:1,minWidth:64},children:l.jsx(j,{component:"span",sx:u.headerStatusText,children:"Status"})}),!f&&l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",flexShrink:0,mr:2,minWidth:88},children:l.jsx(j,{component:"span",sx:u.headerOsaText,children:"Stock / OSA"})}),l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",flexShrink:0,mr:0,width:20,minWidth:20},children:l.jsx(ol,{sx:{...u.arrowDownAllStore}})})]})]}))]}),(function(){const N=v&&!g,$=n.map((k,V)=>{let B=[];k.offers&&Array.isArray(k.offers)?B=k.offers:k.offer&&typeof k.offer=="string"&&k.offer.includes(`
1581
1581
  `)?B=k.offer.split(`
1582
1582
  `):k.offer&&Array.isArray(k.offer)?B=k.offer:k.offer&&(B=[k.offer]);const W=B[0]||"",q=B.length>1?B.slice(1):[];return l.jsxs(P,{sx:{...v&&!g?{gridColumn:"1 / -1",display:"grid",gridTemplateColumns:"subgrid",gap:"12px",alignItems:"flex-start",boxSizing:"border-box",mt:0,mb:0,width:"100%",maxWidth:"100%",minWidth:0,...p.rowCard,...m&&{height:"auto",minHeight:152}}:{display:"flex",flexDirection:g&&v?"column":"row",alignItems:"flex-start",flexWrap:g&&v?"nowrap":"wrap",...v?p.rowCard:u.rowCard,...w&&{height:"auto",minHeight:152},gap:g?"8px":"16px",boxSizing:"border-box",mt:V===0?.5:0,mb:.5,width:"100%",maxWidth:"100%",minWidth:0}},children:[!(v&&x)&&l.jsx(P,{sx:{display:"flex",alignItems:"flex-start",width:16,minHeight:20,gap:"8px",flexShrink:0},children:l.jsx(bt,{checked:A(k),onChange:()=>r(k,i),size:"small",sx:y.checkboxRowSx,icon:l.jsx("span",{style:y.checkboxIconSpanRow}),checkedIcon:l.jsx("span",{style:y.checkboxRowCheckedIconSpan,children:l.jsx(il,{sx:{fontSize:10,color:"#2563EB",position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"}})})})}),l.jsx(P,{sx:{display:"flex",flexDirection:v&&m?"column":"row",alignItems:v&&m?"flex-start":v?"center":"flex-start",height:v&&!w&&!m?56:void 0,minHeight:56,gap:"16px",minWidth:0,flex:g?"0 0 auto":"1 1 0",width:g||v&&m?"100%":void 0,overflow:w||m?"visible":"hidden",...v?p.productBlock:u.productBlock,...v&&{width:void 0,maxWidth:"100%",flex:g?"0 0 auto":"1 1 0"},...(w||v&&m)&&{height:"auto"},...!v&&!g&&{height:void 0},...!v&&g&&{height:76,minHeight:76,maxHeight:76,overflow:"hidden"}},children:v&&m?l.jsxs(l.Fragment,{children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"row",alignItems:"flex-start",gap:"16px",minWidth:0,width:"100%",flex:"0 0 auto"},children:[x&&l.jsx(P,{sx:{display:"flex",alignItems:"flex-start",width:16,minHeight:20,flexShrink:0},children:l.jsx(bt,{checked:A(k),onChange:()=>r(k,i),size:"small",sx:y.checkboxRowSx,icon:l.jsx("span",{style:y.checkboxIconSpanRow}),checkedIcon:l.jsx("span",{style:y.checkboxRowCheckedIconSpan,children:l.jsx(il,{sx:{fontSize:10,color:"#2563EB",position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"}})})})}),l.jsx(P,{sx:{...u.imageBox,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0},children:k.productImage?l.jsx(Ar,{src:k.productImage,alt:k.productName,sx:y.avatar}):l.jsx(Ar,{sx:y.avatarPlaceholder,children:k.productName&&k.productName[0]})}),l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"4px",flex:1,minWidth:0,maxWidth:"100%",overflow:"hidden"},children:[l.jsx(j,{sx:{...u.productName,wordBreak:"break-word",overflowWrap:"break-word",whiteSpace:"normal",overflow:"hidden",fontSize:"12px",lineHeight:"16px"},children:k.productName}),l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap",minWidth:0,overflow:"hidden"},children:[l.jsx(j,{sx:{...u.productMeta,fontSize:"10px",lineHeight:"12px",overflow:"hidden",textOverflow:"ellipsis"},children:k.productWeight}),k.categoryName&&l.jsxs(l.Fragment,{children:[l.jsx(j,{component:"span",sx:{...u.productMeta,fontSize:"10px",lineHeight:"12px"},children:"•"}),l.jsx(j,{component:"span",sx:{...u.productMeta,fontSize:"10px",lineHeight:"12px"},children:k.categoryName})]})]}),l.jsxs(j,{sx:{...u.productSku,fontSize:"10px",lineHeight:"12px",overflow:"hidden",textOverflow:"ellipsis"},children:["SKU: ",k.sku]})]})]}),S?l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"24px",width:"100%",ml:x?"32px":0},children:[x&&l.jsxs(P,{sx:{display:"flex",flexDirection:"row",gap:"50px",alignItems:"center",flexWrap:"wrap",width:"100%"},children:[l.jsx(P,{component:"span",sx:k.status===!0?u.statusActiveBox:u.statusNoStockBox,children:k.status===!0?"Active":"No Stock"}),l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"4px",...p.priceBlock},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px"},children:[l.jsxs(j,{sx:p.priceText,children:["₹",k.price]}),l.jsx(P,{sx:{...p.clockIcon,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:l.jsx(ep,{sx:p.clockIconSx})})]}),k.mrp&&l.jsxs(j,{sx:y.mrpText,children:["₹",k.mrp]}),k.discount&&l.jsx(j,{sx:y.discountText,children:k.discount})]})]}),C&&!x&&l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"4px",...p.priceBlock},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px"},children:[l.jsxs(j,{sx:p.priceText,children:["₹",k.price]}),l.jsx(P,{sx:{...p.clockIcon,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:l.jsx(ep,{sx:p.clockIconSx})})]}),k.mrp&&l.jsxs(j,{sx:y.mrpText,children:["₹",k.mrp]}),k.discount&&l.jsx(j,{sx:y.discountText,children:k.discount})]}),l.jsxs(P,{sx:{display:"flex",flexDirection:"row",gap:"50px",alignItems:"center",flexWrap:"wrap",width:"100%"},children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"2px",flexShrink:0},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:0},children:[k.stock===0&&l.jsx(ji,{title:"No stock",children:l.jsx(cl,{sx:y.errorIcon})}),l.jsx(j,{component:"span",sx:u.stockValue,children:k.stock}),l.jsx(j,{component:"span",sx:u.osaValue,children:k.quantity?`/${k.quantity}`:""})]}),(()=>{const X=typeof k.osa=="number"?k.osa:k.osa??0,G=Number(X),Q=G<50;return l.jsxs(j,{sx:{...u.onShelfText,fontSize:"10px",color:p.onShelfPercentNormal?.color||"#454545"},children:[l.jsxs(P,{component:"span",sx:Q?{color:p.onShelfPercentRed?.color||"#d32f2f"}:{},children:[Math.round(G),"%"]}),l.jsx(P,{component:"span",sx:{color:p.onShelfSpan?.color||"#808080"},children:" on shelf"})]})})()]}),l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:0,flex:1,minWidth:0},children:[l.jsx(j,{sx:{...p.offerText,whiteSpace:"pre-line",fontSize:"12px",lineHeight:"16px"},children:W}),q.length>0&&l.jsxs(j,{sx:y.moreOffersLink,onClick:X=>I(X,B),children:["+",q.length," more"]})]})]})]}):l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:0,width:"100%"},children:[l.jsx(j,{sx:{...p.offerText,whiteSpace:"pre-line",fontSize:"12px",lineHeight:"16px"},children:W}),q.length>0&&l.jsxs(j,{sx:y.moreOffersLink,onClick:X=>I(X,B),children:["+",q.length," more"]})]})]}):l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{...u.imageBox,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexShrink:0,mb:0},children:k.productImage?l.jsx(Ar,{src:k.productImage,alt:k.productName,sx:y.avatar}):l.jsx(Ar,{sx:y.avatarPlaceholder,children:k.productName&&k.productName[0]})}),l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"4px",flex:1,minWidth:0,maxWidth:"100%",overflow:"hidden",...!v&&g&&{height:76,minHeight:76,maxHeight:76}},children:[l.jsx(j,{sx:{...u.productName,wordBreak:"break-word",overflowWrap:"break-word",whiteSpace:"normal",overflow:"hidden",fontSize:"12px",lineHeight:"16px",...!v&&g&&{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"}},children:k.productName}),l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px",minWidth:0,overflow:"hidden",flexWrap:!v&&g?"nowrap":"wrap"},children:[l.jsx(j,{sx:{...u.productMeta,fontSize:"10px",lineHeight:"12px",overflow:"hidden",textOverflow:"ellipsis",flexShrink:!v&&g?0:void 0},children:k.productWeight}),k.categoryName&&l.jsxs(l.Fragment,{children:[l.jsx(j,{component:"span",sx:{...u.productMeta,fontSize:"10px",lineHeight:"12px",flexShrink:0},children:"•"}),l.jsx(j,{component:"span",sx:{...u.productMeta,fontSize:"10px",lineHeight:"12px",...!v&&g&&{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",flex:"1 1 0"}},children:k.categoryName})]})]}),l.jsxs(j,{sx:{...u.productSku,fontSize:"10px",lineHeight:"12px",overflow:"hidden",textOverflow:"ellipsis",...!v&&g&&{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"}},children:["SKU: ",k.sku]})]})]})}),(v&&!g||!v&&!g)&&l.jsx(P,{sx:{display:"flex",alignItems:"flex-start",justifyContent:v&&!g?"center":void 0,...v?p.statusBlock:{},flexShrink:0,minWidth:!v&&!g?64:0,width:g?"100%":void 0,mt:g?1:0,mr:!v&&!g?4:0,...v&&!g&&{alignSelf:"flex-start",marginTop:"8px"}},children:l.jsx(P,{component:"span",sx:k.status===!0?u.statusActiveBox:u.statusNoStockBox,children:k.status===!0?"Active":"No Stock"})}),!v&&!f&&l.jsxs(l.Fragment,{children:[l.jsxs(P,{sx:{display:"flex",flexDirection:"column",gap:"4px",alignItems:"flex-start",flexShrink:0,minWidth:88,width:g?"100%":void 0,mt:g?1:0,ml:g?0:.5,textAlign:"left"},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"flex-start",gap:0},children:[k.stock===0&&l.jsx(ji,{title:"No stock",children:l.jsx(cl,{sx:y.errorIcon})}),l.jsx(j,{component:"span",sx:u.stockValue,children:k.stock}),l.jsx(j,{component:"span",sx:u.osaValue,children:k.quantity?`/${k.quantity}`:""})]}),(()=>{const X=Number(typeof k.osa=="number"?k.osa:k.osa??0),G=X<50;return l.jsxs(j,{sx:{...u.onShelfText,color:"#808080",textAlign:"left"},children:[l.jsxs(P,{component:"span",sx:G?{color:"#d32f2f"}:{},children:[Math.round(X),"%"]})," on shelf"]})})()]}),l.jsx(P,{sx:{width:20,flexShrink:0,minWidth:20}})]}),!v&&f&&l.jsx(P,{sx:{display:"flex",flexDirection:"column",gap:"4px",alignItems:"flex-start",width:"100%",mt:1,ml:"32px",...g&&{minHeight:48}},children:l.jsxs(P,{sx:{display:"flex",alignItems:"flex-start",gap:12,flexWrap:g?"nowrap":"wrap"},children:[g&&l.jsx(P,{component:"span",sx:k.status===!0?u.statusActiveBox:u.statusNoStockBox,children:k.status===!0?"Active":"No Stock"}),l.jsxs(P,{sx:{display:"flex",flexDirection:"column",alignItems:"flex-start",gap:0},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"flex-start",gap:0},children:[k.stock===0&&l.jsx(ji,{title:"No stock",children:l.jsx(cl,{sx:y.errorIcon})}),l.jsx(j,{component:"span",sx:u.stockValue,children:k.stock}),l.jsx(j,{component:"span",sx:u.osaValue,children:k.quantity?`/${k.quantity}`:""})]}),(()=>{const X=Number(typeof k.osa=="number"?k.osa:k.osa??0),G=X<50;return l.jsxs(j,{sx:{...u.onShelfText,color:"#808080",textAlign:"left"},children:[l.jsxs(P,{component:"span",sx:G?{color:"#d32f2f"}:{},children:[Math.round(X),"%"]})," on shelf"]})})()]})]})}),v&&!C&&l.jsxs(P,{sx:{display:"flex",flexDirection:"column",...p.priceBlock,flexShrink:0,minWidth:0,flex:"0 1 auto",width:g?"100%":void 0,mt:g?1:0},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"4px"},children:[l.jsxs(j,{sx:p.priceText,children:["₹",k.price]}),l.jsx(P,{sx:{...p.clockIcon,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:l.jsx(ep,{sx:p.clockIconSx})})]}),k.mrp&&l.jsxs(j,{sx:y.mrpText,children:["₹",k.mrp]}),k.discount&&l.jsx(j,{sx:y.discountText,children:k.discount})]}),v&&!S&&l.jsxs(P,{sx:{display:"flex",flexDirection:"column",...p.stockBlock,flexShrink:0,minWidth:0,width:g?"100%":void 0,mt:g?1:0},children:[l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:0},children:[k.stock===0&&l.jsx(ji,{title:"No stock",children:l.jsx(cl,{sx:y.errorIcon})}),l.jsx(j,{component:"span",sx:u.stockValue,children:k.stock}),l.jsx(j,{component:"span",sx:u.osaValue,children:k.quantity?`/${k.quantity}`:""})]}),(()=>{const X=typeof k.osa=="number"?k.osa:k.osa??0,G=Number(X),Q=G<50;return l.jsxs(j,{sx:{...u.onShelfText,fontSize:"10px",color:p.onShelfPercentNormal.color},children:[l.jsxs(P,{component:"span",sx:Q?{color:p.onShelfPercentRed.color}:{},children:[Math.round(G),"%"]})," ",l.jsx(P,{component:"span",sx:{color:p.onShelfSpan.color},children:"on shelf"})]})})()]}),v&&!m&&l.jsxs(P,{sx:{display:"flex",flexDirection:"column",...p.offerBlock,minWidth:0,flex:"0 1 auto",width:g?"100%":void 0,mt:g?1:0},children:[l.jsx(j,{sx:{...p.offerText,whiteSpace:"pre-line"},children:W}),q.length>0&&l.jsxs(j,{sx:y.moreOffersLink,onClick:X=>I(X,B),children:["+",q.length," more"]})]})]},k.id||V)});return N?l.jsxs(P,{sx:{display:"grid",gridTemplateColumns:x?"minmax(0, 1fr)":C?"auto minmax(0, 1fr) auto":S?"auto minmax(0, 1fr) auto auto":m?"auto minmax(0, 1fr) auto auto auto":"auto minmax(0, 1fr) auto auto auto auto",columnGap:"12px",rowGap:"4px",alignItems:"start",width:"100%",minWidth:0,boxSizing:"border-box"},children:[l.jsx(P,{sx:{gridColumn:"1 / -1",display:"grid",gridTemplateColumns:"subgrid",gap:"12px",alignItems:"center",...p.tableHeader,boxSizing:"border-box"},children:x?l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"12px",minWidth:0},children:[l.jsx(bt,{checked:n.length>0&&n.every(A),indeterminate:n.some(A)&&!n.every(A),onChange:()=>{n.every(A)?n.forEach(k=>r(k,i,!1)):n.forEach(k=>{A(k)||r(k,i,!0)})},size:"small",sx:y.checkboxHeaderSx,icon:l.jsx("span",{style:y.checkboxIconSpanHeader}),checkedIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})}),indeterminateIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})})}),l.jsx(j,{component:"span",sx:{...p.headerLabel,...p.headerProduct},children:"Product"})]}):l.jsxs(l.Fragment,{children:[l.jsx(P,{sx:{display:"flex",alignItems:"center",flexShrink:0},children:l.jsx(bt,{checked:n.length>0&&n.every(A),indeterminate:n.some(A)&&!n.every(A),onChange:()=>{n.every(A)?n.forEach(k=>r(k,i,!1)):n.forEach(k=>{A(k)||r(k,i,!0)})},size:"small",sx:y.checkboxHeaderSx,icon:l.jsx("span",{style:y.checkboxIconSpanHeader}),checkedIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})}),indeterminateIcon:l.jsx("span",{style:y.checkboxCheckedIconSpan,children:l.jsx("span",{style:y.checkboxCheckedIconInner})})})}),l.jsx(P,{sx:{display:"flex",alignItems:"center",minWidth:0},children:l.jsx(j,{component:"span",sx:{...p.headerLabel,...p.headerProduct},children:"Product"})}),!x&&l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"center",minWidth:0},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Status"})}),!C&&l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Price"})}),!S&&l.jsx(P,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-start",minWidth:0},children:l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Stock"})}),!m&&l.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:"12px",minWidth:0,...p.headerOffer},children:[l.jsx(j,{component:"span",sx:{...p.headerLabel},children:"Offer"}),l.jsx(ol,{sx:{...u.arrowDown,fontSize:12,marginTop:"8px",marginLeft:"20px"}})]})]})}),$]}):$})(),l.jsxs(kd,{open:F,anchorEl:O,onClose:T,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:y.popoverPaper},children:[l.jsx(j,{sx:y.popoverTitle,children:"Offers"}),M.map((N,$)=>l.jsxs(j,{sx:y.popoverItem,children:[$+1,". ",N]},$))]}),a&&typeof c=="function"&&typeof d=="function"&&l.jsxs(P,{sx:{...h.wrapper,width:"100%",maxWidth:"100%",flexWrap:"wrap"},children:[l.jsxs(P,{sx:h.resultsPerPageBox,children:[l.jsx(j,{component:"span",sx:h.resultsPerPageText,children:"Results per page"}),l.jsx(Pn,{value:a.limit??10,onChange:N=>d(Number(N.target.value)),IconComponent:Nr,variant:"standard",disableUnderline:!0,sx:h.select,children:[5,10,20,50].map(N=>l.jsx(We,{value:N,children:N},N))})]}),l.jsxs(P,{sx:h.navBox,children:[l.jsx(yt,{size:"small",disabled:(a.currentPage??1)<=1,onClick:()=>c(1),sx:h.iconButton,title:"First page",children:l.jsx(Jd,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:(a.currentPage??1)<=1,onClick:()=>c((a.currentPage??1)-1),sx:h.iconButton,title:"Previous page",children:l.jsx(Hi,{sx:h.paginationIcon??y.paginationIcon})}),l.jsx(j,{component:"span",sx:h.pageText,children:(a.totalCount??0)===0?"0 of 0":`${((a.currentPage??1)-1)*(a.limit??10)+1}-${Math.min((a.currentPage??1)*(a.limit??10),a.totalCount??0)} of ${a.totalCount??0}`}),l.jsx(yt,{size:"small",disabled:!(a.hasNextPage??!1)||(a.currentPage??1)>=(a.totalPages??1),onClick:()=>c((a.currentPage??1)+1),sx:h.iconButton,title:"Next page",children:l.jsx(Ot,{sx:{width:16,height:16,opacity:1}})}),l.jsx(yt,{size:"small",disabled:!(a.hasNextPage??!1)||(a.currentPage??1)>=(a.totalPages??1),onClick:()=>c(a.totalPages??1),sx:h.iconButton,title:"Last page",children:l.jsx(Qd,{sx:h.paginationIcon??y.paginationIcon})})]})]})]})})}const VN={category:"all",status:"all",search:"",store:[]},UN=()=>{const e=on(),t=It(),n=Et(),[r]=Pb(),i=r.get("categoryName"),s=On(),a=s.categoryDetail,[c,d]=z.useState(()=>({...VN,...n.state?.filters||{}})),u=(Array.isArray(n.state?.selectedProducts)?n.state.selectedProducts:[]).reduce((ie,ue)=>{const ve=(ue.categoryName||ue.category||i||"").toString().trim();if(!ve)return ie;const je=ie[ve]||[];return je.some(_e=>_e.id===ue.id)?ie[ve]=je:ie[ve]=[...je,ue],ie},{}),[p,h]=z.useState(u),[,y]=z.useState(null),[b,g]=z.useState(!1),[f,m]=z.useState([]),[S,C]=z.useState(!1),[x,v]=z.useState(!1),{integrationData:w,companyId:A,loading:O,productsLoading:L}=Je(K=>K.dashboard),M=z.useRef(!1),_=z.useRef(!1);z.useEffect(()=>{!A&&!M.current&&(M.current=!0,e(Vo()))},[e,A]);const I=z.useMemo(()=>w&&typeof w=="object"&&Object.keys(w).length>0?{matched:!0,error:"",apiResponse:w,loading:!1}:{matched:!1,error:"No active integration found",apiResponse:null,loading:!1},[w]),T=Je(K=>K.dashboard),{products:F=[],stores:D=[],pagination:U={}}=T||{},{currentPage:N=1,limit:$=10,totalCount:k=0,totalPages:V=1,hasNextPage:B=!1}=U,{sharedCatalogues:W=[],sharedCataloguesTotal:q=0,lastStableActiveCatalogsCount:X=null}=Je(K=>K.productSettings??{}),G=z.useMemo(()=>Array.isArray(W)?W.filter(K=>K.status===!0).length:0,[W]),ee=q>0&&W.length>=q?G:X??G,oe=z.useMemo(()=>{if(!i||!Array.isArray(F))return[];const K=i.trim().toLowerCase();return F.filter(ie=>{const ue=(ie.categoryName||ie.category||"").toString().trim().toLowerCase();return ue&&ue===K}).map(ie=>({...ie,catalogProductId:ie.productId||ie.id,id:ie.id||ie.sku||ie.productName}))},[F,i]),le=oe.length>0,ae=z.useMemo(()=>{if(!oe||oe.length===0)return;const K=oe.map(ie=>Number(ie.price??ie.sellingPrice??ie.mrp)).filter(ie=>Number.isFinite(ie)&&ie>=0);if(K.length!==0)return{min:Math.min(...K),max:Math.max(...K)}},[oe]),re=Array.isArray(F)&&F.length>0,ce=Array.isArray(c.store)?c.store:[],he=!(ce.length===1&&ce[0]!=="all"),de=K=>{K.preventDefault(),t("/settings",{state:{tenantIntegrationData:I.apiResponse}})},ge=z.useMemo(()=>D.length>0?D:[{id:"all",name:"All Stores",storeCode:"all"}],[D]),ze=z.useCallback(K=>{d(K)},[d]),Ee=z.useCallback((K={})=>{const ie=Array.isArray(c.store)?c.store:[],ue={page:N,limit:$,...K};if(i&&i.trim()&&(ue.categoryName=i.trim()),ie.length>0&&!ie.includes("all")){const ve=ie.map(je=>D.find(Ye=>Ye.id===je)?.storeCode).filter(Boolean);ve.length>0&&(ue.storeCode=ve.join(","))}return(c.status==="active"||c.status==="inactive")&&(ue.status=c.status==="active"),(c.stock==="inStock"||c.stock==="outOfStock")&&(ue.inStock=c.stock==="inStock"),typeof c.minPrice=="number"&&Number.isFinite(c.minPrice)&&(ue.minPrice=c.minPrice),typeof c.maxPrice=="number"&&Number.isFinite(c.maxPrice)&&(ue.maxPrice=c.maxPrice),c.search!=null&&String(c.search).trim()!==""&&(ue.search=String(c.search).trim()),ue},[i,N,$,c.store,c.status,c.stock,c.minPrice,c.maxPrice,c.search,D]),me=K=>{e(zn(Ee({page:K})))},De=K=>{e(zn(Ee({page:1,limit:K})))},Le=z.useCallback((K,ie={})=>{const ue=Array.isArray(c.store)?c.store:[],ve={page:1,limit:5e3,...ie};if(K&&String(K).trim()!==""&&(ve.categoryName=String(K).trim()),ue.length>0&&!ue.includes("all")){const je=ue.map(_e=>D.find(Se=>Se.id===_e)?.storeCode).filter(Boolean);je.length>0&&(ve.storeCode=je.join(","))}return c.search!=null&&String(c.search).trim()!==""&&(ve.search=String(c.search).trim()),ve},[c.store,c.search,D]),Ne=z.useCallback(async()=>{const ie=(Array.isArray(n.state?.selectedCategories)?n.state.selectedCategories:[]).map(we=>(we?.categoryName??we?.name??"").toString().trim()).filter(Boolean),ue=Array.isArray(p[i])?p[i]:[],ve=[];for(const we of ie){if(we===i){ue.length>0&&ve.push(ue);continue}try{const Be=Le(we),Ct=await e(Ms(Be)).unwrap().catch(()=>({})),rt=Array.isArray(Ct?.data)?Ct.data:Array.isArray(Ct?.products)?Ct.products:Array.isArray(Ct)?Ct:[];ve.push(rt)}catch{ve.push([])}}ue.length>0&&!ie.includes(i)&&ve.push(ue);const je=new Set(ie);Object.keys(p||{}).forEach(we=>{if(we===i||je.has(we))return;const Be=p[we];Array.isArray(Be)&&Be.length>0&&ve.push(Be)});const _e=ve.flat().filter(Boolean),Ye=new Set,Se=_e.map(we=>({...we,catalogProductId:we?.productId??we?.catalogProductId??we?.id,id:we?.id||we?.sku||we?.productName})).filter(we=>{const Be=(we?.productId||we?.id||we?.sku||we?.productName||"").toString();return!Be||Ye.has(Be)?!1:(Ye.add(Be),!0)});m(Se),g(!0)},[e,i,n.state,p,Le]),pe=z.useRef(null),Ve=z.useRef(null);z.useEffect(()=>{if(!A)return;const K=Array.isArray(c.store)?c.store:[],ie={page:N,limit:$};if(i&&i.trim()&&(ie.categoryName=i.trim()),K.length>0&&!K.includes("all")){const ve=K.map(je=>D.find(Ye=>Ye.id===je)?.storeCode).filter(Boolean);ve.length>0&&(ie.storeCode=ve.join(","))}(c.status==="active"||c.status==="inactive")&&(ie.status=c.status==="active"),(c.stock==="inStock"||c.stock==="outOfStock")&&(ie.inStock=c.stock==="inStock"),typeof c.minPrice=="number"&&Number.isFinite(c.minPrice)&&(ie.minPrice=c.minPrice),typeof c.maxPrice=="number"&&Number.isFinite(c.maxPrice)&&(ie.maxPrice=c.maxPrice),c.search!=null&&String(c.search).trim()!==""&&(ie.search=String(c.search).trim());const ue=JSON.stringify(ie);pe.current!==ue&&(pe.current=ue,e(zn(ie)))},[A,i,N,$,c.store,c.status,c.stock,c.minPrice,c.maxPrice,c.search,e,D]);const Ie=(K,ie)=>{h(ue=>{const ve=ue[ie]||[];let je;return ve.some(_e=>_e.id===K.id)?je=ve.filter(_e=>_e.id!==K.id):je=[...ve,K],{...ue,[ie]:je}}),y(ie)};z.useEffect(()=>{if(_.current||!i||!Array.isArray(oe)||oe.length===0||!(Array.isArray(n.state?.selectedCategories)?n.state.selectedCategories:[]).map(ve=>ve?.categoryName??ve?.name??ve).filter(Boolean).includes(i))return;if((p[i]||[]).length>0){_.current=!0;return}queueMicrotask(()=>{h(ve=>({...ve,[i]:oe}))}),_.current=!0},[i,oe,p,n.state?.selectedCategories]),z.useEffect(()=>{A&&(e(zt(A)),e(Uo()),i&&i.trim()&&e(Fs({categoryName:i.trim()})),n.state?.filters||(i&&i.trim()?e(zn({categoryName:i.trim(),page:1,limit:10})):e(zn({page:1,limit:10}))),e(Yt({page:1})))},[e,A,i,n.state?.filters]),z.useEffect(()=>{if(!A||q<=0)return;(Array.isArray(W)?W.length:0)<q&&e(Yt({page:1,limit:q}))},[A,q,W?.length,e,W]);const se=Array.isArray(n.state?.selectedCategories)?n.state.selectedCategories:[],ne=p[i]||[],xe=le&&ne.length===oe.length,Z=new Map(se.map(K=>{const ie=(K?.categoryName??K?.name??"").toString().trim();return ie?[ie,K]:null}).filter(Boolean));if(i){const K=i.toString().trim();K&&(xe?Z.has(K)||Z.set(K,{categoryName:K}):Z.delete(K))}const fe=Array.from(Z.values()),{setTopbarProps:ye}=Yi()||{};return z.useEffect(()=>{if(ye)return ye({filters:c,onFilterChange:ze,styles:a.topBar,stores:ge,tenantStatus:I,hasProducts:re,priceRange:ae,showBackButton:!0,backTo:"/",backState:{selectedCategories:fe,selectedProducts:Object.values(p||{}).flat()}}),()=>ye({})},[ye,c,ze,a.topBar,ge,I,re,ae,fe,p]),l.jsx(l.Fragment,{children:l.jsxs(P,{sx:a.contentWrapper??{marginTop:0,position:"relative",zIndex:0},children:[O||!A?l.jsx(mo,{text:i?"Fetching Products":"Fetching",fullScreen:!1}):i?i&&L?l.jsx(mo,{text:"Fetching Products",fullScreen:!1}):le?l.jsxs(P,{sx:a.root,children:[l.jsxs(or,{ref:Ve,maxWidth:"lg",sx:{width:"100%",px:{xs:1,sm:2,md:4},display:"flex",flexDirection:"column",alignItems:"stretch"},children:[l.jsx(ey,{productState:T,categoryName:i,categoryProductCount:oe.length,activeCatalogsCount:ee,onManageClick:()=>t("/catalogs/manage-shared"),matchHomePageLayout:!0}),l.jsx(WN,{data:oe,styles:a,selectedProducts:p[i]||[],onSelectProduct:Ie,categoryName:i,showLimitedColumns:he,pagination:{currentPage:N,limit:$,totalCount:k,totalPages:V,hasNextPage:B},onPageChange:me,onLimitChange:De})]}),l.jsx(ry,{containerRef:Ve,onPromoPrint:Ne,onCreateCatalog:()=>C(!0),onOsaRequest:()=>v(!0),selectedProducts:Object.values(p||{}).flat(),selectedCategories:fe})]}):l.jsx(P,{sx:a.loadingBox??{minHeight:300,display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(j,{sx:s?.emptyProduct&&s.emptyProduct.title||{fontSize:"16px",fontWeight:600,color:"#1a1a1a"},children:`No products found in the "${i}" category.`})}):l.jsx(Vd,{handleStartSyncing:de,loading:!1}),l.jsx(ly,{open:b,onClose:()=>{g(!1),m([])},selectedProducts:f},b?"open":"closed"),l.jsx(iy,{open:S,onClose:()=>C(!1),stores:ge,selectedProducts:Object.values(p||{}).flat(),selectedCategories:fe,onCreateSuccess:K=>{h(ie=>({...ie,[i]:[]})),C(!1),K&&t("/",{state:{catalogCreated:!0,catalogSlug:K}})}}),l.jsx(sy,{open:x,onClose:()=>v(!1),stores:ge,selectedProducts:Object.values(p||{}).flat(),selectedCategories:fe,onSuccess:()=>h(K=>({...K,[i]:[]}))})]})})};function HN(){return l.jsx(sb,{children:l.jsxs(ar,{element:l.jsx(bI,{}),children:[l.jsx(ar,{path:"/",element:l.jsx(qI,{})}),l.jsx(ar,{path:"/category",element:l.jsx(UN,{})}),l.jsx(ar,{path:"/product-setting",element:l.jsx(tN,{})}),l.jsx(ar,{path:"/products/settings/ftp-sync",element:l.jsx(SN,{})}),l.jsx(ar,{path:"/catalogs/manage-shared",element:l.jsx(BN,{})})]})})}function RN({StoresModal:e,storesModalProps:t,onStoreSelect:n}){return l.jsx(HN,{StoresModal:e,storesModalProps:t,onStoreSelect:n})}const qN=()=>l.jsx(mo,{text:"Fetching",fullScreen:!0});return({apiUrl:e,authToken:t,basePath:n="/",StoresModal:r,storesModalProps:i,onStoreSelect:s})=>l.jsx("div",{style:{width:"100%",minHeight:"100vh"},children:l.jsx(N1,{apiUrl:e,authToken:t,children:l.jsx(Qb,{store:bf,children:l.jsx(o0.PersistGate,{loading:l.jsx(qN,{}),persistor:O1,children:l.jsx(Sb,{basename:n,children:l.jsx(RN,{StoresModal:r,storesModalProps:i,onStoreSelect:s})})})})})})}));
1583
1583
  //# sourceMappingURL=product-app.umd.js.map