1import{j as e,a7 as c,ab as y,ao as S,T as p,N as k,I as te,B as q,o as A,at as ae,n as P,ar as H,ac as W,X as se,ai as ne,Z as ie,aq as re,O as oe}from"./mui-CRsYZxVY.js";import{r as l}from"./vendor-Dwao9eNC.js";import{u as ce,m as de,w as le,b as ue,e as ge,x as xe,J as pe,az as he,dV as me,dW as $,dX as fe,T,aF as L,c$ as be,br as je,dj as ye,_ as Ce,O as ve,dY as Ie,dZ as _e,d_ as we,d$ as Se,aE as ke,aD as Ee,e0 as De,e1 as Re,e2 as Te,e3 as Ae,e4 as Me}from"./index-TALscxEc.js";import{I as Oe}from"./InlineEditText-O-PTkbvc.js";import{u as Be}from"./useEditCategory-DFBO_RXR.js";import{a as ze,b as Ne}from"./query-8ViTdhdk.js";import{u as Pe}from"./useBatchUpdateCategoryOrder-CUUUOfvi.js";import{C as He}from"./CategoryQuickCreateSheet-DWRrPzmh.js";import{H as We}from"./HubRow-DdcKuFLd.js";import{u as $e}from"./useCategoryMedia-B554yVLD.js";import{M as qe,D as Le,G as Fe}from"./icons-D8aatgQ4.js";import"./datePickers-BIJXYOKG.js";import"./lab-DSem1Osk.js";import"./homeLayout-C05shHWS.js";import"./StatusDotLine-CR-EBrxL.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};n.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},d=new n.Error().stack;d&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[d]="fc7a1417-6aab-4553-8f7c-316c684cf02d",n._sentryDebugIdIdentifier="sentry-dbid-fc7a1417-6aab-4553-8f7c-316c684cf02d")})()}catch{}const Ue=()=>{const n=ze(),{user:d}=ce(),o=d==null?void 0:d.id,{triggerRevalidation:m}=de();return Ne({mutationFn:async u=>{if(!o)throw new Error("User must be logged in to delete a category");const{error:i}=await le.from("categoria").delete().eq("id",u).eq("user_id",o);if(i)throw i;return!0},onSuccess:()=>{n.invalidateQueries({queryKey:["categories"]}),m()}})},dt=()=>{const n=ue(),{data:d}=ge(),o=xe(d),{categoryId:m}=pe(),u=m?Number(m):null,{data:i,isLoading:E}=he(),v=Be(),C=Ue(),f=Pe(),a=l.useMemo(()=>(i||[]).find(t=>t.id===u)||null,[i,u]),{data:I}=$e(),F=l.useMemo(()=>{const t=a?I==null?void 0:I.get(a.id):void 0,s=o&&!!(t!=null&&t.imagem_url),r=o&&!!(t!=null&&t.banner_desktop_url||t!=null&&t.banner_mobile_url);return s&&r?"Imagem e banner configurados":s?"Imagem configurada · sem banner":r?"Banner configurado · sem imagem":"Imagem para a página inicial e banner no topo da categoria"},[a,I,o]),M=l.useMemo(()=>{if(!a||!i)return null;const t=new Map(i.map(x=>[x.id,x])),s=[];let r=a.categoria_pai_id??null,g=0;for(;r&&g<5;){const x=t.get(r);if(!x)break;s.unshift(x.nome),r=x.categoria_pai_id??null,g+=1}return s.length>0?`em ${s.join(" ⺠")}`:null},[a,i]),h=l.useMemo(()=>u?(i||[]).filter(t=>t.id>0&&t.categoria_pai_id===u).sort((t,s)=>{const r=t.destaque??0,g=s.destaque??0;return r!==g?g-r:t.nome.localeCompare(s.nome,"pt-BR")}):[],[i,u]),U=l.useMemo(()=>{const t=new Map;return(i||[]).filter(s=>s.id>0&&s.categoria_pai_id).forEach(s=>{t.set(s.categoria_pai_id,(t.get(s.categoria_pai_id)||0)+1)}),t},[i]),O=l.useMemo(()=>{let t=0,s=(a==null?void 0:a.categoria_pai_id)??null;for(;s&&t<5;){t+=1;const r=(i||[]).find(g=>g.id===s);s=(r==null?void 0:r.categoria_pai_id)??null}return t},[a,i])<2,[V,D]=l.useState(!1),[Q,R]=l.useState(!1),[B,_]=l.useState(null),[Z,w]=l.useState(!1),X=me($(Me,{activationConstraint:{distance:4}}),$(Ae,{activationConstraint:{delay:200,tolerance:12}})),Y=l.useCallback(async t=>{if(!a)return;const s=t.trim();!s||s===a.nome||await v.mutateAsync({id:a.id,nome:s})},[a,v]),G=l.useCallback(t=>{const{active:s,over:r}=t;if(!r||s.id===r.id)return;const g=h.findIndex(j=>j.id.toString()===s.id),x=h.findIndex(j=>j.id.toString()===r.id);if(g===-1||x===-1)return;const N=fe(h,g,x),K=N.length;f.mutate({categories:N.map((j,ee)=>({id:j.id,destaque:K-ee,category:j})),originalCategories:i||[],isSubcategoryUpdate:!0,parentCategoryId:u||void 0})},[h,f,i,u]),J=()=>{a&&C.mutate(a.id.toString(),{onSuccess:()=>{w(!1),a.categoria_pai_id?n(`/categories/${a.categoria_pai_id}`,{replace:!0}):n("/categories",{replace:!0})}})};if(E)return e.jsxs(c,{sx:{position:"relative",minHeight:"100%"},children:[e.jsx(T,{title:"Categoria",navigateBack:!0}),e.jsx(c,{sx:{px:2,py:2},children:e.jsxs(y,{spacing:1.5,children:[e.jsx(S,{variant:"rounded",height:72,sx:{borderRadius:2}}),e.jsx(S,{variant:"rounded",height:64,sx:{borderRadius:2}}),e.jsx(S,{variant:"text",width:120,sx:{mt:2,fontSize:"0.875rem"}}),[0,1,2].map(t=>e.jsx(S,{variant:"rounded",height:64,sx:{borderRadius:2}},t))]})})]});if(!a)return e.jsxs(c,{sx:{p:4,textAlign:"center"},children:[e.jsx(T,{title:"Categoria",navigateBack:!0}),e.jsx(p,{variant:"body2",color:"text.secondary",sx:{mt:4},children:"Categoria não encontrada."})]});const z=h.length>=2,b=V&&z;return e.jsxs(c,{sx:{position:"relative",minHeight:"100%",pb:3},children:[e.jsx(T,{title:b?"Reordenar":a.nome,navigateBack:!b,onBack:b?()=>D(!1):void 0,children:b?e.jsx(k,{size:"small",onClick:()=>D(!1),sx:{fontWeight:600},children:"Pronto"}):e.jsx(te,{edge:"end",onClick:t=>_(t.currentTarget),"aria-label":"Mais opções",children:e.jsx(qe,{})})}),e.jsxs(c,{sx:{px:2,py:2},children:[e.jsxs(c,{sx:{bgcolor:"white",borderRadius:2,px:2,py:1},children:[e.jsx(p,{variant:"caption",color:"text.secondary",sx:{dis
1play:"block",fontWeight:600},children:"Nome"}),e.jsx(Oe,{value:a.nome,onSave:Y,variant:"subtitle1",color:"text.primary",fontWeight:600,maxLength:40}),M&&e.jsx(p,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:.25,fontWeight:500},children:M})]}),e.jsx(q,{onClick:()=>n(`/products?category=${a.id}`),sx:{mt:1.5,width:"100%",bgcolor:"white",borderRadius:2,p:2,justifyContent:"flex-start",textAlign:"left"},children:e.jsxs(y,{direction:"row",alignItems:"center",spacing:1.5,sx:{width:"100%"},children:[e.jsxs(c,{sx:{flex:1},children:[e.jsx(p,{variant:"body1",sx:{fontWeight:600},children:"Ver produtos"}),e.jsxs(p,{variant:"caption",color:"text.secondary",children:[a.product_count??0," ",(a.product_count??0)===1?"produto":"produtos"]})]}),e.jsx(L,{size:20,color:A("#041E42",.35)})]})}),e.jsx(c,{sx:{mt:1.5},children:e.jsx(We,{icon:e.jsx(be,{size:je}),label:"Imagem e banner",description:F,badge:e.jsxs(y,{direction:"row",spacing:.75,alignItems:"center",children:[ye("category_media")&&e.jsx(Ce,{label:"Novo",tint:"brand"}),e.jsx(ve,{variant:o?"cutout":"contained",fontSize:11})]}),onClick:()=>n(`/categories/${a.id}/images`)})}),e.jsxs(c,{sx:{mt:3},children:[e.jsx(p,{variant:"subtitle2",color:"text.secondary",sx:{fontWeight:600,display:"block",px:.5,mb:1},children:"Subcategorias"}),h.length>0?e.jsx(Ie,{sensors:X,collisionDetection:_e,onDragEnd:G,children:e.jsx(we,{items:h.map(t=>t.id.toString()),strategy:Se,children:e.jsx(y,{spacing:1,children:h.map(t=>e.jsx(Ve,{category:t,childCount:U.get(t.id)||0,reorderMode:b,onTap:()=>n(`/categories/${t.id}`)},t.id))})})}):e.jsxs(c,{sx:{bgcolor:"white",borderRadius:2,p:2,display:"flex",gap:1.5,alignItems:"flex-start"},children:[e.jsx(c,{sx:{width:32,height:32,borderRadius:"50%",bgcolor:A("#8865FE",.1),color:"primary.main",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(ke,{size:16})}),e.jsx(p,{variant:"body2",color:"text.secondary",children:O?"Crie subcategorias para organizar esta categoria em grupos menores.":"Esta categoria já está no nÃvel mais interno e não pode ter subcategorias."})]}),O&&!b&&e.jsx(k,{fullWidth:!0,variant:"contained",size:"large",startIcon:e.jsx(Ee,{size:18}),onClick:()=>R(!0),sx:{borderRadius:2,py:1.5,mt:1.5},children:"Adicionar subcategoria"})]})]}),e.jsxs(ae,{anchorEl:B,open:!!B,onClose:()=>_(null),children:[z&&e.jsxs(P,{onClick:()=>{_(null),D(!0)},children:[e.jsx(H,{children:e.jsx(De,{size:20})}),e.jsx(W,{children:"Reordenar"})]}),e.jsxs(P,{onClick:()=>{_(null),w(!0)},children:[e.jsx(H,{children:e.jsx(Le,{fontSize:"small",color:"error"})}),e.jsx(W,{sx:{color:"error.main"},children:"Excluir categoria"})]})]}),e.jsxs(se,{open:Z,onClose:()=>w(!1),children:[e.jsxs(ne,{children:['Excluir "',a.nome,'"?']}),e.jsx(ie,{children:e.jsx(re,{children:"Os produtos não serão excluÃdos, apenas ficarão sem categoria."})}),e.jsxs(oe,{children:[e.jsx(k,{onClick:()=>w(!1),color:"primary",children:"Cancelar"}),e.jsx(k,{onClick:J,color:"error",disabled:C.isPending,autoFocus:!0,children:C.isPending?"Excluindo...":"Excluir"})]})]}),e.jsx(He,{open:Q,onClose:()=>R(!1),parentId:a.id,parentName:a.nome,onCreated:()=>R(!1)})]})},Ve=({category:n,childCount:d,reorderMode:o,onTap:m})=>{const{attributes:u,listeners:i,setNodeRef:E,transform:v,transition:C,isDragging:f}=Re({id:n.id.toString(),disabled:!o}),a={transform:Te.Transform.toString(v),transition:C,zIndex:f?999:"auto",opacity:f?.85:1,boxShadow:f?"0 8px 24px rgba(8,10,20,0.16)":"none",position:"relative"};return e.jsx(c,{ref:E,style:a,sx:{bgcolor:"white",borderRadius:2},children:e.jsxs(y,{direction:"row",alignItems:"center",sx:{width:"100%",minHeight:64},children:[o&&e.jsx(c,{...u,...i,sx:{px:1.5,py:1.75,color:"text.disabled",cursor:"grab",touchAction:"none","&:active":{cursor:"grabbing"}},"aria-label":"Arrastar para reordenar",children:e.jsx(Fe,{})}),e.jsx(q,{onClick:o?void 0:m,disabled:o,sx:{flex:1,px:o?1:2,py:1.5,justifyContent:"flex-start",textAlign:"left",borderRadius:2},children:e.jsxs(y,{direction:"row",alignItems:"center",spacing:1.5,sx:{width:"100%"},children:[e.jsxs(c,{sx:{flex:1,minWidth:0},children:[e.jsx(p,{variant:"body1",sx:{fontWeight:600,textTransform:"none"},children:n.nome}),e.jsxs(p,{variant:"caption",color:"text.secondary",children:[n.product_count??0," ",(n.product_count??0)===1?"produto":"produtos",d>0&&` · ${d} ${d===1?"subcategoria":"subcategorias"}`]})]}),!o&&e.jsx(L,{size:20,color:A("#041E42",.35)})]})})]})})};export{dt 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.