1import{j as e,a7 as r,a2 as U,T as i,ab as d,X as M,ai as $,Z as N,a6 as us,H as ms,aD as gs,O as G,N as b,a9 as v,aa as be,ao as w,o as D,I as fs,at as js,n as ve,ar as Ce,ac as B,aq as V,Q as ys,as as we}from"./mui-CRsYZxVY.js";import{r as j,b as bs}from"./vendor-Dwao9eNC.js";import{w as De,t as We,l as Le,ed as vs,gb as Se,b as ee,bL as Pe,L as Cs,d as Be,N as Re,cv as ws,a$ as _e,b1 as Ss,aP as Ie,aR as _s,J as Is,c8 as ks,v as Es,gc as Ts,gd as As,ge as Ds,e as Ws,bX as Ls,cM as Ps,T as ke,b3 as R,eK as Bs,f as Rs,eB as zs,bd as Os,c0 as Ms,gf as $s,eI as Ee,gg as Ns,fU as Us}from"./index-TALscxEc.js";import{Z as qs}from"./index-DK05pnC7.js";import{u as Fs}from"./useCustomerAddresses-DvZt7JUJ.js";import{u as Qs}from"./useAddressUsedInOrders-sAMvb8LS.js";import{u as Ks}from"./useCustomerAddressMutations-BiKiu96-.js";import{a as ze,b as Oe}from"./query-8ViTdhdk.js";import{C as Hs}from"./CustomerAddressListItem-C-6kO7D1.js";import{ar as J,b as X,W as se,z as Vs,a6 as Ys,p as Zs,k as Gs,M as Js,as as Xs,at as en,au as sn,av as nn,e as Y,aw as tn,c as Te,d as z,D as rn,a as Ae}from"./icons-D8aatgQ4.js";import{u as an}from"./useCustomerInstallments-BZncTEtU.js";import{C as on}from"./CobrancaWhatsAppModal-BMGONXcd.js";import"./datePickers-BIJXYOKG.js";import"./lab-DSem1Osk.js";import"./usePixKeys-CKz2VBnr.js";import"./listaDeBancos-DVgYDDAw.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:{},a=new n.Error().stack;a&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[a]="de071446-2e8f-43b5-9a57-4f755b540c96",n._sentryDebugIdIdentifier="sentry-dbid-de071446-2e8f-43b5-9a57-4f755b540c96")})()}catch{}const ln=()=>{const n=ze();return Oe({mutationFn:async a=>{const{data:p,error:c}=await De.from("cliente").update({deletado_em:new Date().toISOString()}).eq("id",a).select("id, nome").single();if(c)throw new Error(c.message||"Erro ao excluir cliente");return p},onSuccess:a=>{We(Le.DELETE.CUSTOMER,{customerId:a.id,customerName:a.nome}),n.invalidateQueries({queryKey:["customers"]}),n.invalidateQueries({queryKey:["customers-count"]}),n.invalidateQueries({queryKey:["customer"]}),n.invalidateQueries({queryKey:["customerAddresses"]}),n.invalidateQueries({queryKey:["orders"]})}})},dn=()=>{const n=ze();return Oe({mutationFn:async a=>{const{data:p,error:c}=await De.from("cliente").update({deletado_em:null}).eq("id",a).select("id, nome").single();if(c)throw new Error(c.message||"Erro ao restaurar cliente");return p},onSuccess:a=>{We(Le.DELETE.CUSTOMER_RESTORE,{customerId:a.id,customerName:a.nome}),n.invalidateQueries({queryKey:["customers"]}),n.invalidateQueries({queryKey:["customers-count"]}),n.invalidateQueries({queryKey:["customer"]}),n.invalidateQueries({queryKey:["customerAddresses"]}),n.invalidateQueries({queryKey:["orders"]})}})},cn=["canceled","returned"],Z=({label:n,value:a})=>e.jsxs(r,{sx:{flex:1,minWidth:0,textAlign:"center",px:.5},children:[e.jsx(i,{variant:"subtitle1",fontWeight:600,noWrap:!0,children:a}),e.jsx(i,{variant:"caption",color:"text.secondary",component:"div",noWrap:!0,children:n})]}),xn=({orders:n})=>{const{salesCount:a,averageTicket:p,totalSpent:c}=j.useMemo(()=>{const l=n.filter(o=>!cn.includes(o.status_pedido)),C=l.reduce((o,u)=>{var g;const y=((g=u.frete_pedido)==null?void 0:g.valor_frete)||0,h=u.valor_desconto||0,m=u.taxa_de_venda||0;return o+u.subtotal+y+m-h},0);return{salesCount:l.length,totalSpent:C,averageTicket:l.length>0?C/l.length:0}},[n]);return e.jsxs(r,{sx:{py:.5,display:"flex",alignItems:"center"},children:[e.jsx(Z,{label:"Vendas",value:vs(a)}),e.jsx(U,{orientation:"vertical",flexItem:!0,sx:{my:.5}}),e.jsx(Z,{label:"Ticket médio",value:Se(p)}),e.jsx(U,{orientation:"vertical",flexItem:!0,sx:{my:.5}}),e.jsx(Z,{label:"Total gasto",value:Se(c)})]})},A=({icon:n,label:a,value:p,action:c,onClick:l,variant:C="primary"})=>{const o=typeof l=="function",u=C==="secondary";return e.jsxs(d,{direction:"row",spacing:1.5,alignItems:"center",onClick:l,sx:{mx:-1,px:1,py:.75,borderRadius:2,cursor:o?"pointer":"default",transition:"background-color 0.15s ease","&:hover":o?{bgcolor:"background.default"}:void 0},children:[e.jsx(r,{sx:{display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:u?"text.disabled":"text.secondary","& svg":{fontSize:u?18:20}},children:n}),e.jsxs(r,{sx:{flex:1,minWidth:0},children:[e.jsx(i,{variant:"caption",color:"text.secondary",sx:{dis
1play:"block",lineHeight:1.2},children:a}),e.jsx(i,{variant:"body2",fontWeight:u?500:700,color:u?"text.secondary":"text.primary",sx:{wordBreak:"break-word",lineHeight:1.35},children:p})]}),c&&e.jsx(r,{sx:{flexShrink:0,ml:.5},onClick:y=>y.stopPropagation(),children:c})]})},hn=`Olá $primeiro_nome, feliz aniversário! ð 2 3Que seu dia seja incrÃvel e cheio de alegrias. 4 5Atenciosamente, 6Equipe $loja 7 8$link`,pn=({open:n,onClose:a,customerId:p})=>{const[c,l]=j.useState(""),C=ee(),{data:o,isLoading:u}=Pe(p),{data:y,isLoading:h}=Cs(),{data:m,isLoading:g}=Be(),{storeUrl:_}=Re();j.useEffect(()=>{if(n)if(o){const f=o.nome||"Cliente",k=f.split(" ")[0],W=(m==null?void 0:m.nome_loja)||"Nossa loja",q=_,Q=((y==null?void 0:y.template_mensagem_aniversario)||hn).replace(/\$nome/g,f).replace(/\$primeiro_nome/g,k).replace(/\$loja/g,W).replace(/\$link/g,q);l(Q)}else l("");else l("")},[n,o,y,m,_]);const I=()=>{o!=null&&o.telefone&&(window.open(`https://wa.me/${o.telefone}?text=${encodeURIComponent(c)}`,"_blank"),a())},S=n&&(u||h||g);return e.jsxs(M,{open:n,onClose:a,fullWidth:!0,maxWidth:"sm",children:[e.jsx($,{children:e.jsxs(r,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(J,{}),"Mensagem de aniversário"]})}),e.jsx(N,{sx:{pt:3},children:S?e.jsx(r,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:150},children:e.jsx(us,{})}):e.jsxs(e.Fragment,{children:[e.jsxs(i,{variant:"body2",sx:{mb:1},children:["Mensagem para ",(o==null?void 0:o.nome)||"...",":"]}),e.jsx(ms,{elevation:1,sx:{p:2,overflowY:"auto",mb:1.5,fontFamily:"Arial, sans-serif",fontSize:"13px",backgroundColor:"#E0F6CA",borderRadius:"12px 12px 0 12px",position:"relative",wordBreak:"break-word",whiteSpace:"pre-wrap"},children:c||"Carregando prévia da mensagem..."}),e.jsxs(gs,{component:"button",variant:"body2",onClick:()=>{a(),C("/customers/birthdays/template")},sx:{display:"flex",alignItems:"center",color:"text.secondary",textDecoration:"none",fontSize:"13px",mb:1,"&:hover":{textDecoration:"underline"}},disabled:S,children:[e.jsx(X,{fontSize:"small",sx:{mr:.5,fontSize:"16px"}}),"Editar modelo de mensagem"]})]})}),e.jsxs(G,{children:[e.jsx(b,{onClick:a,disabled:S,children:"Cancelar"}),e.jsx(b,{onClick:I,startIcon:e.jsx(se,{}),variant:"contained",disabled:!(o!=null&&o.telefone)||!c||S,children:"Enviar"})]})]})};function un({customerId:n,customerName:a,customerPhone:p}){const c=ee(),{data:l,isLoading:C}=an(n),[o,u]=j.useState(!1),y=j.useMemo(()=>!l||l.length===0?[]:[{customerId:n,customerName:a,customerPhone:p||"",installments:l}],[n,a,p,l]),h=j.useMemo(()=>{if(!l)return{overdue:0,today:0,pending:0,totalOwed:0};const g=l.filter(f=>f.status_parcela==="pendente"),_=g.filter(f=>ws(_e(new Date(f.data_vencimento)),_e(new Date))),I=g.filter(f=>Ss(new Date(f.data_vencimento))),S=Ie(g.map(f=>_s(f.valor_original,Ie((f.pagamentos??[]).filter(k=>k.status==="pago").map(k=>k.valor)))));return{overdue:_.length,today:I.length,pending:g.length,totalOwed:S}},[l]),m=()=>{c(`/customers/${n}/contas-a-receber`)};return!C&&(!l||l.length===0)?e.jsx(v,{sx:{p:4,textAlign:"center"},children:e.jsx(i,{color:"text.secondary",children:"Este cliente não possui contas pendentes"})}):C?e.jsx(v,{sx:{boxShadow:"none"},children:e.jsx(be,{sx:{p:2},children:e.jsxs(d,{spacing:2,children:[e.jsx(w,{width:"100%",height:24}),e.jsx(w,{width:"100%",height:36})]})})}):e.jsxs(v,{sx:{boxShadow:"none"},children:[e.jsx(be,{sx:{p:2},children:e.jsxs(d,{spacing:2,children:[e.jsxs(d,{spacing:1,children:[e.jsxs(d,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsx(i,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:"Total em aberto"}),e.jsx(i,{variant:"body1",fontWeight:600,color:h.totalOwed>0?"primary":"text.secondary",children:h.totalOwed.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})})]}),h.overdue>0&&e.jsxs(d,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{py:1},children:[e.jsxs(d,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(r,{sx:{bgcolor:D("#f44336",.12),borderRadius:"50%",p:.5,display:"flex",justifyContent:"center",alignItems:"center",color:"#f44336"},children:e.jsx(Vs,{fontSize:"small"})}),e.jsx(i,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:"Em atraso"})]}),e.jsx(i,{variant:"h6",fontWeight:"bold",color:"error.main",sx:{fontSize:"1.15rem"},children:h.overdue})]}),h.today>0&&e.jsxs(d,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{py:1},children:[e.jsxs(d,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(r,{sx:{bgcolor:D("#ff9800",.12),borderRadius:"50%",p:.5,display:"flex",justifyContent:"center",alignItems:"center",color:"#ff9800"},children:e.jsx(Ys,{fontSize:"small"})}),e.jsx(i,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:"Vencem hoje"})]}),e.jsx(i,{variant:"h6",fontWeight:"bold",color:"warning.main",sx:{fontSize:"1.15rem"},children:h.today})]}),h.pending>0&&h.overdue===0&&h.today===0&&e.jsxs(d,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{py:1},children:[e.jsxs(d,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(r,{sx:{bgcolor:D("#2196f3",.12),borderRadius:"50%",p:.5,display:"flex",justifyContent:"center",alignItems:"center",color:"#2196f3"},children:e.jsx(Zs,{fontSize:"small"})}),e.jsx(i,{variant:"body2",color:"text.secondary",sx:{fontSize:"0.85rem"},children:"Parcelas pendentes"})]}),e.jsx(i,{variant:"h6",fontWeight:"bold",color:"info.main",sx:{fontSize:"1.15rem"},children:h.pending})]})]}),e.jsx(b,{fullWidth:!0,variant:"contained",startIcon:e.jsx(se,{}),onClick:()=>u(!0),disabled:!p,sx:{bgcolor:"#25D366",color:"white",mt:1,fontWeight:600,textTransform:"none","&:hover":{bgcolor:"#1DA851"},"&:disabled":{bgcolor:"grey.200",color:"text.disabled"}},children:p?"Cobrar via WhatsApp":"Cliente sem telefone cadastrado"}),e.jsx(r,{sx:{display:"flex",justifyContent:"flex-end"},children:e.jsx(b,{onClick:m,size:"small",endIcon:e.jsx(Gs,{sx:{fontSize:16}}),sx:{color:"text.secondary",fontSize:"0.8rem",fontWeight:500,py:.5,px:1.5,"&:hover":{bgcolor:g=>D(g.palette.primary.main,.08)},textTransform:"none"},children:"Ver contas"})})]})}),e.jsx(on,{open:o,onClose:()=>u(!1),customers:y,defaultMode:"urgent"})]})}const O=({children:n})=>e.jsx(i,{variant:"h6",sx:{fontWeight:500,color:"text.primary",mb:2,mt:4,display:"flex",alignItems:"center","&:first-of-type":{mt:0}},children:n}),mn=()=>e.jsxs(d,{spacing:2,children:[e.jsx(w,{width:"30%",height:40}),e.jsx(v,{children:e.jsx(r,{sx:{p:2},children:e.jsxs(d,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(w,{variant:"circular",width:56,height:56}),e.jsxs(r,{flex:1,children:[e.jsx(w,{width:"60%",height:28}),e.jsx(w,{width:"40%",height:20,sx:{mt:.5}})]})]})})}),e.jsx(w,{width:"30%",height:40}),e.jsx(v,{children:e.jsx(r,{sx:{p:2},children:e.jsx(w,{height:80})})}),e.jsx(w,{width:"30%",height:40}),e.jsx(v,{children:e.jsx(r,{sx:{p:2},children:e.jsx(w,{height:100})})})]}),Wn=()=>{var xe,he,pe;const{customerId:n}=Is(),a=ee(),p=ks(),[c,l]=Es(),[C,o]=j.useState(null),u=(xe=p.state)==null?void 0:xe.returnSearch;bs.useEffect(()=>{if(c.get("imported")==="true"){o("Contato importado com sucesso!");const x=new URLSearchParams(c);x.delete("imported"),l(x,{replace:!0})}},[c,l]);const[y,h]=j.useState(null),[m,g]=j.useState(null),[_,I]=j.useState(null),[S,f]=j.useState(!1),[k,W]=j.useState(!1),[q,F]=j.useState(!1),[Q,K]=j.useState(!1),{data:s,isLoading:ne}=Pe(n||""),{data:L}=Ts({path:s==null?void 0:s.profile_url,bucketName:"customer-images",enabled:!!(s!=null&&s.profile_url)&&!s.profile_url.startsWith("blob:")}),{data:te}=As(n),{data:P=[],isLoading:Me}=Fs(Number(n)),{data:re=!1}=Qs(m==null?void 0:m.id),{data:E}=Be(),{storeUrl:$e}=Re(),{data:T=[],isLoading:Ne}=Ds(Number(n)),{data:Ue}=Ws(),{data:qe=[]}=Ls(),Fe=Ps(),ae=qe.filter(t=>t.ativo),ie=async t=>{n&&(await Fe.mutateAsync({customer_ids:[Number(n)],tabela_preco_id:t}),K(!1))},{mutateAsync:Qe,isPending:Ke}=Ks(),{mutateAsync:He,isPending:Ve}=ln(),{mutateAsync:Ye,isPending:Ze}=dn(),oe=(s==null?void 0:s.deletado_em)!==null&&(s==null?void 0:s.deletado_em)!==void 0,Ge=()=>{a(-1)},Je=t=>{h(t.currentTarget)},H=()=>{h(null)},Xe=()=>{a(`/customers/${n}/edit`,{state:{returnSearch:u}}),H()},es=()=>{f(!0),H()},ss=async()=>
8{if(n)try{await He(Number(n)),f(!1),a(-1)}catch(t){console.error("Error deleting customer:",t)}},le=()=>{f(!1)},ns=async()=>{if(n)try{await Ye(Number(n))}catch(t){console.error("Error restoring customer:",t)}},ts=()=>{if(!(s!=null&&s.telefone)||!(E!=null&&E.slug_loja))return;const t=`Olá! Conheça nossa loja online: 9${$e}`;window.open(`https://wa.me/${s.telefone}?text=${encodeURIComponent(t)}`,"_blank")},rs=()=>{s!=null&&s.telefone&&window.open(`https://wa.me/${s.telefone}`,"_blank")},as=()=>{s!=null&&s.email&&window.open(`mailto:${s.email}`,"_blank")},is=()=>{W(!0)},os=()=>{var x;let t=null;(x=s==null?void 0:s.profile_url)!=null&&x.startsWith("blob:")?t=s.profile_url:s!=null&&s.profile_url&&L?t=L:s!=null&&s.profile_url&&(t=s.profile_url),t&&F(!0)},de=()=>{a(`/customers/${n}/addresses/new`)},ls=t=>{a(`/customers/${n}/addresses/${t.id}/edit`,{state:{address:t}})},ds=t=>{g(t)},cs=async()=>{if(m)try{I(null),await Qe(m),g(null)}catch(t){I(t.message||"Erro ao excluir endereço")}},ce=()=>{g(null),I(null)},xs=()=>{console.log("CustomerPage - Creating order for customer:",s);const t={id:s==null?void 0:s.id,nome:s==null?void 0:s.nome,tabela_preco_id:(s==null?void 0:s.tabela_preco_id)??null};console.log("CustomerPage - Navigating with preSelectedCustomer:",t),a("/orders/new",{state:{preSelectedCustomer:t}})};if(!s&&!ne)return e.jsx(r,{sx:{height:"70vh",display:"flex",flexDirection:"column"},children:e.jsx(ke,{title:"Cliente não encontrado",navigateBack:!0})});const hs=ne||Ne||Me;return e.jsxs(r,{sx:{width:"100%",display:"flex",flexDirection:"column",flexGrow:1,overflow:"hidden",position:"relative"},children:[e.jsx(ke,{title:"Detalhes do cliente",navigateBack:Ge,children:e.jsx(fs,{color:"inherit",onClick:Je,children:e.jsx(Js,{})})}),e.jsx(r,{sx:{flex:1,overflowY:"auto",p:{xs:2,md:3},pb:12},children:e.jsxs(r,{sx:{maxWidth:1080,mx:"auto",width:"100%"},children:[C&&e.jsx(R,{severity:"success",onClose:()=>o(null),sx:{mb:2},children:C}),hs?e.jsx(mn,{}):e.jsxs(e.Fragment,{children:[oe&&e.jsx(R,{severity:"warning",sx:{mb:2},action:e.jsx(b,{variant:"text",size:"small",onClick:ns,disabled:Ze,startIcon:e.jsx(Xs,{}),sx:{color:"#DD8B0A",fontWeight:700,"&:hover":{bgcolor:D("#DD8B0A",.1)}},children:"Restaurar"}),children:"Este cliente foi excluÃdo"}),te&&e.jsx(R,{severity:"birthday",icon:e.jsx(J,{sx:{fontSize:20}}),title:`Hoje é o aniversário de ${((he=s==null?void 0:s.nome)==null?void 0:he.split(" ")[0])||"cliente"}!`,sx:{mb:2},action:e.jsx(b,{variant:"contained",size:"small",onClick:is,sx:{bgcolor:"#C465F8","&:hover":{bgcolor:"#B43BE7"}},children:"Parabenizar"})}),e.jsxs(r,{sx:{display:"flex",flexDirection:{xs:"column",md:"row"},alignItems:"flex-start",gap:{xs:4,md:3}},children:[e.jsxs(r,{sx:{width:{xs:"100%",md:360},flexShrink:0},children:[e.jsx(v,{sx:{mb:4},children:e.jsxs(r,{sx:{p:2},children:[e.jsxs(d,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(r,{onClick:os,sx:{cursor:s!=null&&s.profile_url?"pointer":"default"},children:e.jsx(Bs,{alt:(s==null?void 0:s.nome)||"",id:`customer-avatar-${(s==null?void 0:s.customer_user_id)||""}`,imageUrl:s==null?void 0:s.profile_url,sx:{width:56,height:56}})}),e.jsx(r,{sx:{flex:1,minWidth:0},children:e.jsx(i,{variant:"h6",fontWeight:700,sx:{lineHeight:1.25,wordBreak:"break-word"},children:s==null?void 0:s.nome})})]}),e.jsx(U,{sx:{my:2}}),e.jsx(xn,{orders:T}),((s==null?void 0:s.telefone)||(s==null?void 0:s.email)||(s==null?void 0:s.cpf_cnpj)||(s==null?void 0:s.observacoes)||(s==null?void 0:s.dia_aniversario)&&(s==null?void 0:s.mes_aniversario))&&e.jsxs(e.Fragment,{children:[e.jsx(U,{sx:{my:2}}),e.jsxs(d,{spacing:.25,children:[(s==null?void 0:s.telefone)&&e.jsx(A,{icon:e.jsx(se,{sx:{color:"success.main"}}),label:"Telefone",value:Rs(s.telefone),onClick:rs}),(s==null?void 0:s.email)&&e.jsx(A,{icon:e.jsx(en,{}),label:"Email",value:s.email,variant:"secondary",onClick:as}),(s==null?void 0:s.cpf_cnpj)&&e.jsx(A,{icon:e.jsx(sn,{}),label:"CPF/CNPJ",value:s.cpf_cnpj,variant:"secondary"}),(s==null?void 0:s.observacoes)&&e.jsx(A,{icon:e.jsx(nn,{}),label:"Observações",value:s.observacoes,variant:"secondary"}),(s==null?void 0:s.dia_aniversario)&&(s==null?void 0:s.mes_aniversario)&&e.jsx(A,{icon:e.jsx(J,{}),label:"Aniversário",variant:"secondary",value:e.jsxs(e.Fragment,{children:[`${String(s.dia_aniversario).padStart(2,"0")}/${String(s.mes_aniversario).padStart(2,"0")}`,te&&e.jsx(r,{component:"span",sx:{color:"#B43BE7",fontWeight:700,ml:.5},children:"(hoje!)"})]})})]})]}),e.jsxs(d,{spacing:2,sx:{mt:3},children:[e.jsx(b,{variant:"contained",startIcon:e.jsx(Y,{}),onClick:xs,fullWidth:!0,children:"Lançar pedido"}),e.jsxs(d,{direction:"row",spacing:2,children:[e.jsx(b,{variant:"text",startIcon:e.jsx(tn,{}),onClick:ts,disabled:!(E!=null&&E.slug_loja),fullWidth:!0,sx:{bgcolor:"success.50",color:"success.main","&:hover":{bgcolor:"success.100"},"&:disabled":{bgcolor:"grey.100",color:"grey.400"}},children:"Compartilhar loja"}
9),(s==null?void 0:s.customer_user_id)&&e.jsx(b,{variant:"text",startIcon:e.jsx(zs,{}),onClick:()=>a(`/chats/${s.customer_user_id}`),fullWidth:!0,sx:{bgcolor:"primary.50",color:"primary.main","&:hover":{bgcolor:"primary.100"}},children:"Chat vendas"})]})]})]})}),s&&ae.length>0&&Os(Ue)&&e.jsxs(e.Fragment,{children:[e.jsxs(O,{children:[e.jsx(Ms,{style:{marginRight:8}}),"Tabela de preço"]}),e.jsx(v,{sx:{cursor:"pointer"},onClick:()=>K(!0),children:e.jsxs(r,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(r,{children:[e.jsx(i,{variant:"subtitle1",fontWeight:600,children:((pe=s.tabela_preco)==null?void 0:pe.nome)||"Padrão"}),e.jsx(i,{variant:"body2",color:"text.secondary",children:"Toque para alterar"})]}),e.jsx(X,{sx:{color:"text.secondary",fontSize:20}})]})})]}),s&&e.jsxs(e.Fragment,{children:[e.jsxs(O,{children:[e.jsx($s,{sx:{mr:1}}),"Contas a receber"]}),e.jsx(un,{customerId:Number(n),customerName:s.nome,customerPhone:s.telefone})]})]}),e.jsxs(r,{sx:{flex:1,minWidth:0,width:"100%",display:"flex",flexDirection:"column",gap:4},children:[e.jsxs(r,{sx:{order:{md:2}},children:[e.jsxs(O,{children:[e.jsx(Te,{sx:{mr:1}}),"Endereços"]}),P.length>0?e.jsxs(d,{spacing:2,children:[P.slice(0,2).map(t=>e.jsx(Hs,{address:t,onEdit:ls,onDelete:ds,canDelete:!0},t.id)),e.jsx(v,{sx:{cursor:"pointer"},onClick:de,children:e.jsx(r,{sx:{p:2},children:e.jsxs(d,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(Y,{color:"primary"}),e.jsxs(r,{sx:{flex:1},children:[e.jsx(i,{variant:"subtitle1",fontWeight:600,children:"Adicionar endereço"}),e.jsx(i,{variant:"body2",color:"text.secondary",children:"Cadastrar novo endereço"})]}),e.jsx(z,{color:"action"})]})})}),P.length>2&&e.jsx(v,{sx:{cursor:"pointer"},onClick:()=>a(`/customers/${n}/addresses`),children:e.jsx(r,{sx:{p:2},children:e.jsxs(d,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(Te,{color:"primary"}),e.jsxs(r,{sx:{flex:1},children:[e.jsx(i,{variant:"subtitle1",fontWeight:500,children:"Ver todos os endereços"}),e.jsxs(i,{variant:"body2",color:"text.secondary",children:[P.length," endereços cadastrados"]})]}),e.jsx(z,{color:"action"})]})})})]}):e.jsx(v,{sx:{cursor:"pointer"},onClick:de,children:e.jsx(r,{sx:{p:2},children:e.jsxs(d,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(Y,{color:"primary"}),e.jsxs(r,{sx:{flex:1},children:[e.jsx(i,{variant:"subtitle1",fontWeight:600,children:"Adicionar endereço"}),e.jsx(i,{variant:"body2",color:"text.secondary",children:"Este cliente ainda não possui endereços cadastrados"})]}),e.jsx(z,{color:"action"})]})})})]}),e.jsxs(r,{sx:{order:{md:1}},children:[e.jsxs(O,{children:[e.jsx(Ee,{style:{marginRight:8}}),"Pedidos"]}),T.length>0?e.jsxs(d,{spacing:2,children:[T.slice(0,3).map(t=>{var me,ge,fe,je,ye;const x=t.itens_pedido||[],ue=((ge=(me=x[0])==null?void 0:me.produto)==null?void 0:ge.nome)||((je=(fe=x[0])==null?void 0:fe.produto_variacao)==null?void 0:je.nome)||"Item",ps=x.length?x.length>1?`${ue} +${x.length-1}`:ue:void 0;return e.jsx(Ns,{orderNumber:t.numero_pedido||t.pedido_id,userName:t.cliente.nome,itemsSummary:ps,timestamp:t.data_pedido,value:t.subtotal+(((ye=t.frete_pedido)==null?void 0:ye.valor_frete)||0)+(t.taxa_de_venda||0)-(t.valor_desconto||0),orderStatus:t.status_pedido,paymentCondition:t.condicao_pagamento,parcelas:t.parcelas,onClick:()=>a(`/orders/${t.pedido_id}?navigateBack=true`),showRelativeDate:!0,showUserName:!1},t.pedido_id)}),T.length>3&&e.jsx(v,{sx:{cursor:"pointer"},onClick:()=>a(`/orders?customerId=${n}`),children:e.jsx(r,{sx:{p:2},children:e.jsxs(d,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(r,{component:Ee,sx:{color:"primary.main",fontSize:24}}),e.jsxs(r,{sx:{flex:1},children:[e.jsx(i,{variant:"subtitle1",fontWeight:500,children:"Ver todos os pedidos"}),e.jsxs(i,{variant:"body2",color:"text.secondary",children:[T.length," pedidos total"]})]}),e.jsx(z,{color:"action"})]})})})]}):e.jsx(v,{children:e.jsx(r,{sx:{p:2,textAlign:"center"},children:e.jsx(i,{color:"text.secondary",children:"Este cliente ainda não fez nenhum pedido"})})})]})]})]})]})]})}),e.jsxs(js,{anchorEl:y,open:!!y,onClose:H,children:[e.jsxs(ve,{onClick:Xe,children:[e.jsx(Ce,{children:e.jsx(X,{fontSize:"small"})}),e.jsx(B,{children:"Editar"})]}),oe?null:e.jsxs(ve,{onClick:es,children:[e.jsx(Ce,{children:e.jsx(rn,{fontSize:"small"})}),e.jsx(B,{children:"Excluir cliente"})]})]}),e.jsxs(M,{open:!!m,onClose:ce,children:[e.jsx($,{children:"Excluir endereço"}),e.jsxs(N,{children:[_&&e.jsx(R,{severity:"error",sx:{mb:2},children:_}),re?e.jsx(V,{children:"Este endereço não pode ser excluÃdo pois está sendo utilizado em um ou mais pedidos."}):e.jsx(V,{children:"Tem certeza que deseja excluir este endereço? Esta ação não pode ser desfeita."})]}),e.jsxs(G,{children:[e.jsx(b,{onClick:ce,children:"Cancelar"}),e.jsx(b,{onClick:cs,color:"error",disabled:re||Ke,children:"Excluir"})]})]}),e.jsxs(M,{open:S,onClose:le,children:[e.jsx($,{children:"Excluir cliente"}),e.jsx(N,{children:e.jsx(V,{children:"Tem certeza que deseja excluir este cliente?"})}),e.jsxs(G,{children:[e.jsx(b,{onClick:le,children:"Cancelar"}),e.jsx(b,{onClick:ss,color:"error",disabled:Ve,children:"Excluir"})]})]}),n&&e.jsx(pn,{open:k,onClose:()=>W(!1),customerId:n}),e.jsxs(M,{open:Q,onClose:()=>K(!1),fullWidth:!0,maxWidth:"sm",PaperProps:{sx:{borderRadius:2}},children:[e.jsxs($,{children:[e.jsx(i,{variant:"h6",fontWeight:600,children:"Tabela de preço"}),e.jsx(i,{variant:"body2",color:"text.secondary",children:"Selecione a tabela de preço deste cliente"})]}),e.jsx(N,{children:e.jsxs(ys,{sx:{mx:-2},children:[e.jsxs(we,{onClick:()=>ie(null),selected:!(s!=null&&s.tabela_preco_id),children:[e.jsx(B,{primary:"Padrão",primaryTypographyProps:{fontWeight:s!=null&&s.tabela_preco_id?400:600}}),!(s!=null&&s.tabela_preco_id)&&e.jsx(Ae,{color:"primary"})]}),ae.map(t=>{const x=(s==null?void 0:s.tabela_preco_id)===t.id;return e.jsxs(we,{onClick:()=>ie(t.id),selected:x,children:[e.jsx(B,{primary:t.nome,primaryTypographyProps:{fontWeight:x?600:400}
9,secondary:t.pedido_minimo?`Min. ${t.pedido_minimo.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}`:void 0}),x&&e.jsx(Ae,{color:"primary"})]},t.id)})]})})]}),(()=>{var x;let t=null;return(x=s==null?void 0:s.profile_url)!=null&&x.startsWith("blob:")?t=s.profile_url:s!=null&&s.profile_url&&L?t=L:s!=null&&s.profile_url&&(t=s.profile_url),t?e.jsx(Us,{open:q,close:()=>F(!1),slides:[{src:t}],noScroll:{disabled:!0},carousel:{finite:!0},controller:{closeOnBackdropClick:!0,closeOnPullDown:!0,closeOnPullUp:!0},styles:{toolbar:{paddingTop:"var(--safe-area-inset-top, 0px)",paddingBottom:"var(--safe-area-inset-bottom, 0px)",boxShadow:"none"},container:{paddingTop:"calc(var(--safe-area-inset-top, 0px) + 32px)",paddingBottom:"calc(var(--safe-area-inset-bottom, 0px) + 32px)",boxShadow:"none"},navigationPrev:{width:"60px",height:"60px",fontSize:"24px",boxShadow:"none"},navigationNext:{width:"60px",height:"60px",fontSize:"24px",boxShadow:"none"},slide:{boxShadow:"none"}},plugins:[qs]}):null})()]})};export{Wn 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.