1import{j as e,a9 as y,aa as I,ab as o,a7 as t,T as r,a2 as w,ao as f,o as S,N as C,ad as E,I as W,Q as N,at as $,n as k,ar as T,ac as P,X as q,ai as V,Z as Q,aq as J,O as Y}from"./mui-CRsYZxVY.js";import{r as g}from"./vendor-Dwao9eNC.js";import{bF as H,f as K,bo as U,bp as X,cF as Z,w as G,t as ee,l as ne,b as M,e as se,x as te,cu as re,cv as oe,a$ as L,b1 as ae,J as ie,T as z}from"./index-TALscxEc.js";import{Y as ce,ac as le,ad as de,c as xe,ae as he,z as ue,a6 as fe,k as je,M as me,b as pe,D as ge}from"./icons-D8aatgQ4.js";import{u as ye}from"./useSupplier-DvF4zMpW.js";import{a as be,b as ve}from"./query-8ViTdhdk.js";import{u as Se,S as we,a as Ce}from"./StockMovementSkeleton-OwZxa3oJ.js";import"./datePickers-BIJXYOKG.js";import"./lab-DSem1Osk.js";import"./ProductAvatar-BTM6y7KS.js";import"./getMovementTypeInfo-D9It_2AF.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:{},s=new n.Error().stack;s&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[s]="44011e8d-0994-4fc7-970c-943682a8d299",n._sentryDebugIdIdentifier="sentry-dbid-44011e8d-0994-4fc7-970c-943682a8d299")})()}catch{}const j=({icon:n,label:s,value:a})=>a?e.jsxs(o,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(t,{sx:{color:"primary.main"},children:n}),e.jsxs(t,{flex:1,children:[e.jsx(r,{variant:"caption",color:"text.secondary",children:s}),e.jsx(r,{variant:"body2",children:a})]})]}):null,Ie=()=>e.jsx(y,{elevation:1,children:e.jsx(I,{children:e.jsxs(o,{spacing:2,children:[e.jsxs(t,{children:[e.jsx(r,{variant:"h6",gutterBottom:!0,children:e.jsx(f,{width:"40%"})}),e.jsx(r,{variant:"caption",children:e.jsx(f,{width:"20%"})})]}),e.jsx(w,{}),e.jsx(o,{spacing:2,children:[...Array(5)].map((n,s)=>e.jsxs(o,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(t,{sx:{color:"primary.main"},children:e.jsx(f,{variant:"circular",width:24,height:24})}),e.jsxs(t,{flex:1,children:[e.jsx(f,{width:"20%"}),e.jsx(f,{width:"60%"})]})]},s))})]})})}),B=({supplier:n,isLoading:s=!1})=>{const a=h=>U(Z(h),"PPP",{locale:X});return s?e.jsx(Ie,{}):n?e.jsx(y,{elevation:1,children:e.jsx(I,{children:e.jsxs(o,{spacing:2,children:[e.jsxs(t,{children:[e.jsx(r,{variant:"h6",gutterBottom:!0,fontWeight:500,children:n.nome}),e.jsx(r,{variant:"caption",color:"text.secondary",children:`Cadastrado em ${a(n.criado_em)}`})]}),e.jsx(w,{}),e.jsxs(o,{spacing:2,children:[e.jsx(j,{icon:e.jsx(H,{}),label:"CPF/CNPJ",value:n.cpf_cnpj}),e.jsx(j,{icon:e.jsx(ce,{}),label:"Responsável",value:n.nome_responsavel}),e.jsx(j,{icon:e.jsx(le,{}),label:"Telefone",value:K(n.telefone||"")}),e.jsx(j,{icon:e.jsx(de,{}),label:"Email",value:n.email}),e.jsx(j,{icon:e.jsx(xe,{}),label:"Endereço",value:n.endereco}),n.observacoes&&e.jsxs(e.Fragment,{children:[e.jsx(w,{}),e.jsxs(o,{spacing:1,children:[e.jsxs(o,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(he,{fontSize:"small",color:"primary"}),e.jsx(r,{variant:"caption",color:"text.secondary",children:"Observações"})]}),e.jsx(r,{variant:"body2",whiteSpace:"pre-wrap",children:n.observacoes})]})]})]})]})})}):null},De=()=>{const n=be();return ve({mutationFn:async({id:s})=>{const{error:a}=await G.from("fornecedor").update({deletado_em:new Date().toISOString()}).eq("id",s);if(a)throw a;return s},onSuccess:s=>{ee(ne.DELETE.SUPPLIER,{supplierId:s}),n.invalidateQueries({queryKey:["suppliers"]})}})};function Ee({supplierId:n}){const s=M(),{data:a}=se(),h=te(a),{data:u,isLoading:b}=re({enabled:h}),i=g.useMemo(()=>{const x=(u||[]).filter(c=>c.fornecedor_id===n&&c.status==="pendente"),m=x.filter(c=>oe(L(new Date(c.data_vencimento)),L(new Date))).length,d=x.filter(c=>ae(new Date(c.data_vencimento))).length;return{count:x.length,total:x.reduce((c,p)=>c+p.valor,0),overdue:m,today:d}},[u,n]);return!h||b||i.count===0?null:e.jsxs(t,{children:[e.jsx(r,{variant:"subtitle1",gutterBottom:!0,fontWeight:500,color:"primary",sx:{px:1,mb:2},children:"Contas a pagar"}),e.jsx(y,{sx:{boxShadow:"none"},children:e.jsx(I,{sx:{p:2},children:e.jsxs(o,{spacing:1,children:[e.jsxs(o,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsx(r,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:"Total em aberto"}),e.jsx(r,{variant:"body1",fontWeight:600,color:"primary",children:i.total.toLocaleStr
1ing("pt-BR",{style:"currency",currency:"BRL"})})]}),i.overdue>0&&e.jsxs(o,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{py:1},children:[e.jsxs(o,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(t,{sx:{bgcolor:S("#f44336",.12),borderRadius:"50%",p:.5,display:"flex",justifyContent:"center",alignItems:"center",color:"#f44336"},children:e.jsx(ue,{fontSize:"small"})}),e.jsx(r,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:"Em atraso"})]}),e.jsx(r,{variant:"h6",fontWeight:"bold",color:"error.main",sx:{fontSize:"1.15rem"},children:i.overdue})]}),i.today>0&&e.jsxs(o,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{py:1},children:[e.jsxs(o,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(t,{sx:{bgcolor:S("#ff9800",.12),borderRadius:"50%",p:.5,display:"flex",justifyContent:"center",alignItems:"center",color:"#ff9800"},children:e.jsx(fe,{fontSize:"small"})}),e.jsx(r,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:i.today===1?"Vence hoje":"Vencem hoje"})]}),e.jsx(r,{variant:"h6",fontWeight:"bold",color:"warning.main",sx:{fontSize:"1.15rem"},children:i.today})]}),e.jsx(t,{sx:{display:"flex",justifyContent:"flex-end"},children:e.jsx(C,{onClick:()=>s(`/contas-a-pagar?fornecedor=${n}`),size:"small",endIcon:e.jsx(je,{sx:{fontSize:16}}),sx:{color:"text.secondary",fontSize:"0.8rem",fontWeight:500,py:.5,px:1.5,"&:hover":{bgcolor:x=>S(x.palette.primary.main,.08)},textTransform:"none"},children:"Ver contas"})})]})})})]})}const Oe=()=>{const{supplierId:n}=ie(),s=M(),a=Number(n),[h,u]=g.useState(null),[b,i]=g.useState(!1),[x,m]=g.useState(null),{data:d,isLoading:c}=ye(a),{data:p=[],isLoading:_}=Se({supplierId:a}),D=De(),A=l=>{u(l.currentTarget)},v=()=>{u(null)},R=()=>{s(`/suppliers/${a}/edit`),v()},F=()=>{i(!0),v()},O=async()=>{try{await D.mutateAsync({id:a}),s("/suppliers")}catch(l){m((l==null?void 0:l.message)||"Erro ao excluir fornecedor"),i(!1)}};return!d&&!c?e.jsxs(t,{sx:{height:"70vh",display:"flex",flexDirection:"column"},children:[e.jsx(z,{title:"Detalhes do fornecedor",navigateBack:!0}),e.jsx(t,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",p:2},children:e.jsx(E,{severity:"error",children:"Fornecedor não encontrado"})})]}):e.jsxs(t,{sx:{display:"flex",flexDirection:"column"},children:[e.jsx(z,{title:"Detalhes do fornecedor",navigateBack:!0,children:e.jsx(W,{color:"inherit",onClick:A,children:e.jsx(me,{})})}),e.jsx(t,{sx:{flex:1,overflow:"auto",p:2,pb:2},children:e.jsxs(o,{spacing:2,children:[x&&e.jsx(E,{severity:"error",onClose:()=>m(null),children:x}),e.jsx(y,{elevation:1,children:c?e.jsx(t,{children:e.jsx(B,{supplier:d,isLoading:!0})}):d&&e.jsx(B,{supplier:d})}),e.jsx(Ee,{supplierId:a}),e.jsxs(t,{children:[e.jsx(r,{variant:"subtitle1",gutterBottom:!0,fontWeight:500,color:"primary",sx:{px:1,mb:2},children:"Histórico de movimentações"}),_?e.jsx(o,{spacing:1,children:[1,2,3].map(l=>e.jsx(we,{},l))}):p.length===0?e.jsx(t,{sx:{p:4},children:e.jsx(r,{color:"text.secondary",textAlign:"center",variant:"body2",children:"Nenhuma movimentação registrada para este fornecedor"})}):e.jsx(N,{disablePadding:!0,children:p.map(l=>e.jsx(Ce,{...l,hideProduct:!1,hideSupplier:!0,onClick:()=>s(`/stock/movements/${l.id}`)},l.id))})]})]})}),e.jsxs($,{anchorEl:h,open:!!h,onClose:v,children:[e.jsxs(k,{onClick:R,children:[e.jsx(T,{children:e.jsx(pe,{fontSize:"small"})}),e.jsx(P,{children:"Editar"})]}),e.jsxs(k,{onClick:F,children:[e.jsx(T,{children:e.jsx(ge,{fontSize:"small"})}),e.jsx(P,{children:"Excluir"})]})]}),e.jsxs(q,{open:b,onClose:()=>i(!1),children:[e.jsx(V,{children:"Excluir fornecedor"}),e.jsx(Q,{children:e.jsxs(J,{children:["Tem certeza que deseja excluir este fornecedor?",(d==null?void 0:d.nome)&&` "${d.nome}"`]})}),e.jsxs(Y,{children:[e.jsx(C,{onClick:()=>i(!1),children:"Cancelar"}),e.jsx(C,{onClick:O,color:"error",disabled:D.isPending,children:"Excluir"})]})]})]})};export{Oe 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.