1import{oI as qe,g as A,a_ as se,r as l,aT as de,j as e,qS as K,qd as Se,qe as _e,o as G,kC as ue,m as Y,k as Ge,l as Ve,cV as we,C as le,d as Te,bj as ze,R as X,B as H,T as ee,t as U,ag as Ue,ah as Fe,ai as V,aB as De,N as pe,aE as ye,aF as ge,aG as he,fg as Ke,ay as me,fM as Qe,h as Ce,b as Xe,I as Je,fJ as Ye,e8 as Ze,az as J,P as Q,aw as ke,ax as Ie,af as Re,dH as et,qM as tt,j_ as at,au as nt,ac as st}from"./index-DD7wEX2k.js";import{P as it}from"./Page-mik8EZ_Q.js";import{Q as ot,a as lt}from"./QueryClientProvider-Dzw9-502.js";import{c as te}from"./react-router-dom.min-Caf_HWK8.js";import{d as Ee}from"./DoubleArrow-C2cCUJ1u.js";import{d as rt}from"./AddCircleOutline-COf8fMgR.js";import{d as ct}from"./FileCopyOutlined-CsLkg8dP.js";import{f as dt,g as ut}from"./utils-Bgys39Sh.js";import{c as xe,d as pt,g as gt}from"./constant-DwQ-lYYh.js";import{C as Me}from"./Card-CU05tOYa.js";import{d as ht}from"./ArrowDropDown-AeO9ZKDt.js";import{d as ft}from"./ArrowDropUp-xVit32Pr.js";import{S as mt}from"./ActionButtonMenu-BC9lDWO8.js";import{C as yt}from"./CustomPagination-BHCaCTvk.js";import{C as oe}from"./CustomLoadingButton-DzS_9QXf.js";import{d as Ct}from"./Add-9Qks_6Vu.js";import{d as xt}from"./Info-OZvC33_z.js";import{D as vt,C as bt,P as jt}from"./react-beautiful-dnd.esm-Cq-87PJT.js";import{A as ne}from"./Autocomplete-w5JONlgQ.js";import{d as St}from"./DragIndicator-HflC0EXH.js";import{T as Oe}from"./TableContainer-BUx5ZMeU.js";import{d as _t,I as kt,a as It,b as Lt,c as Pt}from"./index-q1lL6yK7.js";import{S as ce}from"./Grid-eV9hG1VW.js";import{I as wt,F as Tt}from"./ImportLanguageWrapper-DENdKda1.js";import"./Publish-JkXB9gP0.js";import"./ToggleOn-DyW7ZvlH.js";import"./Delete-TaFDY8Lv.js";import"./Update-CQ15_MJp.js";import"./link-B9vAowY9.js";import"./memoize-one.esm-CcMeOnPo.js";
1import"./usePaperThemeBackground-Bg5016l_.js";import"./ListingDetailChannel-DS267EEK.js";import"./formik.esm-y-epKQ_W.js";import"./toString-BpP3vzIR.js";import"./Text-zCOVi-Ia.js";import"./formik-material-ui.es6-Brkbu6Gk.js";import"./RadioGroup-DH1Vw7cH.js";import"./RadioGroupContext-CcoEOJr4.js";import"./Switch-y6CmP1sJ.js";import"./Lazy-B4elB764.js";import"./Help-nbKtWl93.js";import"./Attributes-DjVLZtKp.js";import"./TableListingImage-Cey2QcV2.js";import"./CopyComponent-Bam8Kwx6.js";import"./OpenModal80-DXvSOxil.js";import"./TabLabelCustom-bw2nSDOa.js";import"./VideoDialog-CarNDfsd.js";import"./YouTube-D6acImqD.js";import"./FeedTableLogButton-Bwhn_acc.js";import"./ArrowBack-DPKRexet.js";import"./FeedGuideButton-DuiK-byC.js";import"./HelpOutlineOutlined-BibOM1T3.js";/* empty css */import"./FeedHelper-MRUQ0M26.js";const zt={categoryList:[],setList:()=>{},addCategory:()=>{},deleteSingleCategory:()=>Promise.resolve(),deleteSpecial:()=>{},activate:()=>{},deactivate:()=>{},page:0,setPage:()=>{},limit:0,setLimit:()=>{},tableRef:null,resetChecked:()=>{},loading:!1,firstIndex:0,lastIndex:0,getList:()=>Promise.resolve(),setLoading:()=>{},shouldScrollRef:null,uncategorizedItems:[],setItems:()=>{},itemPage:1,setItemPage:()=>{},getItems:()=>Promise.resolve(),itemLoading:!1,setItemLoading:()=>{},count:0,setCount:()=>{},counting:!1,setCounting:()=>{},uncategorizedTabCount:0,setTabCount:()=>{}},N=l.createContext(zt),Ft={checked:!1,field:["",""],filter:["contains","contains"],value:["",""],category:{id:"",path:""},items:0,either:"if",type:"category",active:!0,added:!0},Dt=t=>t.map(i=>{var f,a,o,m;return{active:i.active,checked:!1,category:i.category,id:i.id,_id:i._id,type:i.type,either:i.conditions.length===2?"and":"if",items:i.count||0,field:[i.conditions[0].field,((f=i.conditions[1])==null?void 0:f.field)??""],filter:[i.conditions[0].filter,((a=i.conditions[1])==null?void 0:a.filter)??"contains"],value:[i.conditions[0].value,((o=i.conditions[1])==null?void 0:o.value)??""],status:i.status,smart:i.smart,...i.smart?{value_label:[i.conditions[0].value_label,((m=i.conditions[1])==null?void 0:m.value_label)??""]}:{}}}),Rt=({children:t})=>{const c=parseInt(localStorage.getItem("rowPerPage"))||qe,{feed_skus:i}=A(F=>{var P;return(P=F==null?void 0:F.account)==null?void 0:P.user}),{tableFeedList:f}=A(F=>F==null?void 0:F.feed),a=f.length,{id:o}=se(),[m,n]=l.useState([]),[h,_]=l.useState(0),[v,L]=l.useState(c),[d,S]=l.useState(!0),[z,w]=l.useState(!1),[j,x]=l.useState(!1),[g,r]=l.useState(i||0),[p,I]=l.useState([]),[s,b]=l.useState(1),[u,y]=l.useState(0),D=h*v,E=h*v+v,k=l.useRef(null),T=l.useRef(!1),M=l.useRef(null),{enqueueSnackbar:Z}=de();l.useEffect(()=>{T.current&&k.current&&(k.current.scrollTop=k.current.scrollHeight,T.current=!1)},[m]);const W=async(F="",P=[])=>{S(!0);try{await K.get.getFeedCategoriesList(o).then(R=>{if(R&&R.status<400){let $=Dt(R.data.data);n(O=>{switch(F){case"single":return[...$,...O.filter(B=>B.added)];case"multiple":return[...$,...O.filter(B=>B.added).filter(B=>!P.includes(B.uuid))];default:return $}});const q=$.length===0?"noCate":"";if(F==="firstRender"&&ae({},q),$.some(O=>O.status==="counting")){const O=async()=>{const B=await K.get.getFeedCategoriesList(o);B&&B.status<400&&(n(fe=>fe.map(ie=>{const re=B.data.data.find(je=>je._id===ie._id||je.id===ie.id);return re&&re.status!==ie.status?{...ie,status:re.status,items:re.count}:ie})),!B.data.data.some(fe=>fe.status==="counting")?(clearTimeout(M.current),M.current=null,x(!0),ae()):M.current=setTimeout(O,3e3))};M.current=setTimeout(O,3e3)}}})}catch(R){console.log(R),Z(`Error fetching data: ${R}`,{variant:"error"})}S(!1)};l.useEffect(()=>{if(a)return W("firstRender"),()=>clearTimeout(M.current)},[o,a]);const ae=async(F,P)=>{let R={feed_id:o,uncategorized:"yes",...F};const $=(F==null?void 0:F.title)||(F==null?void 0:F.sku),q=f.find(C=>C.id.toString()===o.toString());P==="noCate"&&!q&&(delete R.feed_id,delete R.uncategorized);try{if(P){if(P==="noCate"){w(!0);const C=await Se(R);C&&C.status<400&&C.data.count&&(r(C.data.count),y(C.data.count))}await _e({page:s,limit:v,...R}).then(C=>{C&&C.status<400&&I(C.data.data)}).catch(C=>{console.error("Error fetching data:",C),Z(`Error fetching data: ${C.message}`,{variant:"error"})})}else{x(!0);const C=await Se(R);C&&C.status<400&&C.data.count?(r(C.data.count||0),$||y(C.data.count||0),await _e({page:F?1:s,limit:v,...R}).then(B=>{B&&B.status<400&&I(B.data.data)}).catch(B=>{console.error("Error fetching data:",B),Z(`Error fetching data: ${B.message}`,{variant:"error"})})):(y(0),r(0),I([]))}}catch(C){console.log(C)}w(!1),x(!1)},Be=()=>{let F=G.cloneDeep(m);F.forEach(P=>{P.checked=!1}
1),n(()=>F)},$e=()=>{let F=G.cloneDeep(m);F.push({...Ft,uuid:ue()}),n(()=>F),T.current=!0;const P=Math.ceil(F.length/v);h<P-1&&_(P-1)},ve=async(F,P,R)=>{if(F.length){S(!0);try{let $={id:o,body:{ids:F}};x(!0),await K.delete.deleteCategories($).then(async q=>{if(q&&q.status<400){n(B=>B.filter(be=>!F.includes(be._id))),setTimeout(()=>{ae({},"noRecount")},5e3);let C={id:o,body:q.data};const O=await K.post.countByPosition(C);O&&O.status<400&&(r(O.data.uncategorized||0),y(O.data.uncategorized||0),await W(P,R))}})}catch($){console.log($),Z(`Error delete categories: ${$}`,{variant:"error"})}S(!1)}},We=async F=>{let P=G.cloneDeep(m),R=v*h+F;P[R]._id?ve([P[R]._id],"single"):(P.splice(R,1),n(()=>P))},He=F=>{let P=G.cloneDeep(m);const R=P.slice(D,E);let $=[],q=[];switch(F){case"delete_all":$=R.map(C=>C._id).filter(C=>C),q=R.map(C=>C.uuid).filter(C=>C),P=P.filter((C,O)=>!(O>=D&&O<=E-1));break;case"delete_unused":$=R.filter(C=>!C.items).map(C=>C._id).filter(C=>C),q=R.filter(C=>C.added).map(C=>C.uuid).filter(C=>C),P=P.filter((C,O)=>O<D||O>E-1||O>=D&&O<=E-1&&!C.added),P.forEach(C=>{C.checked=!1});break;case"delete_selected":$=R.filter(C=>C.checked).map(C=>C._id).filter(C=>C),q=R.filter(C=>C.checked).map(C=>C.uuid).filter(C=>C),P=P.filter(C=>!C.checked);break}$.length?ve($,"multiple",q):n(()=>P)},Ne=()=>{let F=G.cloneDeep(m);F.filter(P=>P.checked).forEach(P=>{P.active=!0,P.checked=!1,P.applyChange=!0}),n(()=>F)},Ae=()=>{let F=G.cloneDeep(m);F.filter(P=>P.checked).forEach(P=>{P.active=!1,P.checked=!1,P.applyChange=!0}),n(()=>F)};return e.jsx(N.Provider,{value:{categoryList:m,setList:n,addCategory:$e,deleteSingleCategory:We,deleteSpecial:He,activate:Ne,deactivate:Ae,page:h,setPage:_,limit:v,setLimit:L,tableRef:k,resetChecked:Be,loading:d,firstIndex:D,lastIndex:E,getList:W,setLoading:S,shouldScrollRef:T,uncategorizedItems:p,setItems:I,itemPage:s,setItemPage:b,getItems:ae,itemLoading:z,setItemLoading:w,count:g,setCount:r,counting:j,setCounting:x,uncategorizedTabCount:u,setTabCount:y},children:t})},Et=[{value:"manual",label:"Categorization"},{value:"item",label:"Uncategorized Items"}],Mt=Y(t=>({chip:{marginLeft:8,"& .MuiChip-labelSmall":{padding:6}},selectedChip:{backgroundColor:t.palette.primary.main,color:t.palette.common.white},unselectedChip:{backgroundColor:t.name==="ONE_DARK"?"#505050":"#e4e4e4",color:t.name==="ONE_DARK"?"#e6e5e8":"#546e7a"},tabContent:{display:"flex",width:"max-content"}}));function Ot(t){const{tab:c,setTab:i,loading:f}=t,a=Mt(),{itemLoading:o,uncategorizedTabCount:m,categoryList:n,counting:h}=l.useContext(N),_=n.some(d=>d.status==="counting"),v=(d,S)=>i(S),L=d=>e.jsxs("div",{className:a.tabContent,children:[d.label,d.value!=="manual"&&!!m&&e.jsx(we,{label:m||0,size:"small",className:`${a.chip} ${c===d.value?a.selectedChip:a.unselectedChip}`}),(o||h)&&d.value!=="manual"&&e.jsx(le,{size:20,color:"primary",style:{marginLeft:8}})]});return e.jsx(Ge,{value:c,onChange:v,"aria-label":"simple tabs example",indicatorColor:"primary",textColor:"primary",children:Et.map(d=>e.jsx(Ve,{label:L(d),value:d.value,disabled:f||o||d.value==="item"&&(h||_)},d.value))})}const Bt=t=>l.createElement("svg",{id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",x:"0px",y:"0px",viewBox:"0 0 122.88 111.96",style:{enableBackground:"new 0 0 122.88 111.96"},xmlSpace:"preserve",width:"1em",height:"1em",...t},l.createElement("g",null,l.createElement("path",{d:"M61.15,0L0,26.52l61.41,24.96l61.47-24.88L61.15,0L61.15,0z M122.88,57.12L95.46,45.31L62.73,58.56 c-0.88,0.36-1.83,0.33-2.65,0L27.27,45.22L0,57.05L61.41,82L122.88,57.12L122.88,57.12z M96.14,75.56L62.73,89.08 c-0.88,0.36-1.83,0.33-2.65,0L26.59,75.47L0,87.01l61.41,24.96l61.47-24.88L96.14,75.56L96.14,75.56z"}))),$t=Y(t=>({card:{display:"flex",alignItems:"flex-start",padding:16,transition:"box-shadow 0.3s, border-color 0.3s",border:"1px solid #ccc",cursor:"pointer","&:hover":{boxShadow:t.palette.type==="dark"?"0 4px 12px rgba(255, 255, 255, 0.1)":"0 4px 12px rgba(0, 0, 0, 0.1)",borderColor:t.palette.primary.main}}})),Wt=()=>e.jsx(Bt,{style:{width:24,height:24,fill:"#1976d2",marginTop:8}}),Ht=[{key:"smart",hasSmart:!0,flipIcon:!0,title:"Smart Categories",description:"Automatically match your Shopify categories to your channel's category system.",Icon:dt,getHandle:t=>t.generateSmart},{key:"generate",title:"Generate Categories",description:"Select a product field that best categorizes your items, and generate category mappings based on its values.",Icon:Wt,getHandle:t=>t.generateCategory},{key:"add",title:"Add Category",description:"Create manual rules to assign your products to the correct categories on the selected channel.",Icon:rt,getHandle:t=>t.addCategory},{key:"copy",title:"Copy Categories",description:"Copy existing categories from another channel.",Icon:ct,getHandle:t=>t.copyCategory}];function Nt({copyCategory:t=()=>{},generateCategory:c=()=>{},generateSmart:i=()=>{}}){const f=$t(),{id:a}=te.useParams(),o=Te(),{email:m,acctm:n,mainstore_type:h}=A(g=>{var r;return(r=g==null?void 0:g.account)==null?void 0:r.user}),{tableFeedList:_}=A(g=>g.feed),v=_.find(g=>g.id===parseInt(a)),L=!!m&&m.includes("shopify.com"),{addCategory:d}=l.useContext(N),S=v==null?void 0:v.type,z=S==="X (Twitter)"?"X (Twitter)":S?ze(S):"channel",x=xe.includes(v==null?void 0:v.category_src)&&h==="shopify";return e.jsx(X.Fragment,{children:e.jsxs(H,{flexDirection:"column",display:"flex",alignItems:"center",justifyContent:"center",mt:5,children:[e.jsx(ee,{variant:"h4",children:"Start categorizing your items"}),!(L||n)&&e.jsxs(ee,{variant:"body2",children:["Choose one of the methods below to match your products with the"," ",z,"'s categories."]}),e.jsxs(H,{marginTop:2,width:"50%",style:{gap:"8px",display:"flex",flexDirection:"column"},children:[Ht.filter(g=>x||!g.hasSmart).map(({title:g,description:r,Icon:p,flipIcon:I,getHandle:s,key:b})=>{const u=x&&b==="smart"||!x&&b==="generate";return e.jsxs(Me,{variant:"outlined",className:f.card,onClick:s({generateSmart:i,generateCategory:c,addCategory:d,copyCategory:t}),children:[e.jsx(p,{color:"primary",style:{marginTop:5,transform:I?"scaleY(-1)":"scaleY(1)"}}),e.jsxs(H,{ml:2,children:[e.jsxs(ee,{variant:"subtitle1",style:{fontWeight:500},children:[g,u&&e.jsx(we,{label:"Recommended",size:"small",color:"primary",style:{marginLeft:8}})]}),e.jsx(ee,{variant:"body2",color:"textSecondary",children:r})]})]},b)}),e.jsx(H,{display:"flex",justifyContent:"end",children:e.jsx(U,{variant:"contained",size:"small",onClick:()=>o.push(`/feeds/${a}/rules`),endIcon:e.jsx(Ee,{fontSize:"small"}
1),children:"Skip this step"})})]})]})})}const At=["Field","Condition","Value","Set to Category","Items"];function qt(t){const{applyChange:c,renderCategories:i}=t,f=i.filter(o=>o.checked),a=o=>{c("selectAll",o)};return e.jsx(Ue,{children:e.jsxs(Fe,{children:[e.jsx(V,{style:{padding:0},children:e.jsx(De,{checked:f.length===i.length,onChange:o=>a(o.target.checked),style:{padding:"9px"}})}),e.jsx(V,{style:{padding:0}}),e.jsx(V,{}),At.map(o=>e.jsx(V,{children:o},o))]})})}const Gt=Y(t=>({dialog:{"& .MuiDialog-paper":{width:600}}})),Vt=l.forwardRef(function(c,i){const f=Gt(),{deleteSpecial:a}=l.useContext(N),[o,m]=l.useState(!1),n=l.useRef(null);l.useImperativeHandle(i,()=>({show:d=>{m(S=>!S),n.current=d}}));const h=()=>{m(!1),n.current=null},_=()=>{a(n.current),h()},v=()=>{switch(n.current){case"delete_unused":return"This will delete the unused categories. Are you sure you want to proceed? This action cannot be undone.";case"delete_all":return"This will delete all categories. Are you sure you want to proceed? This action cannot be undone. ";case"delete_selected":return"This will delete the selected categories. Are you sure you want to proceed? This action cannot be undone.";default:return""}},L=()=>{switch(n.current){case"delete_unused":return"Delete Unused Categories";case"delete_all":return"Delete All Categories";case"delete_selected":return"Delete Selected Categories";default:return""}};return e.jsxs(pe,{open:o,onClose:h,className:f.dialog,children:[e.jsx(ye,{onClose:h,children:L()}),e.jsx(ge,{dividers:!0,children:e.jsx(ee,{variant:"body1",children:v()})}),e.jsxs(he,{children:[e.jsx(U,{onClick:_,color:"primary",size:"small",variant:"contained",children:"Delete"}),e.jsx(U,{onClick:h,size:"small",variant:"contained",children:"Cancel"})]})]})}),Ut=Y(t=>({boxOption:{display:"flex",fontWeight:500,alignItems:"center"},optionText:{display:"inline-flex",alignItems:"center",paddingLeft:"6px",fontSize:14,lineHeight:1.5,fontWeight:500},buttonOutline:{"& .MuiButton-outlined.Mui-disabled":{border:"1px solid rgba(205,205,205,255)"},margin:8,display:"flex",marginLeft:12,gap:8}})),Kt=[{value:"smart",label:"Smart Categories"},{value:"move",label:"Move Categories",selected:!0},{value:"copy",label:"Copy Categories"},{value:"generate",label:"Generate Categories"},{value:"delete_selected",label:"Delete Selected",selected:!0},{value:"delete_unused",label:"Delete Unused"},{value:"delete_all",label:"Delete All"}];function Qt({copyCategory:t=()=>{},generateCategory:c=()=>{},moveCategory:i=()=>{},generateSmart:f=()=>{}}){const{id:a}=se(),{mainstore_type:o}=A(u=>{var y;return(y=u==null?void 0:u.account)==null?void 0:y.user}),{tableFeedList:m}=A(u=>u.feed),n=m.find(u=>u.id===parseInt(a)),{categoryList:h,activate:_,deactivate:v,limit:L}=l.useContext(N),d=h.filter(u=>u.checked),w=xe.includes(n==null?void 0:n.category_src)&&o==="shopify",j=Math.ceil(h.length/L),x=Kt.filter(u=>{if(!w&&u.value==="smart")return!1;if(d.length!==0){const y=d.every(E=>!E.active),D=d.every(E=>E.active);return y?u.value!=="deactivate"&&!(j===1&&u.value==="move"):D?u.value!=="activate"&&!(j===1&&u.value==="move"):!0}return!u.selected}),g=Ut(),{settings:r}=Ke(),[p,I]=l.useState(null),s=l.useRef(null),b=u=>{switch(I(null),u){case"move":i();break;case"copy":t();break;case"generate":c();break;case"smart":f();break;case"delete_unused":case"delete_all":case"delete_selected":s.current.show(u);break;case"activate":_();break;case"deactivate":v();break}};return e.jsxs(X.Fragment,{children:[e.jsx(H,{className:g.buttonOutline,children:e.jsxs(U,{onClick:u=>{I(u.currentTarget)},color:"primary",variant:"contained",style:{fontSize:14,padding:"3.375px 5px 3.375px 10px"},children:[e.jsx(H,{children:e.jsx(ee,{style:{fontSize:"0.8125rem",fontWeight:500},component:"span",children:"Select Action"})}),e.jsx(H,{display:"flex",children:p?e.jsx(ft,{}):e.jsx(ht,{})})]})}),e.jsx(mt,{anchorEl:p,open:!!p,onClose:()=>I(null),children:x.map(u=>e.jsx(me,{value:u.value,name:u.value,onClick:()=>b(u.value),style:{padding:"6px 16px 6px 0",fontWeight:500},children:e.jsxs(H,{pl:Qe,className:g.boxOption,children:[ut(u.value,r.theme,u.value==="smart"),e.jsx(ee,{variant:"body2",className:g.optionText,children:u.label})]})},u.value))}),e.jsx(Vt,{ref:s})]})}const Xt=Y(t=>({buttonOutline:{"& .MuiButton-outlined.Mui-disabled":{border:"1px solid rgba(205,205,205,255)"},margin:8,marginLeft:12,display:"flex",gap:"8px"},startIcon:{margin:0,marginBottom:1.25}
1}));function Jt(t){const c=t.filter(i=>i.added||i.applyChange);return c.length===0?!1:c.every(i=>{var v,L,d,S,z,w;const f=(v=i.filter)==null?void 0:v[0],a=(L=i.filter)==null?void 0:L[1],o=(d=i.value)==null?void 0:d[0],m=(S=i.value)==null?void 0:S[1],n=(z=i.field)==null?void 0:z[0],h=(w=i.field)==null?void 0:w[1],_=n&&(o||f==="is_empty");return i.either==="and"?_&&(h&&(m||a==="is_empty")):_})}const Yt=(t,c)=>{let i=G.cloneDeep(c);i.forEach((a,o)=>{a.position||(a.position=o)});let f={id:t,body:{feed_category:i.filter(a=>a.added||a.applyChange).map((a,o)=>{var h,_,v,L,d,S,z,w;const m=a.smart===!0,n=[{field:((h=a.field)==null?void 0:h[0])||"",filter:((_=a.filter)==null?void 0:_[0])||"",value:((v=a.value)==null?void 0:v[0])||"",...m&&((L=a.value_label)!=null&&L[0])?{value_label:a.value_label[0]}:{}},{field:((d=a.field)==null?void 0:d[1])||"",filter:((S=a.filter)==null?void 0:S[1])||"",value:((z=a.value)==null?void 0:z[1])||"",...m&&((w=a.value_label)!=null&&w[1])?{value_label:a.value_label[1]}:{}}];return{category:a.category,active:a.active,type:"category",conditions:n,either:a.either||"if",_id:a._id,position:typeof a.position=="number"?a.position+1:o+1,...m?{smart:!0}:{}}})}};return f.body.feed_category.forEach(a=>{a.either==="if"&&a.conditions.splice(1,1),delete a.either,a._id||delete a._id,delete a.added,delete a.applyChange}),f};function Zt(t){const c=Xt(),i=Ce(),{enqueueSnackbar:f}=de(),{addCategory:a,categoryList:o,page:m,setPage:n,limit:h,setLimit:_,resetChecked:v,loading:L,getList:d,setLoading:S,getItems:z,setCounting:w,setCount:j,setList:x,setTabCount:g}=l.useContext(N),r=!Jt(o)||L,{id:p}=te.useParams(),[I,s]=l.useState(!1),b=async()=>{let k=Yt(p,o);if(k.body.feed_category.length){s(T=>!T),S(!0);try{await K.post.postCategoriesList(k).then(async T=>{if(T&&T.status<400){w(!0),setTimeout(()=>{z({},"noRecount")},5e3);let M=o.map(W=>({...W,status:"counting"}));x(M);let Z={id:p,body:{mapping_ids:T.data.feed_category.map(W=>W._id)}};await K.post.startCount(Z).then(async W=>{if(W&&W.status<400){let ae=W.data.uncategorized||0;j(ae),g(ae),w(!1),await d()}})}})}catch(T){console.log(T),f(`Error posting data: ${T.message}`,{variant:"error"})}S(!1),s(T=>!T)}},u=async k=>{var M;const T=(M=k==null?void 0:k.target)==null?void 0:M.value;h!==T&&(_(T),localStorage.setItem("listingRowPerPage",T),Math.ceil(o.length/T)<m&&n(Math.ceil(o.length/T)),i(Ze({limit:T})))},y=async(k,T)=>{n(T),v();const M=document.querySelector(`#${Ye}`);M&&M.scrollTo({top:0,behavior:"smooth"})},D=k=>y(0,k.target.value),E=o.filter(k=>k.position);return e.jsx(X.Fragment,{children:e.jsx(yt,{total:(o==null?void 0:o.length)??0,page:m,limit:h,onPageChange:y,onRowPerPageChange:u,onHandleCustomPageChange:D,iconDisabled:E.length,showMultiple:!0,childrenButton:e.jsxs(H,{className:c.buttonOutline,children:[e.jsx(U,{variant:"contained",size:"small",onClick:()=>a(),startIcon:e.jsx(Ct,{}),classes:{startIcon:c.startIcon},children:"Add Category"}),e.jsx(oe,{text:"Save",loading:I,handleClick:b,minWidth:55,disabled:r}),E.length>0&&e.jsx(Xe,{title:"Please save your changes after re-positioning the list before using the page pagination to avoid losing your adjustments.",children:e.jsx(Je,{size:"small",children:e.jsx(xt,{style:{color:"#ffa726"}})})})]})})})}function ea(t){const{category:c,applyChange:i}=t;return e.jsx(V,{style:{width:40,padding:0},children:e.jsx(De,{style:{padding:"9px"},checked:c.checked,onChange:f=>i("checked",f.target.checked)})})}function ta(t){const{category:c,applyChange:i}=t,f=c.either,a=()=>{i("either",f==="if"?"and":"if")};return e.jsx(V,{style:{width:60,paddingTop:0,paddingBottom:0},children:e.jsx(U,{size:"small",variant:"contained",color:f==="and"?"primary":"",disabled:!c.active||c.smart,onClick:()=>a(),children:ze(f)})})}const aa=Y(t=>({groupHeader:{paddingLeft:t.spacing(1.5),margin:0,color:t.palette.text.primary,fontWeight:"bold",fontSize:13,position:"sticky",top:-8,backgroundColor:t.palette.background.paper,zIndex:1,lineHeight:2.5}}));function na({category:t,applyChange:c,fieldOptions:i}){const f=aa(),a=t.either,o=i.find(n=>n.value===t.field[0])||"",m=i.find(n=>n.value===t.field[1])||"";return e.jsxs(V,{style:{width:250},children:[e.jsx(ne,{options:i,value:o,getOptionLabel:n=>n.name||"",onChange:(n,h)=>c("field1",h==null?void 0:h.value),disabled:!t.active||t.smart,size:"small",groupBy:n=>n.type,filterSelectedOptions:!0,getOptionSelected:(n,h)=>n.value===h.value,PaperComponent:n=>e.jsx(Q,{...n,variant:"outlined",style:{minWidth:250}}),renderGroup:n=>e.jsxs("div",{children:[e.jsx("div",{className:f.groupHeader,children:n.group}),n.children]},n.key),renderInput:n=>e.jsx(J,{...n,variant:"outlined",fullWidth:!0,placeholder:"Select or Type to Find"})}),a==="and"&&e.jsx(ne,{options:i,disabled:!t.active||t.smart,value:m,getOptionLabel:n=>n.name||"",onChange:(n,h)=>c("field2",h==null?void 0:h.value),style:{marginTop:8},size:"small",groupBy:n=>n.type,filterSelectedOptions:!0,getOptionSelected:(n,h)=>n.value===h.value,PaperComponent:n=>e.jsx(Q,{...n,variant:"outlined",style:{minWidth:250}}),renderGroup:n=>e.jsxs("div",{children:[e.jsx("div",{className:f.groupHeader,children:n.group}),n.children]},n.key),renderInput:n=>e.jsx(J,{...n,variant:"outlined",fullWidth:!0,placeholder:"Select or Type to Find"})})]})}const Le=[{label:"contains",value:"contains"},{label:"does not contain",value:"not_contains"},{label:"is equal to",value:"is_equal"},{label:"is not equal to",value:"is_not_equal"},{label:"is empty",value:"is_empty",isSmart:!0},{label:"is not empty",value:"is_not_empty",isSmart:!0}];function sa({category:t={},applyChange:c=()=>{}}){const i=t.either,f=Le.filter(a=>t.smart?a:!a.isSmart);return e.jsxs(V,{style:{width:250},children:[e.jsx(ke,{variant:"outlined",fullWidth:!0,size:"small",disabled:!t.active,children:e.jsx(Ie,{value:t.filter[0],onChange:a=>c("filter1",a.target.value),displayEmpty:!0,disabled:t.smart,MenuProps:{PaperProps:{variant:"outlined"},anchorOrigin:{vertical:"bottom",horizontal:"left"},getContentAnchorEl:null},children:f.map(a=>e.jsx(me,{value:a.value,style:{fontSize:13},disabled:t.field[0]==="description"&&["is_equal","is_not_equal"].includes(a.value),
1children:a.label},a.value))})}),i==="and"&&e.jsx(ke,{variant:"outlined",fullWidth:!0,size:"small",disabled:!t.active,style:{marginTop:8},children:e.jsx(Ie,{value:t.filter[1],onChange:a=>c("filter2",a.target.value),displayEmpty:!0,disabled:t.smart,MenuProps:{PaperProps:{variant:"outlined"},anchorOrigin:{vertical:"bottom",horizontal:"left"},getContentAnchorEl:null},children:Le.map(a=>e.jsx(me,{value:a.value,style:{fontSize:13},disabled:t.field[1]==="description"&&["is_equal","is_not_equal"].includes(a.value),children:a.label},a.value))})})]})}function ia({category:t,applyChange:c}){var v,L;const[i,f]=l.useState(t.value[0]),[a,o]=l.useState(t.value[1]),m=(v=t.value_label)==null?void 0:v[0],n=(L=t.value_label)==null?void 0:L[1],h=t.either,_=(d,S)=>{const z=d.trim().replace(/\s+/g," ");switch(c(S,z),S){case"value1":f(z);break;case"value2":o(z);break}};return e.jsxs(V,{style:{width:300},children:[t.filter[0]!=="is_empty"&&e.jsx(J,{value:t.smart?m:i||"",onChange:d=>f(d.target.value),onBlur:d=>_(d.target.value,"value1"),size:"small",disabled:!t.active||t.smart,variant:"outlined",fullWidth:!0}),h==="and"&&t.filter[1]!=="is_empty"&&e.jsx(J,{value:t.smart?n:a||"",onChange:d=>o(d.target.value),onBlur:d=>_(d.target.value,"value2"),style:{marginTop:8},size:"small",disabled:!t.active||t.smart,variant:"outlined",fullWidth:!0})]})}const oa=l.memo(t=>{var y,D,E;const{category:c,applyChange:i,defaultOptions:f}=t,a=c.value[0]||c.value[1],o=(y=c==null?void 0:c.category)==null?void 0:y.path,m=(D=c==null?void 0:c.category)==null?void 0:D.id,n={category_id:m,name:o,path:o},[h,_]=l.useState([]),[v,L]=l.useState([]),[d,S]=l.useState(""),[z,w]=l.useState(!1),{id:j}=te.useParams(),x=l.useRef(""),g=l.useRef(""),r=l.useCallback(G.debounce(async(k,T)=>{let M=[];if(k.length){let Z={id:j,params:{name:k}};w(!0);try{const W=await K.get.getFeedCategories(Z);W&&W.status<400&&(M=W.data.data)}catch(W){console.error("Error fetching options:",W),M=[]}w(!1)}else M=[];switch(T){case"searchValue":_(M);break;case"rowValue":L(M);break}},500),[j]),p=k=>{S(k),r(k,"searchValue")},I=(k,T)=>{i("category",T||null);const M=T==null?void 0:T.path.split(" > ").slice(0,-1).join(" > ");S(T?M:"")},s=()=>d&&h.length?h:a&&v.length?v:!o||!m?f:[n,...f],b=((E=s())==null?void 0:E.find(k=>{var T,M;return parseInt(k.category_id)===parseInt((T=c==null?void 0:c.category)==null?void 0:T.id)&&((M=c==null?void 0:c.category)==null?void 0:M.path)===k.path}))||"",u=()=>{const k=x.current,T=g.current;d&&d!==k?(w(!0),r(d,"searchValue"),x.current=d):!m&&!o&&a&&a!==T&&(w(!0),r(a,"rowValue"),g.current=a)};return e.jsx(V,{style:{width:700},children:e.jsx(ne,{value:b,id:"async-autocomplete",options:s()||[],getOptionLabel:k=>k.path||"",getOptionSelected:(k,T)=>k.category_id===T.category_id,onOpen:u,onChange:I,getOptionDisabled:()=>z,disabled:!c.active,size:"small",fullWidth:!0,PaperComponent:k=>e.jsx(Q,{...k,variant:"outlined"}),renderInput:k=>e.jsx(J,{...k,onChange:T=>p(T.target.value),placeholder:"Category",variant:"outlined",InputProps:{...k.InputProps,endAdornment:e.jsxs(X.Fragment,{children:[z?e.jsx(le,{color:"primary",size:20}):null,k.InputProps.endAdornment]})}})})})});function la(t){const{category:c}=t,i=c.status==="counting",f=te.useHistory(),{id:a}=te.useParams(),o=()=>{f.push({pathname:"/feeds/items",search:`?feed_id=${a}&category_rule_id=${c._id}&count=${c.items}&category_feed_id=${a}`,state:{name:c.category.path}})};return e.jsx(V,{style:{width:75},children:e.jsx(U,{size:"small",color:c.items>0?"primary":"default",style:{padding:0,minWidth:50,minHeight:22.75},variant:"contained",disabled:!c.items||i,onClick:()=>o(),children:i?e.jsx(le,{size:18,color:"primary"}):c.items||0})})}function ra(){return e.jsx(V,{style:{padding:0,width:20},children:e.jsx(H,{display:"flex",children:e.jsx(St,{fontSize:"small",color:"action"})})})}function ca(t){const{defaultOptions:c}=t,{setList:i,categoryList:f,firstIndex:a,lastIndex:o}=l.useContext(N),{id:m}=se(),{mainstore_type:n}=A(s=>{var b;return(b=s==null?void 0:s.account)==null?void 0:b.user}),{tableFeedList:h}=A(s=>s.feed),{listAttributes:_}=A(s=>s.attributes),v=(_==null?void 0:_.map(s=>({type:"MetaFields",name:s.recipeName?s.recipeName===s.name?s.name:s.recipeName:s.name,value:`c.${s.name}`})))||[],L=(s=[])=>n==="shopify"?s.map(b=>b.name==="Brand"?{type:"Main Store Fields",name:"Vendor",value:"brand"}:b):s.filter(b=>b.value!=="product_type"),d=h.find(s=>s.id===parseInt(m)),w=xe.includes(d==null?void 0:d.category_src)&&n==="shopify",j=[...L(pt).map(s=>n==="shopify"&&s.name==="Category"?{...s,name:"Collection"}:s),...v,...w?[{type:"Shopify Field",name:"Product Category",value:"shopify_product_category"}]:[]],x=s=>(b,u)=>{let y=G.cloneDeep(f),D=a+s;switch(b){case"field1":y[D].field[0]=u,u==="description"&&["is_not_equal","is_equal"].includes(y[D].filter[0])&&(y[D].filter[0]="");break;case"field2":y[D].field[1]=u,u==="description"&&["is_not_equal","is_equal"].includes(y[D].filter[1])&&(y[D].filter[1]="");break;case"filter1":y[D].filter[0]=u;break;case"filter2":y[D].filter[1]=u;break;case"value1":if(y[D].value[0]!==u)y[D].value[0]=u;else return;break;case"value2":if(y[D].value[1]!==u)y[D].value[1]=u;else return;break;case"category":if(u)y[D][b]={id:u.category_id,path:u.path};else{if(!y[D][b].id)return;y[D][b]={id:"",path:""}}break;case"selectAll":y.forEach((E,k)=>{k>=a&&k<=o-1&&(E.checked=u)});break;default:y[D][b]=u;break}![null,void 0].includes(s)&&b!=="checked"&&(y[D].applyChange=!0),i(()=>y)},g=(s,b)=>
1({userSelect:"none",...b,pointerEvents:s?"none":"auto"}),r=s=>{if(!s.destination)return;const b=p(f,s.source.index,s.destination.index);i(b.map((u,y)=>(y>=a&&y<=o-1&&(u.position=y,u.applyChange=!0),u)))},p=(s,b,u)=>{const y=b+a,D=u+a,E=Array.from(s),[k]=E.splice(y,1);return E.splice(D,0,k),E},I=f.slice(a,o);return e.jsx(vt,{onDragEnd:r,children:e.jsx(bt,{droppableId:"droppable",children:s=>e.jsxs(H,{component:"tbody",...s.droppableProps,ref:s.innerRef,children:[I.map((b,u)=>e.jsx(jt,{draggableId:b._id||b.uuid,index:u,children:(y,D)=>e.jsxs(Fe,{ref:y.innerRef,...y.draggableProps,...y.dragHandleProps,style:g(D.isDragging,y.draggableProps.style),children:[e.jsx(ea,{category:b,applyChange:x(u)}),e.jsx(ra,{}),e.jsx(ta,{category:b,applyChange:x(u)}),e.jsx(na,{category:b,applyChange:x(u),fieldOptions:j}),e.jsx(sa,{category:b,applyChange:x(u)}),e.jsx(ia,{category:b,applyChange:x(u)}),e.jsx(oa,{category:b,applyChange:x(u),defaultOptions:c}),e.jsx(la,{category:b})]})},b._id||b.uuid)),s.placeholder]})})})}const da=Y(t=>({tableContainer:{position:"relative",height:"100%"},root:{"& .MuiTableCell-root":{padding:"6px 16px"},"& .MuiTableCell-stickyHeader":{backgroundColor:t.palette.background.default,zIndex:t.zIndex.appBar}}}));function ua({generateSmart:t=()=>{},copyCategory:c=()=>{},generateCategory:i=()=>{},moveCategory:f=()=>{}}){const a=da(),[o,m]=l.useState([]),{id:n}=te.useParams(),{setList:h,categoryList:_,setPage:v,tableRef:L,firstIndex:d,lastIndex:S}=l.useContext(N),z=(j,x,g)=>{let r=G.cloneDeep(_),p=d+g;switch(j){case"field1":r[p].field[0]=x;break;case"field2":r[p].field[1]=x;break;case"filter1":r[p].filter[0]=x;break;case"filter2":r[p].filter[1]=x;break;case"value1":if(r[p].value[0]!==x)r[p].value[0]=x;else return;break;case"value2":if(r[p].value[1]!==x)r[p].value[1]=x;else return;break;case"category":if(x)r[p][j]={id:x.category_id,path:x.path};else{if(!r[p][j].id)return;r[p][j]={id:"",path:""}}break;case"selectAll":r.forEach((I,s)=>{s>=d&&s<=S-1&&(I.checked=x)});break;default:r[p][j]=x;break}![null,void 0].includes(g)&&j!=="checked"&&(r[p].applyChange=!0),h(()=>r)},w=_.slice(d,S);return l.useEffect(()=>{w.length===0&&v(j=>j-1)},[w.length,v]),l.useEffect(()=>{n&&(async()=>{try{await K.get.getFeedCategories({id:n}).then(x=>{x&&x.status<400&&m(()=>x.data.data)})}catch(x){console.error("Error fetching options:",x)}})()},[n]),e.jsxs(X.Fragment,{children:[e.jsx(Qt,{copyCategory:c,generateCategory:i,moveCategory:f,generateSmart:t}),e.jsx(Oe,{className:a.tableContainer,component:Q,variant:"outlined",ref:L,style:{borderTop:"none"},children:e.jsxs(Re,{className:a.root,stickyHeader:!0,children:[e.jsx(qt,{applyChange:z,renderCategories:w}),e.jsx(ca,{defaultOptions:o})]})}),e.jsx(Zt,{})]})}const pa=Y(t=>({groupHeader:{paddingLeft:t.spacing(1.5),margin:0,color:t.palette.text.primary,fontWeight:"bold",fontSize:13,position:"sticky",top:-10,backgroundColor:t.palette.background.paper,zIndex:1,lineHeight:2.5}})),ga=l.forwardRef(function(c,i){const{generateOptions:f=[]}=c,a=pa(),[o,m]=l.useState(!1),[n,h]=l.useState(null),[_,v]=l.useState(!1),{enqueueSnackbar:L}=de(),{id:d}=te.useParams(),{setList:S,shouldScrollRef:z}=l.useContext(N);l.useImperativeHandle(i,()=>({open:()=>m(r=>!r)}));const w=()=>{m(r=>!r),h(null)},j=(r,p)=>{const I=(p==null?void 0:p.value)||"";h(I)},x=async()=>{let r={id:d,body:{field:n}};v(p=>!p);try{await K.post.generateCategory(r).then(async p=>{if(p&&p.status<400)if(p.data.feed_category.length!==0){let I=p.data.feed_category.map(s=>{var b,u,y;return{uuid:ue(),active:s.active,checked:!1,category:s.category,type:s.type,either:s.conditions.length===2?"and":"if",items:s.count||0,field:[s.conditions[0].field,((b=s.conditions[1])==null?void 0:b.field)??""],filter:[s.conditions[0].filter,((u=s.conditions[1])==null?void 0:u.filter)??"contains"],value:[s.conditions[0].value??"",((y=s.conditions[1])==null?void 0:y.value)??""],applyChange:!0,added:!0}});S(s=>[...s.filter(b=>!b.added),...I]),z.current=!0,w()}else L("No categories were generated from this field",{variant:"warning"})})}catch(p){console.log(p),L("Generate Fail",{variant:"error"})}v(p=>!p)},g=f==null?void 0:f.find(r=>(r==null?void 0:r.value)===n);return e.jsxs(pe,{open:o,onClose:()=>w(),PaperProps:{style:{width:400}},PaperComponent:r=>e.jsx(Q,{...r,variant:"outlined"}),children:[e.jsx(ye,{onClose:()=>w(),children:"Set Category Field"}),e.jsx(ge,{dividers:!0,children:e.jsx(ne,{groupBy:r=>r.type,options:f,value:g,getOptionLabel:r=>r.name,PaperComponent:r=>e.jsx(Q,{...r,variant:"outlined",style:{minWidth:250}}),onChange:j,size:"small",renderGroup:r=>e.jsxs("div",{children:[e.jsx("div",{className:a.groupHeader,children:r.group}),r.children]},r.key),renderInput:r=>e.jsx(J,{...r,placeholder:"Select or Type to Find",variant:"outlined",fullWidth:!0})})}),e.jsxs(he,{style:{paddingRight:24},children:[e.jsx(oe,{text:"Generate",loading:_,handleClick:()=>x(),minWidth:85,disabled:!n,height:30.75}),e.jsx(U,{variant:"contained",size:"small",onClick:()=>w(),children:"Cancel"})]})]})}),ha=l.forwardRef(function(c,i){const{categories:f}=c,[a,o]=l.useState(!1),[m,n]=l.useState(null),{setList:h,shouldScrollRef:_,page:v,setPage:L,limit:d,categoryList:S}=l.useContext(N),[z,w]=l.useState(!1),{id:j}=te.useParams(),{enqueueSnackbar:x}=de();l.useImperativeHandle(i,()=>({open:()=>o(I=>!I)}));const g=()=>{o(I=>!I),n(null)},r=(I,s)=>{n(s)},p=async()=>{let I={id:j,body:{from_id:m.id}};w(s=>!s);try{await K.post.copyCategory(I).then(async s=>{if(s&&s.status<400)if(s.data.feed_category.length!==0){let b=s.data.feed_category.map(y=>{var D,E,k;return{uuid:ue(),active:y.active,checked:!1,category:y.category,type:y.type,either:y.conditions.length===2?"and":"if",items:y.count||0,field:[y.conditions[0].field,((D=y.conditions[1])==null?void 0:D.field)??""],filter:[y.conditions[0].filter,((E=y.conditions[1])==null?void 0:E.filter)??"contains"],value:[y.conditions[0].value,((k=y.conditions[1])==null?void 0:k.value)??""],applyChange:!0,added:!0}});h(y=>[...y,...b]),_.current=!0;const u=Math.ceil((S.length+b.length)/d);v<u-1&&L(u-1),g()}else x("The feed you selected has no categories!",{variant:"warning"})})}catch(s){console.log(s),x("Generate Fail",{variant:"error"})}w(s=>!s)};return e.jsxs(pe,{open:a,onClose:()=>g(),PaperProps:{style:{width:400}},PaperComponent:I=>e.jsx(Q,{...I,variant:"outlined"}),children:[e.jsx(ye,{onClose:()=>g(),children:"Copy Category"}),e.jsx(ge,{dividers:!0,children:e.jsx(ne,{value:m,options:f,getOptionLabel:I=>I.name,onChange:r,PaperComponent:I=>e.jsx(Q,{...I,variant:"outlined",style:{minWidth:250}}),size:"small",filterSelectedOptions:!0,renderInput:I=>e.jsx(J,{...I,placeholder:"Select a Feed",variant:"outlined",fullWidth:!0})})}),e.jsxs(he,{style:{paddingRight:24},children:[e.jsx(oe,{text:"Copy",loading:z,handleClick:p,minWidth:55,disabled:!(m!=null&&m.id),height:30.75}),e.jsx(U,{variant:"contained",size:"small",onClick:()=>g(),children:"Cancel"})]})]})}),fa=l.forwardRef(function(c,i){const[f,a]=l.useState(!1),[o,m]=l.useState(null),{setList:n,page:h,categoryList:_,limit:v,setPage:L}=l.useContext(N),d=Math.ceil(_.length/v),S=Array.from({length:d},(j,x)=>({value:x,label:`Page ${x+1}`})).filter(j=>j.value!==h);l.useImperativeHandle(i,()=>({open:()=>a(j=>!j)}));const z=()=>{a(j=>!j),m(null)},w=()=>{let j=G.cloneDeep(_);const x=j.filter(r=>r.checked),g=j.filter(r=>!r.checked);g.splice((o.value-1)*v+v,0,...x),g.forEach(r=>{r.checked=!1}
1),n(()=>g),L(o.value),z()};return e.jsxs(pe,{open:f,onClose:()=>z(),PaperProps:{style:{width:400}},PaperComponent:j=>e.jsx(Q,{...j,variant:"outlined"}),children:[e.jsx(et,{onClose:()=>z(),children:"Move Selected Category"}),e.jsx(ge,{dividers:!0,children:e.jsx(ne,{options:S,value:o,getOptionLabel:j=>j.label,PaperComponent:j=>e.jsx(Q,{...j,variant:"outlined",style:{minWidth:200}}),onChange:(j,x)=>m(x),size:"small",renderInput:j=>e.jsx(J,{...j,placeholder:"Select Page",variant:"outlined",fullWidth:!0}),getOptionSelected:(j,x)=>j.value===x.value})}),e.jsxs(he,{children:[e.jsx(U,{variant:"contained",size:"small",color:"primary",onClick:()=>w(),children:"Move"}),e.jsx(U,{variant:"contained",size:"small",onClick:()=>z(),children:"Cancel"})]})]})});function ma(t){const{copyCategories:c}=t,{categoryList:i,setList:f,shouldScrollRef:a}=l.useContext(N),o=l.useRef(null),m=l.useRef(null),n=l.useRef(null),{mainstore_type:h}=A(g=>{var r;return(r=g==null?void 0:g.account)==null?void 0:r.user}),{id:_}=se(),{listAttributes:v}=A(g=>g.attributes),L=(v==null?void 0:v.map(g=>({type:"MetaFields",name:g.recipeName===g.name?g.name:g.recipeName,value:"c."+g.name})))||[],S=[...((g=[])=>h==="shopify"?g.map(r=>r.name==="Brand"?{type:"Main Store Fields",name:"Vendor",value:"brand"}:r):g)(gt).filter(g=>h!=="shopify"||g.name!=="Brand").map(g=>({...g,name:h==="shopify"&&g.name==="Category"?"Collection":g.name})),...L],z=()=>o.current.open(),w=()=>m.current.open(),j=()=>n.current.open(),x=async()=>{try{const g=await K.post.getSmartCategories(_);if(g&&g.status<400&&g.data.feed_category.length>0){let r=g.data.feed_category.map(p=>{var I,s,b,u;return{uuid:ue(),active:p.active,checked:!1,category:p.category,type:p.type,either:p.conditions.length===2?"and":"if",items:p.count||0,field:[p.conditions[0].field,((I=p.conditions[1])==null?void 0:I.field)??""],filter:[p.conditions[0].filter,((s=p.conditions[1])==null?void 0:s.filter)??"contains"],value:[p.conditions[0].value??"",((b=p.conditions[1])==null?void 0:b.value)??""],value_label:[p.conditions[0].value_label??"",((u=p.conditions[1])==null?void 0:u.value_label)??""],applyChange:!0,added:!0,smart:p.smart}});f(p=>[...p.filter(I=>!I.added),...r]),a.current=!0}}catch(g){console.log(g)}};return e.jsxs(X.Fragment,{children:[i.length===0&&e.jsx(Nt,{generateSmart:x,generateCategory:z,copyCategory:w}),i.length!==0&&e.jsx(ua,{generateCategory:z,copyCategory:w,moveCategory:j,generateSmart:x}),e.jsx(ga,{ref:o,generateOptions:S}),e.jsx(ha,{ref:m,categories:c}),e.jsx(fa,{ref:n})]})}const Pe={title:"",sku:""};function ya({setFilter:t=()=>{}}){const{getItems:c,setItemPage:i}=l.useContext(N),[f,a]=l.useState(!1),[o,m]=l.useState(!1),[n,h]=l.useState(Pe),_=(d={})=>{const S=G.merge({},n,d);h(()=>S)},v=async()=>{t(()=>n),a(!0);try{await c(n),i(1)}catch(d){console.log(d)}a(!1)},L=async()=>{t({}),h(Pe),m(!0);try{await c({}),i(1)}catch(d){console.log(d)}m(!1)};return e.jsxs(ce,{container:!0,spacing:1,alignItems:"center",style:{padding:8},children:[e.jsx(ce,{item:!0,xs:3,children:e.jsx(J,{placeholder:"Search products",fullWidth:!0,size:"small",variant:"outlined",value:n.title,onChange:d=>_({title:d.target.value})})}),e.jsx(ce,{item:!0,xs:3,children:e.jsx(J,{fullWidth:!0,placeholder:"Search by SKU or ID",size:"small",variant:"outlined",value:n.sku,onChange:d=>_({sku:d.target.value})})}),e.jsx(ce,{item:!0,xs:6,children:e.jsxs(H,{display:"flex",style:{gap:"8px"},children:[e.jsx(oe,{text:"Search",loading:f,disabled:o,handleClick:v,minWidth:72,height:30.75}),e.jsx(oe,{text:"Clear",loading:o,disabled:f,handleClick:L,minWidth:72,height:30.75})]})})]})}const Ca=Y(t=>({tableContainer:{position:"relative",height:"100%"},root:{"& .MuiTableCell-root":{padding:"6px"},"& .MuiTableCell-stickyHeader":{backgroundColor:t.palette.background.default,zIndex:t.zIndex.appBar}},image:{height:40,width:40,overflow:"hidden",border:"1px solid #b5b2b1",borderRadius:4,marginRight:4,padding:0}}));function xa(){const t=Ca(),{loadingFeedList:c}=A(z=>z==null?void 0:z.feed),{id:i}=se(),{uncategorizedItems:f,itemPage:a,limit:o,setItemPage:m,setLimit:n,count:h,setItems:_,uncategorizedTabCount:v,getItems:L}=l.useContext(N),[d,S]=l.useState({});return l.useEffect(()=>()=>{h!==v&&L()},[h]),c?e.jsx(H,{display:"flex",justifyContent:"center",alignItems:"center",height:250,children:e.jsx(le,{})}):e.jsxs(X.Fragment,{children:[e.jsx(ya,{setFilter:S}),e.jsx(Oe,{className:t.tableContainer,component:Q,variant:"outlined",children:e.jsx(Re,{className:t.root,stickyHeader:!0,children:e.jsxs(_t,{children:[e.jsx(kt,{fromUncategorized:!0}),e.jsx(It,{data:f,fromUncategorized:!0,filter:d}),e.jsx(Lt,{})]})})}),e.jsx(Pt,{page:a,setPage:m,limit:o,setLimit:n,total:h,setData:_,filter:d,additionalPayload:{feed_id:i,uncategorized:"yes"}})]})}function va(){const{loading:t,categoryList:c}=l.useContext(N),i=Ce(),{tableFeedList:f}=A(p=>p==null?void 0:p.feed),a=f.length,[o,m]=l.useState("manual"),[n,h]=l.useState([]),[_,v]=l.useState(""),{id:L}=se(),d=Te(),{email:S,acctm:z}=A(p=>{var I;return(I=p==null?void 0:p.account)==null?void 0:I.user}),w=!!S&&S.includes("shopify.com"),j=JSON.parse(sessionStorage.getItem("feedInfor")),x=j==null?void 0:j.category_type;l.useEffect(()=>
1{v(x)},[x]),l.useEffect(()=>{i(tt({feedId:L}))},[]),l.useEffect(()=>{h(f.filter(p=>p.id!==parseInt(L)))},[a]);const g=()=>t&&c.length===0?e.jsx(H,{display:"flex",justifyContent:"center",alignItems:"center",height:250,children:e.jsx(le,{})}):e.jsxs(X.Fragment,{children:[o==="manual"&&e.jsx(ma,{copyCategories:n}),o==="item"&&e.jsx(xa,{})]}),r=()=>_==="no_category"?e.jsxs(H,{display:"flex",alignItems:"center",justifyContent:"center",height:"80%",flexDirection:"column",children:[e.jsxs(ee,{variant:"h4",children:["Categorization is not required for this"," ",w||z?"feed":"channel",", and can be skipped"]}),e.jsx(U,{size:"small",color:"primary",variant:"contained",onClick:()=>d.push(`/feeds/${L}/rules`),style:{marginTop:8},endIcon:e.jsx(Ee,{fontSize:"small"}),children:"Skip this step"})]}):e.jsxs(X.Fragment,{children:[e.jsx(Ot,{setTab:m,tab:o,loading:t}),e.jsx(wt,{noBorder:!0,children:g()})]});return e.jsx(Me,{variant:"outlined",style:{display:"flex",flexDirection:"column",flex:"1 1 0",marginBottom:8},children:r()})}const ba=Y(t=>({root:{backgroundColor:t.palette.background.dark,marginTop:t.spacing(3),paddingBottom:0},container:{padding:"0 12px",display:"flex",flexDirection:"column",flex:1},extend:{paddingTop:12,display:"flex",flexDirection:"column",flex:1}})),ja=new lt({defaultOptions:{queries:{refetchOnWindowFocus:!1}}});function _n(){const t=ba(),c=Ce();return l.useEffect(()=>{c(at())},[]),e.jsx(X.Fragment,{children:e.jsx(Rt,{children:e.jsx(it,{classes:t.root,extendClass:t.extend,title:"Feed Categories",noPadding:!0,children:e.jsx(nt,{children:e.jsxs(st,{maxWidth:!1,className:t.container,children:[e.jsx(Tt,{header:"Feed Categories"}),e.jsx(ot,{client:ja,children:e.jsx(va,{})})]})})})})})}export{_n as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.