PageSourceSearch

https://maxxvidaplanner.lovable.app/assets/app.clients._clientId-QX6Dh20B.js

js maxxvidaplanner.lovable.app collected 2026-10-03 03:34:05 UTC 30,234 bytes, 1 lines download raw bytes

1import{bW as z,ek as A,aG as X,dQ as Z,cU as g,cw as e,Z as B,l as P,br as U,df as j,B as G,bm as J,bo as ee,bp as N,bn as y,a2 as ae,a7 as I,Y as te,W as m,z as se,bq as M,dY as H,dX as K,dP as F,dc as w,ai as Y,dO as le,dH as ne}from"./index-TjtOvFgc.js";import{L as $}from"./label-ca8vhkqM.js";import{f as ie,g as re,h as de,x as ce,k as oe}from"./admin-queries-BmL4vX0v.js";import{A as me}from"./AccessTab-DJ4rVo98.js";import{D as pe}from"./DocumentsPanel-pv6crUVI.js";import{n as O,C as ue,a as he}from"./buyer-client-link-H_gS1eQE.js";import{S as Q}from"./switch-BsNdofS6.js";import{L as xe}from"./LanguageChip-BRf94xTa.js";import{C as fe}from"./chevron-left-DUj7fZEe.js";import{S as je}from"./save-C7vgez-e.js";import{F as W}from"./file-text-BX3Z4Zd8.js";import{U as ge}from"./users-Dr54RT6i.js";import"./use-server-fn-D0umlOOA.js";import"./avatar-CsxmAoA7.js";import"./table-e-dmoUql.js";import"./dropdown-menu-Bdvyy151.js";import"./chevron-right-byR9IKqu.js";import"./circle-BAm3i5CV.js";import"./dropbox-upload.functions-LX4CevpX.js";import"./integration-settings.functions-DsWw-TGP.js";import"./dropbox.functions-DgromGlw.js";import"./alert-CSl8E7C5.js";import"./search-DwPadhS8.js";import"./circle-alert-Bd5cyG1i.js";import"./refresh-ccw-np28rkKW.js";import"./inbox-D41VpU6_.js";import"./circle-x-Bnjd_o_T.js";import"./PhysicalArchiveCell-utJfRK6M.js";import"./physical-archive-sqGT9Rp2.js";import"./archive-tUmjvx91.js";import"./link-2-DaepNVly.js";import"./download-jtY6AHRM.js";import"./share-2-DaCjSkMl.js";const be=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],V=z("file-pen-line",be);const Ne=[["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]],ye=z("phone",Ne),ve=["spouse","partner","parent","child","sibling","representative","other"],we={name:"",preferredName:"",company:"",contactName:"",cpfCnpj:"",rgPassport:"",dateOfBirth:"",nationality:"",maritalStatus:"",email:"",secondaryEmail:"",phone:"",mobilePhone:"",whatsapp:"",website:"",street:"",number:"",complement:"",neighborhood:"",city:"",state:"",country:"",postalCode:"",address:"",notes:"",preferences:"",languagesSpokenText:"",preferredLanguage:"pt",allowEmailNotifications:!1,allowWhatsappNotifications:!1};function q(t,c="BRL"){return t==null?"—":t.toLocaleString("pt-BR",{style:"currency",currency:c})}function ca(){const{t}=A(),{clientId:c}=X.useParams(),l=ie(c),p=re(c),u=de(c),f=ce(),h=oe(),i=Z(),n=!!i.data?.isStaff,v=!!i.data?.isAdmin,[s,r]=g.useState(we),[k,S]=g.useState([]);g.useEffect(()=>{if(!l.data)return;const a=l.data;r({name:a.name,preferredName:a.preferredName??"",company:a.company??"",contactName:a.contactName??"",cpfCnpj:a.cpfCnpj??"",rgPassport:a.rgPassport??"",dateOfBirth:a.dateOfBirth??"",nationality:a.nationality??"",maritalStatus:a.maritalStatus??"",email:a.email??"",secondaryEmail:a.secondaryEmail??"",phone:a.phone??"",mobilePhone:a.mobilePhone??"",whatsapp:a.whatsapp??"",website:a.website??"",street:a.street??"",number:a.number??"",complement:a.complement??"",neighborhood:a.neighborhood??"",city:a.city??"",state:a.state??"",country:a.country??"",postalCode:a.postalCode??"",address:a.address??"",notes:a.notes??"",preferences:a.preferences??"",languagesSpokenText:(a.languagesSpoken??[]).join(", "),preferredLanguage:a.preferredLanguage,allowEmailNotifications:a.allowEmailNotifications,allowWhatsappNotifications:a.allowWhatsappNotifications}),S(a.roles)},[l.data]);const d=g.useMemo(()=>{const a=p.data??[];return{owned:a.filter(x=>x.relation==="owned").length,purchased:a.filter(x=>x.relation==="purchased").length,sold:a.filter(x=>x.relation==="sold").length}},[p.data]);if(l.isLoading)return e.jsx("div",{className:"p-6 text-muted-foreground",children:t("common.loading")});if(!l.data)return e.jsx("div",{className:"p-6",children:t("clients.detail.notFound")});const C=async()=>{try{await f.mutateAsync({id:c,name:s.name.trim()||l.data.name,preferredName:s.preferredName||null,company:s.company||null,contactName:s.contactName||null,cpfCnpj:s.cpfCnpj||null,rgPassport:s.rgPassport||null,dateOfBirth:s.dateOfBirth||null,
1nationality:s.nationality||null,maritalStatus:s.maritalStatus||null,email:s.email||null,secondaryEmail:s.secondaryEmail||null,phone:s.phone||null,mobilePhone:s.mobilePhone||null,whatsapp:s.whatsapp||null,website:s.website||null,street:s.street||null,number:s.number||null,complement:s.complement||null,neighborhood:s.neighborhood||null,city:s.city||null,state:s.state||null,country:s.country||null,postalCode:s.postalCode||null,address:s.address||null,notes:s.notes||null,preferences:s.preferences||null,languagesSpoken:s.languagesSpokenText?s.languagesSpokenText.split(",").map(a=>a.trim()).filter(Boolean):[],preferredLanguage:s.preferredLanguage,allowEmailNotifications:s.allowEmailNotifications,allowWhatsappNotifications:s.allowWhatsappNotifications,roles:k}),j.success(t("clients.detail.saved"))}catch(a){j.error(a.message)}},L=a=>{S(x=>x.includes(a)?x.filter(E=>E!==a):[...x,a])},b=O(s.whatsapp),_=Ce(s),T=O(s.cpfCnpj).length===14;return e.jsxs("div",{className:"p-6 space-y-4 overflow-auto max-w-5xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(B,{to:"/app/clients",className:"text-sm text-muted-foreground hover:underline flex items-center gap-1",children:[e.jsx(fe,{className:"h-4 w-4"})," ",t("clients.detail.backToClients")]}),e.jsxs("div",{className:"flex gap-2",children:[n&&e.jsxs(P,{size:"sm",onClick:C,disabled:f.isPending,children:[e.jsx(je,{className:"h-4 w-4 mr-1"})," ",t("clients.detail.save")]}),v&&e.jsxs(P,{variant:"ghost",size:"sm",onClick:async()=>{if(confirm(t("clients.detail.confirmDelete")))try{await h.mutateAsync(c),j.success(t("clients.detail.deleted")),history.back()}catch(a){j.error(a.message)}},children:[e.jsx(U,{className:"h-4 w-4 mr-1"})," ",t("clients.detail.delete")]})]})]}),e.jsxs("div",{className:"flex items-baseline gap-3 flex-wrap",children:[e.jsx("h2",{className:"text-2xl font-semibold",children:s.name||t("clients.detail.clientFallback")}),e.jsx(xe,{value:s.preferredLanguage}),e.jsx("div",{className:"flex gap-1 flex-wrap",children:k.map(a=>e.jsx(G,{variant:"secondary",children:t(`clients.detail.roleLabel.${a}`)},a))})]}),e.jsxs(J,{defaultValue:"overview",className:"w-full",children:[e.jsxs(ee,{className:"flex flex-wrap h-auto",children:[e.jsx(N,{value:"overview",children:t("clients.detail.tabs.overview")}),e.jsx(N,{value:"properties",children:t("clients.detail.tabs.properties")}),e.jsx(N,{value:"transactions",children:t("clients.detail.tabs.transactions")}),e.jsx(N,{value:"documents",children:t("clients.detail.tabs.documents")}),e.jsx(N,{value:"contact",children:t("clients.detail.tabs.contact")}),!T&&e.jsx(N,{value:"related",children:t("clients.detail.tabs.related")}),e.jsx(N,{value:"notes",children:t("clients.detail.tabs.notes")}),e.jsx(N,{value:"history",children:t("clients.detail.tabs.history")}),i.data?.isStaff&&e.jsx(N,{value:"access",children:t("access.tabTitle",{defaultValue:"Access"})})]}),e.jsxs(y,{value:"overview",className:"space-y-4",children:[e.jsxs("div",{className:"grid sm:grid-cols-3 gap-3",children:[e.jsx(D,{label:t("clients.detail.statCards.owned"),value:d.owned}),e.jsx(D,{label:t("clients.detail.statCards.purchased"),value:d.purchased}),e.jsx(D,{label:t("clients.detail.statCards.sold"),value:d.sold})]}),e.jsx("section",{className:"rounded-md border bg-card p-4 space-y-2 text-sm",children:T?e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.company")}),e.jsxs("p",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("clients.detail.companyName"),":"]})," ",s.name||"—"]}),e.jsxs("p",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("clients.detail.cnpj"),":"]})," ",s.cpfCnpj||"—"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.contactSummary")}),e.jsxs("p",{children:[e.jsx(ae,{className:"inline h-3 w-3 mr-1"})," ",s.email||"—"]}),e.jsxs("p",{children:[e.jsx(ye,{className:"inline h-3 w-3 mr-1"})," ",s.mobilePhone||s.phone||s.whatsapp||"—"]}),b&&e.jsxs("a",{href:`https://wa.me/${b}`,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-emerald-700 hover:underline",children:[e.jsx(I,{className:"h-3 w-3"})," ",s.whatsapp]}),e.jsxs("p",{className:"text-muted-foreground",children:[t("clients.detail.address"),": ",_||"—"]}),e.jsxs("p",{className:"text-muted-foreground",children:[t("clients.detail.cpf"),": ",s.cpfCnpj||"—"]}
1),e.jsxs("p",{className:"text-muted-foreground",children:[t("clients.detail.nextBirthday"),": ",Se(s.dateOfBirth,t)]})]})})]}),e.jsxs(y,{value:"properties",className:"space-y-4",children:[e.jsx(ke,{clientId:c}),e.jsx(R,{title:t("clients.detail.propertyGroups.owned"),items:(p.data??[]).filter(a=>a.relation==="owned")}),e.jsx(R,{title:t("clients.detail.propertyGroups.purchased"),items:(p.data??[]).filter(a=>a.relation==="purchased")}),e.jsx(R,{title:t("clients.detail.propertyGroups.sold"),items:(p.data??[]).filter(a=>a.relation==="sold")})]}),e.jsx(y,{value:"transactions",children:e.jsx("section",{className:"rounded-md border bg-card",children:(u.data??[]).length===0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:t("clients.detail.transactionsEmpty")}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-2",children:t("clients.detail.transactionCols.date")}),e.jsx("th",{className:"p-2",children:t("clients.detail.transactionCols.kind")}),e.jsx("th",{className:"p-2",children:t("clients.detail.transactionCols.role")}),e.jsx("th",{className:"p-2",children:t("clients.detail.transactionCols.property")}),e.jsx("th",{className:"p-2 text-right",children:t("clients.detail.transactionCols.value")})]})}),e.jsx("tbody",{children:(u.data??[]).map(a=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-2",children:a.transactionDate??"—"}),e.jsx("td",{className:"p-2",children:a.kind}),e.jsx("td",{className:"p-2",children:a.role}),e.jsx("td",{className:"p-2",children:a.propertyId?e.jsx(B,{to:"/app/properties/$propertyId",params:{propertyId:a.propertyId},className:"hover:underline",children:a.propertyTitle??a.propertyId}):"—"}),e.jsx("td",{className:"p-2 text-right",children:q(a.value,a.currency)})]},a.id))})]})})}),e.jsx(y,{value:"documents",children:e.jsx(pe,{clientId:c})}),e.jsxs(y,{value:"contact",className:"space-y-4",children:[e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.rolesSection")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ue.map(a=>{const x=k.includes(a);return e.jsx("button",{type:"button",disabled:!n,onClick:()=>L(a),className:`text-xs px-2 py-1 rounded-full border transition-colors ${x?"bg-primary text-primary-foreground border-primary":"bg-background hover:bg-accent"}`,children:t(`clients.detail.roleLabel.${a}`,he[a])},a)})})]}),e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.notificationsSection")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("clients.detail.notificationsHelp")}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsx(o,{label:t("clients.detail.preferredLanguage"),children:e.jsx("div",{className:"flex gap-2",children:["pt","en","nl"].map(a=>{const x=s.preferredLanguage===a;return e.jsx("button",{type:"button",disabled:!n,onClick:()=>r({...s,preferredLanguage:a}),className:`text-xs px-3 py-1 rounded-full border transition-colors ${x?"bg-primary text-primary-foreground border-primary":"bg-background hover:bg-accent"}`,children:te[a].native},a)})})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx($,{className:"text-sm",children:t("clients.detail.allowEmailNotifications")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.email?t("clients.detail.emailWillSend",{email:s.email}):t("clients.detail.noEmailOnFile")})]}),e.jsx(Q,{disabled:!n||!s.email,checked:s.allowEmailNotifications,onCheckedChange:a=>r({...s,allowEmailNotifications:!!a})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 opacity-60",children:[e.jsxs("div",{children:[e.jsx($,{className:"text-sm",children:t("clients.detail.allowWhatsappNotifications")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("clients.detail.whatsappReserved")})]}),e.jsx(Q,{disabled:!0,checked:s.allowWhatsappNotifications,onCheckedChange:a=>r({...s,allowWhatsappNotifications:!!a})})]})]})]})]}),T?e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.company")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("clients.detail.companyHelp")}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsx(o,{label:t("clients.detail.fields.companyNameLegal"),children:e.jsx(m,{disabled:!n,value:s.name,onChange:a=>r({...s,name:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.cnpj"),children:e.jsx(m,{disabled:!n,value:s.cpfCnpj,onChange:a=>r({...s,cpfCnpj:a.target.value})})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.personalSection")}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsx(o,{label:t("clients.detail.fields.fullName"),children:e.jsx(m,{disabled:!n,value:s.name,onChange:a=>r({...s,name:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.preferredName"),children:e.jsx(m,{disabled:!n,value:s.preferredName,onChange:a=>r({...s,preferredName:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.company"),children:e.jsx(m,{disabled:!n,value:s.company,onChange:a=>r({...s,company:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.primaryContact"),children:e.jsx(m,{disabled:!n,value:s.contactName,onChange:a=>r({...s,contactName:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.cpfCnpj"),children:e.jsx(m,{disabled:!n,value:s.cpfCnpj,onChange:a=>r({...s,cpfCnpj:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.rgPassport"),children:e.jsx(m,{disabled:!n,value:s.rgPassport,onChange:a=>r({...s,rgPassport:a.target.value})})}
1),e.jsx(o,{label:t("clients.detail.fields.dateOfBirth"),children:e.jsx(m,{type:"date",disabled:!n,value:s.dateOfBirth,onChange:a=>r({...s,dateOfBirth:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.nationality"),children:e.jsx(m,{disabled:!n,value:s.nationality,onChange:a=>r({...s,nationality:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.maritalStatus"),children:e.jsx(m,{disabled:!n,value:s.maritalStatus,onChange:a=>r({...s,maritalStatus:a.target.value})})})]})]}),e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.contactSection")}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsx(o,{label:t("clients.detail.fields.email"),children:e.jsx(m,{type:"email",disabled:!n,value:s.email,onChange:a=>r({...s,email:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.secondaryEmail"),children:e.jsx(m,{type:"email",disabled:!n,value:s.secondaryEmail,onChange:a=>r({...s,secondaryEmail:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.mobilePhone"),children:e.jsx(m,{disabled:!n,value:s.mobilePhone,onChange:a=>{const x=a.target.value;r(E=>({...E,mobilePhone:x,whatsapp:E.whatsapp.trim()===""?x:E.whatsapp}))}})}),e.jsx(o,{label:t("clients.detail.fields.whatsapp"),children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{disabled:!n,value:s.whatsapp,onChange:a=>r({...s,whatsapp:a.target.value})}),b&&e.jsxs(e.Fragment,{children:[e.jsx("a",{href:`https://wa.me/${b}`,target:"_blank",rel:"noreferrer",title:t("clients.detail.openWhatsapp"),className:"inline-flex items-center px-3 rounded-md border bg-emerald-600 text-white hover:bg-emerald-700",children:e.jsx(I,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",title:t("clients.detail.copyNumber"),onClick:()=>{navigator.clipboard.writeText(s.whatsapp),j.success(t("clients.detail.copied"))},className:"inline-flex items-center px-3 rounded-md border hover:bg-accent",children:e.jsx(se,{className:"h-4 w-4"})})]})]})})]})]}),e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.addressSection")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("clients.detail.currentAddress",{address:_||"—"})}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsx(o,{label:t("clients.detail.fields.street"),children:e.jsx(m,{disabled:!n,value:s.street,onChange:a=>r({...s,street:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.number"),children:e.jsx(m,{disabled:!n,value:s.number,onChange:a=>r({...s,number:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.complement"),children:e.jsx(m,{disabled:!n,value:s.complement,onChange:a=>r({...s,complement:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.neighborhood"),children:e.jsx(m,{disabled:!n,value:s.neighborhood,onChange:a=>r({...s,neighborhood:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.city"),children:e.jsx(m,{disabled:!n,value:s.city,onChange:a=>r({...s,city:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.state"),children:e.jsx(m,{disabled:!n,value:s.state,onChange:a=>r({...s,state:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.country"),children:e.jsx(m,{disabled:!n,value:s.country,onChange:a=>r({...s,country:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.postalCode"),children:e.jsx(m,{disabled:!n,value:s.postalCode,onChange:a=>r({...s,postalCode:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.freeFormAddress"),className:"sm:col-span-2",children:e.jsx(m,{disabled:!n,value:s.address,onChange:a=>r({...s,address:a.target.value})})})]})]})]})]}),!T&&e.jsx(y,{value:"related",className:"space-y-4",children:e.jsx(Ee,{clientId:c,canEdit:n})}),e.jsx(y,{value:"notes",className:"space-y-4",children:e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsx(o,{label:t("clients.detail.fields.internalNotes"),children:e.jsx(M,{disabled:!n,rows:4,value:s.notes,onChange:a=>r({...s,notes:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.preferences"),children:e.jsx(M,{disabled:!n,rows:3,value:s.preferences,onChange:a=>r({...s,preferences:a.target.value})})}),e.jsx(o,{label:t("clients.detail.fields.languagesSpoken"),children:e.jsx(m,{disabled:!n,value:s.languagesSpokenText,onChange:a=>r({...s,languagesSpokenText:a.target.value})})})]})}),e.jsx(y,{value:"history",children:e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-2 text-sm",children:[e.jsx("h3",{className:"font-medium",children:t("clients.detail.historyTitle")}),(u.data??[]).length===0&&e.jsx("p",{className:"text-muted-foreground",children:t("clients.detail.noHistory")}),e.jsx("ul",{className:"space-y-2",children:(u.data??[]).map(a=>e.jsxs("li",{className:"flex items-center justify-between border-b pb-1",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("span",{children:[a.transactionDate??e.jsx("span",{className:"italic text-muted-foreground",children:t("clients.detail.noDocumentDate")})," ","— ",a.kind," (",a.role,")"]}),a.notes&&e.jsx("span",{className:"text-xs text-muted-foreground",children:a.notes}),!a.transactionDate&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t("clients.detail.uploadedDate",{date:a.createdAt.slice(0,10)})})]}),e.jsxs("span",{className:"text-muted-foreground",children:[a.propertyTitle??"—"," · ",q(a.value,a.currency)]})]},a.id))}),e.jsx("p",{className:"text-xs text-muted-foreground pt-2",children:t("clients.detail.auditComingNext")})]})}),i.data?.isStaff&&e.jsx(y,{value:"access",className:"space-y-4",children:e.jsx(me,{resourceType:"client",resourceId:c})})]})]})}function D({label:t,value:c}){return e.jsxs("div",{className:"rounded-md border bg-card p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t}),e.jsx("p",{className:"text-2xl font-semibold",children:c})]})}function o({label:t,children:c,className:l}){return e.jsxs("div",{className:l,children:[e.jsx($,{className:"mb-1 block",children:t}),c]})}
1function Ce(t){return[[t.street,t.number,t.complement].filter(Boolean).join(", "),t.neighborhood,[t.city,t.state].filter(Boolean).join(" - "),t.postalCode,t.country].filter(Boolean).join(" · ")||t.address||""}function ke({clientId:t}){const c=H(),[l,p]=g.useState(""),[u,f]=g.useState("buyer"),[h,i]=g.useState(null),n=K({queryKey:["client-link-property-search",l],enabled:l.trim().length>=2,queryFn:async()=>{const{data:s,error:r}=await w.from("properties").select("id,title").ilike("title",`%${l.trim()}%`).limit(15);if(r)throw r;return s??[]}}),v=F({mutationFn:async()=>{if(!h)throw new Error("Selecione um imóvel");const s=u==="buyer"?"purchase":u==="owner"?"ownership_transfer":"sale",{error:r}=await w.from("client_transactions").insert({client_id:t,property_id:h.id,role:u,kind:s});if(r)throw r},onSuccess:()=>{j.success("Imóvel vinculado ao cliente"),i(null),p(""),c.invalidateQueries({queryKey:["client-properties",t]}),c.invalidateQueries({queryKey:["client-transactions",t]})},onError:s=>j.error(s?.message??"Não foi possível vincular")});return e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-2",children:[e.jsx("h3",{className:"font-medium",children:"Vincular imóvel"}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx(m,{className:"sm:flex-1",placeholder:"Buscar imóvel por título…",value:h?h.title:l,onChange:s=>{i(null),p(s.target.value)}}),e.jsxs("select",{className:"h-9 rounded-md border bg-background px-2 text-sm",value:u,onChange:s=>f(s.target.value),children:[e.jsx("option",{value:"buyer",children:"Comprador"}),e.jsx("option",{value:"owner",children:"Proprietário"}),e.jsx("option",{value:"seller",children:"Vendedor"})]}),e.jsxs(P,{size:"sm",disabled:!h||v.isPending,onClick:()=>v.mutate(),children:[e.jsx(Y,{className:"h-4 w-4 mr-1"})," Vincular"]})]}),!h&&l.trim().length>=2&&e.jsx("div",{className:"max-h-48 overflow-y-auto rounded border divide-y",children:(n.data??[]).length===0?e.jsx("p",{className:"p-2 text-sm text-muted-foreground",children:"Nenhum imóvel encontrado"}):(n.data??[]).map(s=>e.jsx("button",{type:"button",className:"block w-full px-2 py-1.5 text-left text-sm hover:bg-muted",onClick:()=>i(s),children:s.title},s.id))})]})}function R({title:t,items:c}){const{t:l}=A(),{data:p=[]}=le(),{data:u=[]}=ne(),f=i=>i?p.find(n=>n.id===i)?.name??"—":"—",h=i=>i?u.find(n=>n.id===i)?.name??"—":"—";return!c||c.length===0?e.jsxs("section",{className:"rounded-md border bg-card p-4",children:[e.jsx("h3",{className:"font-medium mb-2",children:t}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l("common.none",{defaultValue:"None."})})]}):e.jsxs("section",{className:"rounded-md border bg-card p-4",children:[e.jsxs("h3",{className:"font-medium mb-2",children:[t," (",c.length,")"]}),e.jsx("ul",{className:"divide-y",children:c.map(i=>e.jsxs("li",{className:"py-1.5 flex items-center gap-3 text-sm whitespace-nowrap",children:[e.jsx(B,{to:"/app/properties/$propertyId",params:{propertyId:i.id},className:"font-medium hover:underline truncate flex-1 min-w-0",title:i.title,children:i.title}),e.jsx("span",{className:"text-muted-foreground truncate w-32",title:f(i.municipalityId),children:f(i.municipalityId)}),e.jsx("span",{className:"text-muted-foreground truncate w-32",title:h(i.districtId),children:h(i.districtId)}),e.jsx("span",{className:"tabular-nums w-32 text-right",children:q(i.saleValue)}),i.matriculaUrl?e.jsx("a",{href:i.matriculaUrl,target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),title:l("clients.detail.propertyRow.matricula"),"aria-label":l("clients.detail.propertyRow.matricula"),className:"text-primary hover:opacity-80 shrink-0",children:e.jsx(W,{className:"h-4 w-4"})}):e.jsx("span",{title:l("clients.detail.propertyRow.noMatricula"),"aria-label":l("clients.detail.propertyRow.noMatricula"),className:"text-muted-foreground/40 shrink-0",children:e.jsx(W,{className:"h-4 w-4"})}),i.salesContractUrl?e.jsx("a",{href:i.salesContractUrl,target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),title:l("clients.detail.propertyRow.salesContract"),"aria-label":l("clients.detail.propertyRow.salesContract"),className:"text-primary hover:opacity-80 shrink-0",children:e.jsx(V,{className:"h-4 w-4"})}):e.jsx("span",{title:l("clients.detail.propertyRow.noSalesContract"),"aria-label":l("clients.detail.propertyRow.noSalesContract"),className:"text-muted-foreground
1/40 shrink-0",children:e.jsx(V,{className:"h-4 w-4"})})]},`${i.relation}-${i.id}`))})]})}function Se(t,c){if(!t)return"—";const l=new Date(t);if(Number.isNaN(l.getTime()))return"—";const p=new Date,u=new Date(p.getFullYear(),l.getMonth(),l.getDate());u<p&&u.setFullYear(p.getFullYear()+1);const f=Math.round((u.getTime()-p.getTime())/(1e3*60*60*24));return c("clients.detail.nextBirthdayIn",{date:u.toLocaleDateString(),count:f})}function _e(t){return K({queryKey:["client-relations",t],queryFn:async()=>{const{data:c,error:l}=await w.from("client_relations").select("id,relationship,related_client_id,note").eq("client_id",t);if(l)throw l;const p=c??[],u=Array.from(new Set(p.map(i=>i.related_client_id))).filter(Boolean);if(u.length===0)return p;const{data:f}=await w.from("clients").select("id,name,cpf_cnpj,email,mobile_phone,whatsapp").in("id",u),h=new Map;return(f??[]).forEach(i=>h.set(i.id,i)),p.map(i=>({...i,related:h.get(i.related_client_id)??null}))}})}function Ee({clientId:t,canEdit:c}){const{t:l}=A(),p=H(),u=_e(t),[f,h]=g.useState(""),[i,n]=g.useState(""),[v,s]=g.useState("spouse"),r=F({mutationFn:async()=>{const d=i.replace(/\D+/g,"");if(!d)throw new Error(l("clients.detail.related.cpfRequired"));const{data:C,error:L}=await w.rpc("upsert_related_client_from_party",{_name:f.trim()||"(sem nome)",_doc:d});if(L)throw L;const b=C;if(!b)throw new Error(l("clients.detail.related.createFailed"));if(b===t)throw new Error(l("clients.detail.related.selfError"));const{error:_}=await w.from("client_relations").insert([{client_id:t,related_client_id:b,relationship:v},{client_id:b,related_client_id:t,relationship:v}]);if(_)throw _},onSuccess:()=>{h(""),n(""),s("spouse"),p.invalidateQueries({queryKey:["client-relations"]}),j.success(l("clients.detail.related.added"))},onError:d=>j.error(d.message)}),k=F({mutationFn:async d=>{const{error:C}=await w.from("client_relations").delete().or(`and(client_id.eq.${t},related_client_id.eq.${d}),and(client_id.eq.${d},related_client_id.eq.${t})`);if(C)throw C},onSuccess:()=>{p.invalidateQueries({queryKey:["client-relations"]}),j.success(l("clients.detail.related.removed"))},onError:d=>j.error(d.message)}),S=u.data??[];return e.jsxs("section",{className:"rounded-md border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:l("clients.detail.related.title")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("clients.detail.related.help")}),S.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:l("clients.detail.related.empty")}):e.jsx("ul",{className:"divide-y",children:S.map(d=>e.jsxs("li",{className:"py-2 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-medium",children:[d.related?e.jsx(B,{to:"/app/clients/$clientId",params:{clientId:d.related.id},className:"hover:underline",children:d.related.name}):e.jsx("span",{className:"text-muted-foreground",children:l("clients.detail.related.unknown")}),e.jsx(G,{variant:"secondary",className:"ml-2 capitalize",children:l(`clients.detail.relationship.${d.relationship}`,{defaultValue:d.relationship})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[d.related?.cpf_cnpj??"—",d.related?.email?` · ${d.related.email}`:"",d.related?.whatsapp||d.related?.mobile_phone?` · ${d.related.whatsapp??d.related.mobile_phone}`:""]}),d.note&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:d.note})]}),c&&e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>k.mutate(d.related_client_id),children:e.jsx(U,{className:"h-4 w-4"})})]},d.id))}),c&&e.jsxs("div",{className:"border-t pt-3 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:l("clients.detail.related.addTitle")}),e.jsxs("div",{className:"grid sm:grid-cols-4 gap-2",children:[e.jsx(m,{placeholder:l("clients.detail.fields.fullName"),value:f,onChange:d=>h(d.target.value)}),e.jsx(m,{placeholder:l("clients.detail.related.cpfPlaceholder"),value:i,onChange:d=>n(d.target.value)}
1),e.jsx("select",{value:v,onChange:d=>s(d.target.value),className:"border rounded-md px-2 py-1 text-sm bg-background",children:ve.map(d=>e.jsx("option",{value:d,children:l(`clients.detail.relationship.${d}`)},d))}),e.jsxs(P,{onClick:()=>r.mutate(),disabled:r.isPending||!i.trim(),children:[e.jsx(Y,{className:"h-4 w-4 mr-1"})," ",l("common.add")]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("clients.detail.related.requirementHelp")})]})]})}export{ca as component};

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.