1var oe=Object.defineProperty,ie=Object.defineProperties;var ne=Object.getOwnPropertyDescriptors;var te=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var ae=(e,t,a)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,O=(e,t)=>{for(var a in t||(t={}))re.call(t,a)&&ae(e,a,t[a]);if(te)for(var a of te(t))le.call(t,a)&&ae(e,a,t[a]);return e},Z=(e,t)=>ie(e,ne(t));var W=(e,t,a)=>new Promise((p,h)=>{var b=m=>{try{v(a.next(m))}catch(C){h(C)}},N=m=>{try{v(a.throw(m))}catch(C){h(C)}},v=m=>m.done?p(m.value):Promise.resolve(m.value).then(b,N);v((a=a.apply(e,t)).next())});import{r as o,d as ce,j as s}from"./vendor-BlJ90GWG.js";import{m as de,u as ue,o as me,l as ge,t as pe,aj as he,n as be,r as fe,B as ve,c4 as Ce,X as _e,ab as ye,c5 as Pe,x as xe,L as ke,T as je,bu as Se,_ as Ae}from"./index-BIHwndtW.js";import{p as se,a as ee}from"./productService-yNlwgCrp.js";import{u as Ne}from"./useDebounce-DdJ7lloX.js";import{H as Te}from"./HelpButton-BV0JJIfF.js";import{S as Ee}from"./SearchInput-DSeNCzLI.js";import{S as De}from"./Select-CGDbQs1i.js";import{T as Ie}from"./Tabs-B3oeE_nw.js";import{A as we}from"./ActionsDropdown-CEk78LeB.js";import"./pdf-Ba4Lif-1.js";import"./charts-i6LaAsIH.js";(function(){try{var e=typeof window!="undefined"?window:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:{};e.SENTRY_RELEASE={id:"0d78e8d78eda4804299eff0767f9df5613e65c75"};var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="6449a5b7-bf3b-47a9-8acc-9b3b692f06be",e._sentryDebugIdIdentifier="sentry-dbid-6449a5b7-bf3b-47a9-8acc-9b3b692f06be")}catch(a){}})();const Me=400,Fe={search:"",status:"all",kind:"all"};function Be(e,t,a,p){const h={page:a,per_page:p};return e.status!=="all"&&(h.is_active=e.status==="active"?"1":"0"),e.kind!=="all"&&(h.kind=e.kind),t&&(h.search=t),h}const Le=()=>{var B,$,r,l,d,_,L,H,R;const{showToast:e}=de(),t=ue(),a=me(),[p,h]=o.useState(Fe),[b,N]=o.useState(1),[v]=o.useState(10),[m,C]=o.useState(!1),[T,w]=o.useState(null),[E,f]=o.useState(!1),[X,K]=o.useState([]),D=Ne(p.search,Me),M=o.useMemo(()=>Be(p,D,b,v),[p,D,b,v]),k=o.useMemo(()=>se.list(t,M),[t,M]),g=ge({queryKey:k,queryFn:u=>W(null,[u],function*({signal:n}){var y,q,z,x,A,I;const i=yield ee.getProducts(t,M,{signal:n});return{products:Array.isArray(i==null?void 0:i.data)?i.data:[],totalPages:(q=(y=i==null?void 0:i.meta)==null?void 0:y.lastPage)!=null?q:1,currentPage:(x=(z=i==null?void 0:i.meta)==null?void 0:z.currentPage)!=null?x:b,total:(I=(A=i==null?void 0:i.meta)==null?void 0:A.total)!=null?I:0}}),placeholderData:pe,staleTime:0,retry:!1}),F=o.useMemo(()=>{var n,u;return(u=(n=g.data)==null?void 0:n.products)!=null?u:[]},[g.data]),j=g.isError?((r=($=(B=g.error)==null?void 0:B.response)==null?void 0:$.data)==null?void 0:r.message)||"Não foi possÃvel carregar o catálogo.":null;o.useEffect(()=>{j&&e({type:"error",title:"Erro",message:j})},[j,e]);const S=o.useCallback(()=>a.invalidateQueries({queryKey:se.all()}),[a]),P=o.useCallback((n,u)=>{K(i=>u?i.includes(n)?i:[...i,n]:i.filter(y=>y!==n))},[]),Q=o.useCallback(n=>{h(u=>O(O({},u),n)),N(1)},[]),Y=o.useCallback(n=>{N(n)},[]),G=o.useCallback(n=>{w(n),C(!0)},[]),U=o.useCallback(()=>{C(!1),w(null),f(!1)},[]),V=o.useCallback(()=>W(null,null,function*(){var u,i;if(!T)return;const n=T.id;f(!0),P(n,!0);try{yield ee.deleteProduct(t,n),yield S(),e({type:"success",title:"Sucesso",message:"Item excluÃdo com sucesso!"}),C(!1),w(null)}catch(y){e({type:"error",title:"Não foi possÃvel excluir",message:((i=(u=y.response)==null?void 0:u.data)==null?void 0:i.message)||"Não foi possÃvel excluir o item."})}finally{f(!1),P(n,!1)}}),[t,T,S,P,e]),J=o.useCallback(n=>W(null,null,function*(){var q,z;const u=F.find(x=>x.id===n);if(!u)return;const i=!u.isActive;P(n,!0),yield a.cancelQueries({queryKey:k});const y=x=>a.setQueryData(k,A=>A&&Z(O({},A),{products:A.products.map(I=>I.id===n?Z(O({},I),{isActive:x}):I)}));y(i);try{yield ee.updateProductStatus(t,n,i),yield S(),e({type:"success",title:"Sucesso",message:`Item ${i?"ativado":"desativado"} com sucesso!`})}catch(x){y(u.isActive),e({type:"error",title:"Erro",message:((z=(q=x.response)==null?void 0:q.data)==null?void 0:z.message)||"Não foi possÃvel alterar o status do item."})}finally{P(n,!1)}}),[t,F,a,k,S,P,e]);return{products:F,loading:g.isPending,error:j,currentPage:(d=(l=g.data)==null?void 0:l.currentPage)!=null?d:b,totalPages:(L=(_=g.data)==null?void 0:_.totalPages)!=null?L:1,total:(R=(H=g.data)==null?void 0:H.total)!=null?R:0,itemsPerPage:v,filters:p,isDeleteModalOpen:m,productToDelete:T,deletingProduct:E,pendingActions:X,refetch:g.refetch,handlePageChange:Y,setFilters:Q,openDeleteConfirmationModal:G,closeDeleteConfirmationModal:U,confirmDeleteProduct:V,toggleProductStatus:J}},Re="_container_1be2a_7",qe="_header_1be2a_13",ze="_titleContainer_1be2a_22",Oe="_title_1be2a_22",Ke="_subtitle_1be2a_36",Qe="_headerActions_1be2a_42",$e="_controls_1be2a_49",He="_searchRow_1be2a_58",We="_searchField_1be2a_65",Xe="_filterSelect_1be2a_70",Ye="_nameCell_1be2a_76",Ge="_nameText_1be2a_83",Ue="_deliverablesBadge_1be2a_88",Ve="_noPrice_1be2a_94",Je="_actionsContainer_1be2a_101",Ze="_empty_1be2a_107",c={container:Re,header:qe,titleContainer:ze,title:Oe,subtitle:Ke,headerActions:Qe,controls:$e,searchRow:He,searchField:We,filterSelect:Xe,nameCell:Ye,nameText:Ge,deliverablesBadge:Ue,noPrice:Ve,actionsContainer:Je,empty:Ze},et={one_time:"Ãnica",monthly:"Mensal",quarterly:"Trimestral",yearly:"Anual"},gt=()=>{const e=ce(),t=he(),{user:a,hasPermission:p}=be(),b=(a==null?void 0:a.role)==="super_admin"||(a==null?void 0:a.role)==="admin"||p("access_financial"),{products:N,loading:v,currentPage:m,totalPages:C,total:T,itemsPerPage:w,filters:E,setFilters:f,handlePageChange:X,isDeleteModalOpen:K,productToDelete:D,deletingProduct:M,openDeleteConfirmationModal:k,closeDeleteConfirmationModal:g,confirmDeleteProduct:F,toggleProductStatus:j,pendingActions:S}=Le(),P=o.useCallback(()=>e(`${t}/products/add`),[e,t]),Q=o.useCallback(r=>e(`${t}/products/edit/${r}`),[e,t]),Y=o.useMemo(()=>[{id:"all",label:"Todos"},{id:"active",label:"Ativos"},{id:"inactive",label:"Inativos"}],[]),G=o.useMemo(()=>[{value:"service",label:"Serviços"},{value:"product",label:"Produtos"}],[]),U=o.useCallback(r=>f({search:r.target.value}),[f]),V=o.useCallback(r=>f({status:r}),[f]),J=o.useCallback(r=>f({kind:r||"all"}),[f]),B=o.useCallback(r=>S.includes(r),[S]),$=o.useMemo(()=>{const r=[{key:"code",title:"Código",width:"10%",render:l=>l||"â"},{key:"name",title:"Nome",width:b?"26%":"36%",render:(l,d)=>{var _;return s.jsxs("div",{className:c.nameCell,children:[s.jsx("span",{className:c.nameText,children:l}),((_=d.deliverables)==null?void 0:_.length)>0&&s.jsxs("span",{className:c.deliverablesBadge,children:[d.deliverables.length," ",d.deliverables.length===1?"entregável":"entregáveis"]})]})}},{key:"kind",title:"Tipo",width:"12%",render:l=>l==="product"?"Produto":"Serviço"},{key:"billingCycle",title:"Cobrança",width:"13%",render:l=>et[l]||"â"}];return b&&r.push({key:"unitPrice",title:"Preço",width:"15%",align:"right",render:l=>l==null?s.jsx("span",{className:c.noPrice,children:"A combinar"}):fe(l)}),r.push({key:"isActive",title:"Status",width:"12%",render:l=>s.jsx(ve,{variant:l?"success":"soft-neutral",size:"sm",children:l?"Ativo":"Inativo"})},{key:"actions",title:"Ações",width:"80px",align:"right",sortable:!1,render:(l,d)=>{var R;const _=B(d.id),L=((R=d.projectLinksCount)!=null?R:0)>0,H=[{icon:s.jsx(Ce,{size:16}),label:"Editar",onClick:()=>Q(d.id),disabled:_},{icon:d.isActive?s.jsx(_e,{size:16}):s.jsx(ye,{size:16}),label:d.isActive?"Desativar":"Ativar",onClick:()=>j(d.id),disabled:_},{icon:s.jsx(Pe,{size:16}),label:L?"Excluir (em uso)":"Excluir",onClick:()=>k(d),disabled:_||L,danger:!0}];return s.jsx("div",{className:c.actionsContainer,children:s.jsx(we,{actions:H,size:"sm"})})}}),r},[b,B,Q,j,k]);return s.jsxs("div",{className:c.container,children:[s.jsxs("div",{className:c.header,children:[s.jsxs("div",{className:c.titleContainer,children:[s.jsx("h1",{className:c.title,children:"Produtos e serviços"}),s.jsx("p",{className:c.subtitle,children:"Cadastre o que a sua agência vende e vincule aos projetos"}),s.jsx(Te,{collection:"produtos-e-servicos"})]}),s.jsx("div",{className:c.headerActions,children:s.jsx(xe,{variant:"primary",icon:s.jsx(ke,{size:16}),onClick:P,children:"Novo item"})})]}),s.jsxs("div",{className:c.controls,children:[s.jsxs("div",{className:c.searchRow,children:[s.jsx("div",{className:c.searchField,children:s.jsx(Ee,{id:"search-products",placeholder:"Buscar por nome, código ou descrição...",value:E.search,onChange:U,fullWidth:!0})}),s.jsx(De,{id:"filter-kind",name:"kind",value:E.kind==="all"?"":E.kind,onChange:J,options:G,placeholder:"Todos os tipos",fullWidth:!1,className:c.filterSelect})]}),s.jsx(Ie,{variant:"underline",tabs:Y,activeId:E.status,onChange:V,ariaLabel:"Filtrar itens por status"})]}),s.jsx(je,{columns:$,data:N,loading:v,getRowId:r=>r.id,emptyMessage:s.jsxs("span",{className:c.empty,children:[s.jsx(Se,{size:16}),"Seu catálogo está vazio. Cadastre o que a agência vende (gestão de tráfego, social media, criação de siteâ¦) para depois vincular aos projetos."]}),pagination:{currentPage:m,lastPage:C,total:T,perPage:w},onPageChange:X,paginationAlign:"right"}),K&&s.jsx(Ae,{isOpen:K,onClose:g,onConfirm:F,title:"Excluir item do catálogo",message:`Tem certeza que deseja excluir "${D==null?void 0:D.name}"? Itens vinculados a projetos não podem ser excluÃdos â nesse caso, desative-o para retirá-lo do seletor sem afetar os projetos existentes.`,confirmText:"Excluir",cancelText:"Cancelar",type:"error",isProcessing:M,confirmButtonVariant:"danger"})]})};export{gt 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.