PageSourceSearch

https://app.threedaydigital.com/assets/RealtorDocuments-Dp94nbke.js

js threedaydigital.com collected 2026-10-02 14:59:56 UTC 33,207 bytes, 1 lines download raw bytes

1import{cJ as Fe,cB as _e,cM as Te,c4 as m,cN as Ne,bo as E,bN as e,aF as Re,ab as Ee,B,au as te,a7 as H,at as I,E as $e,cU as V,ad as ae,l as G,h as be,g as le,aZ as Pe,bi as je,$ as ne,N as ie,L as q,f as U,ct as Oe,x as Ae,P as Le,co as Me}from"./index-MaNUTrZd.js";import{F as Ue,U as X,a as Be,b as Ye,d as se,t as Ve,e as qe,m as He,f as ye,T as Ke,c as ze,i as Ge,S as Je}from"./forms--Kecbqcp.js";import{u as We}from"./DealDrawer-BnnWrVmA.js";import{i as Ze,e as ve}from"./files-2G4Gp_1y.js";import"./catalog-CLoK1JSZ.js";async function C(s,l,c={}){if(!s)return{ok:!1,error:"not_signed_in"};try{const n=await fetch("/.netlify/functions/realtor-docs",{method:"POST",headers:Pe(),body:JSON.stringify({...c,action:l,user_id:s})});return await n.json().catch(()=>({ok:!1,error:`http_${n.status}`}))}catch{return{ok:!1,error:"network"}}}const J={draft:{label:"Draft",tone:"grey"},ready:{label:"Approved — ready to send",tone:"blue"},out_for_signature:{label:"Out for signature",tone:"amber"},completed:{label:"Signed",tone:"green"},declined:{label:"Declined",tone:"rose"},voided:{label:"Voided",tone:"grey"}},Qe="application/pdf,image/png,image/jpeg,image/webp";async function ke(s,l){if(l.size>32*1024*1024)throw new Error(`${l.name} is over 32 MB`);if(l.size>10*1024*1024)try{await fetch("/.netlify/functions/doc-uploads-config",{method:"POST"})}catch{}const c=We(s,l.name),n=await Me.storage.from("doc-uploads").upload(c,l,{contentType:l.type||"application/octet-stream",upsert:!1});if(n.error)throw new Error(n.error.message);return{path:c,name:l.name,mime:l.type||"application/octet-stream"}}function Xe(s,l){const c=atob(l),n=new Uint8Array(c.length);for(let r=0;r<c.length;r++)n[r]=c.charCodeAt(r);const y=URL.createObjectURL(new Blob([n],{type:"application/pdf"})),g=document.createElement("a");g.href=y,g.download=s,document.body.appendChild(g),g.click(),g.remove(),setTimeout(()=>URL.revokeObjectURL(y),3e4)}function ut(){const s=Fe(),{user:l}=_e(),[c,n]=Te(),[y,g]=m.useState(null),[r,j]=m.useState([]),[h,b]=m.useState(""),[i,k]=m.useState(c.get("tab")==="library"?"library":"documents"),[D,f]=m.useState(null),[w,T]=m.useState(!1),[O,P]=Ne(),M=c.get("open")||"",$=m.useCallback(async()=>{const[a,u]=await Promise.all([C(s,"docs_list"),C(s,"forms_list")]);a!=null&&a.ok?(g(a.documents||[]),b("")):(b((a==null?void 0:a.error)||"failed"),g([])),u!=null&&u.ok&&j(u.forms||[])},[s]);m.useEffect(()=>{document.title="Documents · ThreeDay Realtor"},[]),m.useEffect(()=>{s&&$()},[s,$]),m.useEffect(()=>{y&&y.length===0&&!c.get("tab")&&!c.get("open")&&!c.get("new")&&k("library")},[y]),m.useEffect(()=>{const a=c.get("new");!a||!s||(async()=>{const u=await C(s,"doc_create",{template_key:a,deal_id:c.get("deal")||void 0,client_id:c.get("client")||void 0}),x=new URLSearchParams(c);x.delete("new"),x.delete("deal"),x.delete("client"),u!=null&&u.ok?x.set("open",u.document.id):P(E(u),"bad"),n(x,{replace:!0}),$()})()},[c.get("new"),s]);const p=a=>{const u=new URLSearchParams(c);a?u.set("open",a):u.delete("open"),n(u,{replace:!0})};async function F(a){if(l!=null&&l.id){if(!/pdf$/i.test(a.type)&&!/\.pdf$/i.test(a.name)){P("Upload the form as a PDF.","bad");return}T(!0);try{const u=await ke(l.id,a),x=await C(s,"form_upload",{path:u.path,name:a.name.replace(/\.pdf$/i,"")});x!=null&&x.ok?(P(`Added to your forms — ${x.fields} fillable field${x.fields===1?"":"s"}`),$()):P(E(x),"bad")}catch(u){P(`Could not upload: ${(u==null?void 0:u.message)||"error"}`,"bad")}T(!1)}}if(h==="realtor_tables_missing")return e.jsx("div",{className:"max-w-7xl mx-auto pt-1 pb-16",children:e.jsx(Re,{})});const _={draft:(y||[]).filter(a=>a.status==="draft"||a.status==="ready").length,out:(y||[]).filter(a=>a.status==="out_for_signature").length,done:(y||[]).filter(a=>a.status==="completed").length};return e.jsxs("div",{className:"max-w-7xl mx-auto pt-1 pb-16","data-rt-documents-page":!0,children:[O,e.jsx(Ee,{icon:"📝",title:"Documents",blurb:"Forms that fill themselves from what your clients send — an ID, a pre-approval letter, a pay stub — approved by you, signed online, filed on the deal.",actions:e.jsx("button",{type:"button",className:B,onClick:()=>k("library"),"data-rt-docs-new":!0,children:"+ New document"})}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-5",children:[e.jsx(te,{value:_.draft,label:"📝 Drafts"}),e.jsx(te,{value:_.out,label:"✍️ Out for signature",tone:_.out?"warn":void 0}),e.jsx(te,{value:_.done,label:"✅ Signed"})]}),e.jsx("div",{className:"flex gap-1 border-b border-slate-200 mb-4",role:"tablist",children:[["documents",`Your documents${y?` · ${y.length}`:""}`],["library","Forms library"]].map(([a,u])=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===a,onClick:()=>k(a),"data-rt-docs-tab":a,className:"px-3.5 py-2.5 text-[15px] font-bold border-b-2 -mb-px "+(i===a?"border-teal-600 text-teal-700":"border-transparent text-slate-500 hover:text-slate-800"),children:u},a))}),h&&h!=="realtor_tables_missing"&&e.jsx("div",{className:"mb-4",children:e.jsx(H,{tone:"rose",children:E({error:h})})}),i==="documents"&&(y===null?e.jsx(I,{}):y.length===0?e.jsx($e,{icon:"📝",title:"No documents yet",body:"Start from the library — then drop in what the client sent you and the form fills itself.",action:e.jsx("button",{type:"button",className:B,onClick:()=>k("library"),children:"Open the forms library"})}):e.jsx("div",{className:G+" divide-y divide-slate-100","data-rt-doc-list":!0,children:y.map(a=>{var L;const u=Ue[a.template_key],x=J[a.status]||J.draft;return e.jsxs("button",{type:"button",onClick:()=>p(a.id),className:"w-full text-left flex items-center gap-3 px-4 py-3 hover:bg-slate-50","data-rt-doc-row":a.status,children:[e.jsx("span",{className:"text-[22px]",children:a.template_key===X?"📎":(u==null?void 0:u.icon)||"📝"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-bold text-[15px] text-slate-900 truncate",children:a.title}),e.jsx("div",{className:"text-[13.5px] text-slate-500 truncate",children:a.status==="out_for_signature"?((L=a.waiting_on)!=null&&L.length?`Waiting on ${a.waiting_on.join(", ")}`:"Out for signature")+` · ${a.signers_signed} of ${a.signers_total} signed`:a.status==="completed"?`Signed ${V(a.completed_at,{time:!1})}`:`Updated ${V(a.updated_at)}`})]}),e.jsx(ae,{tone:x.tone,children:x.label})]},a.id)})})),i==="library"&&e.jsxs("div",{className:"space-y-6","data-rt-library":!0,children:[e.jsxs(H,{tone:"blue",children:["📚 ",e.jsx("b",{children:"ThreeDay templates are plain-language documents"})," — not your board’s licensed forms. For a form your market prescribes (an Agreement of Purchase and Sale, a standard lease), ",e.jsx("b",{children:"upload your fillable PDF once"})," under “Your own forms” and ThreeDay fills and sends it the same way."]}
1),Be.filter(a=>a.id!=="mine").map(a=>{const u=Ye.filter(x=>x.category===a.id);return u.length?e.jsxs("div",{"data-rt-shelf":a.id,children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-2",children:[e.jsxs("span",{className:"font-extrabold text-[17px] text-slate-900",children:[a.icon," ",a.label]}),e.jsx("span",{className:"text-[14px] text-slate-500",children:a.blurb})]}),e.jsx("div",{className:"grid sm:grid-cols-2 xl:grid-cols-3 gap-3",children:u.map(x=>e.jsxs("div",{className:G+" p-4 flex flex-col","data-rt-template-card":x.key,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"text-[26px] leading-none",children:x.icon}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-extrabold text-[15.5px] text-slate-900",children:x.name}),e.jsx("div",{className:"text-[13.5px] text-slate-600 mt-0.5",children:x.blurb})]})]}),e.jsxs("div",{className:"text-[13px] text-slate-500 mt-2",children:[se(x).length," fields · signed by ",x.signers.filter(L=>!L.optional).map(L=>L.label).join(" + ")||"you",se(x).some(L=>L.extract)?" · ✨ fills from uploads":""]}),e.jsx("div",{className:"mt-auto pt-3",children:e.jsx("button",{type:"button",className:be,onClick:()=>f({template_key:x.key,name:x.name}),"data-rt-start-template":x.key,children:"Start"})})]},x.key))})]},a.id):null}),e.jsxs("div",{"data-rt-shelf":"mine",children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-2 flex-wrap",children:[e.jsx("span",{className:"font-extrabold text-[17px] text-slate-900",children:"📎 Your own forms"}),e.jsx("span",{className:"text-[14px] text-slate-500",children:"Any fillable PDF — your board’s licensed forms included. Upload it once; reuse it for every client."}),e.jsxs("label",{className:le+" ml-auto cursor-pointer",children:[w?"Reading the form…":"⬆ Upload a fillable PDF",e.jsx("input",{type:"file",accept:"application/pdf",className:"hidden",disabled:w,onChange:a=>{var x;const u=(x=a.target.files)==null?void 0:x[0];a.target.value="",u&&F(u)},"data-rt-form-upload":!0})]})]}),r.length===0?e.jsx("div",{className:"text-[14px] text-slate-500",children:"None yet. The PDF needs fillable fields (most board forms do — ask for the “fillable” version)."}):e.jsx("div",{className:"grid sm:grid-cols-2 xl:grid-cols-3 gap-3",children:r.map(a=>e.jsxs("div",{className:G+" p-4 flex flex-col","data-rt-own-form":a.id,children:[e.jsxs("div",{className:"font-extrabold text-[15.5px] text-slate-900",children:["📎 ",a.name]}),e.jsxs("div",{className:"text-[13px] text-slate-500 mt-1",children:[(a.pdf_fields||[]).filter(u=>u.type!=="signature").length," fillable fields · added ",V(a.created_at,{time:!1})]}),e.jsxs("div",{className:"mt-auto pt-3 flex gap-2",children:[e.jsx("button",{type:"button",className:be,onClick:()=>f({form_id:a.id,name:a.name}),children:"Start"}),e.jsx("button",{type:"button",className:"text-[13.5px] font-bold text-slate-500 hover:underline",onClick:async()=>{if(!window.confirm(`Remove “${a.name}” from your forms? Documents already made from it keep their copy.`))return;const u=await C(s,"form_delete",{id:a.id});u!=null&&u.ok?$():P(E(u),"bad")},children:"Remove"})]})]},a.id))})]})]}),D&&e.jsx(Ie,{ownerId:s,what:D,onClose:()=>f(null),onMade:a=>{f(null),k("documents"),$(),p(a)}}),M&&e.jsx(et,{ownerId:s,id:M,onClose:()=>p(null),onChanged:$,onOpen:a=>p(a)},M)]})}function Ie({ownerId:s,what:l,onClose:c,onMade:n}){const[y,g]=m.useState(null),[r,j]=m.useState(""),[h,b]=m.useState(!1),[i,k]=m.useState("");m.useEffect(()=>{je(s,"deals_list").then(f=>g(f!=null&&f.ok?f.deals||[]:[]))},[s]);async function D(){b(!0),k("");const f=await C(s,"doc_create",{...l.form_id?{form_id:l.form_id}:{template_key:l.template_key},deal_id:r||void 0});b(!1),f!=null&&f.ok?n(f.document.id):k(E(f))}return e.jsxs(ne,{open:!0,onClose:c,title:`Start: ${l.name}`,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:U,onClick:c,children:"Cancel"}),e.jsx("button",{type:"button",className:B,onClick:D,disabled:h,"data-rt-start-go":!0,children:h?"Starting…":"Start it"})]}),children:[e.jsx("label",{className:ie,children:"For which deal? (fills the address, price, dates and client for you)"}),y===null?e.jsx(I,{}):e.jsxs("select",{className:q,value:r,onChange:f=>j(f.target.value),"data-rt-start-deal":!0,children:[e.jsx("option",{value:"",children:"No deal — I’ll fill it in"}),y.map(f=>{var w;return e.jsxs("option",{value:f.id,children:[f.title||((w=f.property)==null?void 0:w.address)||"Untitled deal",f.household?` — ${f.household}`:""]},f.id)})]}),e.jsx("div",{className:"text-[13.5px] text-slate-500 mt-3",children:"Next, drop in what the client sent you (a photo of their ID, a pre-approval letter, a pay stub) and the blanks fill themselves for you to check."}),i&&e.jsx("div",{className:"mt-3",children:e.jsx(H,{tone:"rose",children:i})})]})}function et({ownerId:s,id:l,onClose:c,onChanged:n,onOpen:y}){var me,pe,xe;const{user:g}=_e(),[r,j]=m.useState(null),[h,b]=m.useState(""),[i,k]=m.useState({}),[D,f]=m.useState("idle"),[w,T]=m.useState(null),[O,P]=m.useState(null),[M,$]=m.useState(!1),[p,F]=m.useState(!1),[_,a]=m.useState({name:"",brokerage:"",email:""}),[u,x]=m.useState([]),[L,S]=Ne(),W=m.useRef({}),K=m.useRef(null),d=r==null?void 0:r.document,R=m.useMemo(()=>d?Ve(d):null,[d==null?void 0:d.template_key,d==null?void 0:d.pdf_fields,d==null?void 0:d.title]),Z=d&&(d.status==="draft"||d.status==="ready"),z=m.useCallback(async()=>{var o;const t=await C(s,"doc_get",{id:l});t!=null&&t.ok?(j(t),k(t.document.fields||{}),b(""),((o=t.extraction)==null?void 0:o.status)==="done"&&P(t.extraction),t.extraction&&["queued","running"].includes(t.extraction.status)&&T({id:t.extraction.id,files:(t.extraction.files||[]).length||1})):b(E(t))},[s,l]);m.useEffect(()=>{z()},[z]),m.useEffect(()=>{je(s,"settings_get").then(t=>{var o,v,N;if(t!=null&&t.ok){const A=((o=t.realtor_hq)==null?void 0:o.profile)||{};a({name:A.full_name||((v=t.profile)==null?void 0:v.full_name)||"",brokerage:A.brokerage||"",email:((N=t.profile)==null?void 0:N.email)||""})}})},[s]);const Y=m.useCallback(async()=>{const t=W.current;if(W.current={},!Object.keys(t).length)return;f("saving");const o=await C(s,"doc_save",{id:l,patch:t});o!=null&&o.ok?(f("saved"),j(v=>v&&{...v,document:{...v.document,...o.document,fields:{...o.document.fields,...W.current}}}),o.unapproved&&S("Changed after approval — approve it again before sending."),n()):(f("failed"),S(E(o),"bad"))},[s,l,n,S]);m.useEffect(()=>()=>{K.current&&clearTimeout(K.current),Y()},[]);function re(t,o){k(v=>({...v,[t]:o})),x(v=>v.filter(N=>N!==t)),W.current[t]=o,f("idle"),K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{Y()},700)}async function we(t){if(!(g!=null&&g.id))return;const o=Array.from(t).slice(0,8);if(o.length)try{await Y(),S(`Uploading ${o.length} file${o.length===1?"":"s"}…`);const v=[];for(const A of o)v.push(await ke(g.id,A));const N=await C(s,"doc_fill_start",{id:l,files:v});if(!(N!=null&&N.ok)){S(E(N),"bad");return}T({id:N.extraction_id,files:v.length})}catch(v){S(`Could not upload: ${(v==null?void 0:v.message)||"error"}`,"bad")}}m.useEffect(()=>{if(!w)return;let t=!0;const o=Date.now(),v=async()=>{var fe,ge;if(!t)return;const A=await C(s,"doc_fill_get",{extraction_id:w.id});if(!t)return;const he=(fe=A==null?void 0:A.extraction)==null?void 0:fe.status;if(he==="done"){T(null),P(A.extraction);const ee=(((ge=A.extraction.result)==null?void 0:ge.filled)||[]).length;S(ee?`Filled ${ee} field${ee===1?"":"s"} from their files — check the ✨ ones`:"Read the files — nothing new to fill"),await z(),n();return}
1if(he==="error"){T(null),S(`Could not read the files: ${String(A.extraction.error||"").replace(/^[a-z_]+: /,"")}`,"bad");return}if(Date.now()-o>4*6e4){T(null),S("Reading is taking long — it will fill in when it finishes. Reopen the document in a minute.","bad");return}setTimeout(v,2500)},N=setTimeout(v,2e3);return()=>{t=!1,clearTimeout(N)}},[w==null?void 0:w.id]);async function Q(t,o={},v){await Y();const N=await C(s,t,{id:l,...o});return N!=null&&N.ok?(v&&S(v),await z(),n(),N):((N==null?void 0:N.error)==="missing_fields"&&Array.isArray(N.missing)&&x(N.missing),S(E(N),"bad"),null)}async function Se(){await Y();const t=await C(s,d.status==="completed"&&d.signed_pdf_path?"doc_pdf_url":"doc_pdf_draft",{id:l,which:"signed"});t!=null&&t.ok&&t.url?window.open(t.url,"_blank","noopener"):t!=null&&t.ok&&t.base64?Xe(t.filename||"document.pdf",t.base64):S(E(t),"bad")}const Ce=m.useMemo(()=>R?qe(R,i,{agentName:_.name,brokerage:_.brokerage,today:Oe()}):"",[R,i,_.name,_.brokerage]),oe=R?He(R,i):[],de=d&&J[d.status]||J.draft,De=(d==null?void 0:d.ai_fields)||{},ce=((me=O==null?void 0:O.result)==null?void 0:me.conflicts)||[],ue=((pe=O==null?void 0:O.result)==null?void 0:pe.warnings)||[];return e.jsxs(Ae,{open:!0,onClose:c,wide:!0,title:d?d.title:"Document",footer:d?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap","data-rt-doc-actions":d.status,children:[d.status==="draft"&&e.jsx("button",{type:"button",className:B,onClick:()=>Q("doc_approve",{},"Approved — ready to send for signature"),"data-rt-doc-approve":!0,children:"✓ Approve"}),d.status==="ready"&&e.jsx("button",{type:"button",className:B,onClick:()=>$(!0),"data-rt-doc-send":!0,children:"✍️ Send for signature"}),d.status==="out_for_signature"&&e.jsx("button",{type:"button",className:U,onClick:()=>Q("doc_remind",{},"Reminder sent"),"data-rt-doc-remind":!0,children:"🔔 Remind now"}),e.jsx("button",{type:"button",className:U,onClick:Se,"data-rt-doc-pdf":!0,children:d.status==="completed"?"⬇ Signed PDF":"⬇ PDF"}),((r==null?void 0:r.client)||d.household_id)&&e.jsx("button",{type:"button",className:U,onClick:async()=>{var o;await Y();const t=await C(s,"doc_save_copy",{id:l});t!=null&&t.ok?S(`Saved to ${(o=r==null?void 0:r.client)!=null&&o.name?r.client.name+"'s":"their"} files — Offers & agreements`):S(E(t),"bad")},title:"A PDF of this document as it stands, into the client's Files","data-rt-doc-save-copy":!0,children:"💾 Save to their files"}),["completed","declined","voided"].includes(d.status)&&e.jsx("button",{type:"button",className:U,onClick:async()=>{const t=await C(s,"doc_duplicate",{id:l});t!=null&&t.ok?(n(),y(t.document.id)):S(E(t),"bad")},"data-rt-doc-duplicate":!0,children:"⧉ Duplicate"}),["draft","ready","out_for_signature"].includes(d.status)&&e.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[14px] font-bold text-rose-700 hover:bg-rose-50",onClick:async()=>{const t=window.prompt(d.status==="out_for_signature"?"Void it? The signing links stop working. Reason (optional):":"Void this document? Reason (optional):","");t!==null&&await Q("doc_void",{reason:t},"Voided")},"data-rt-doc-void":!0,children:"Void"}),e.jsx("span",{className:"ml-auto text-[13px] text-slate-400","data-rt-doc-saved":D,children:D==="saving"?"Saving…":D==="saved"?"Saved ✓":D==="failed"?"Not saved":""})]}):void 0,children:[L,h&&e.jsx(H,{tone:"rose",children:h}),!r&&!h&&e.jsx(I,{}),d&&R&&e.jsxs("div",{"data-rt-doc":d.id,"data-status":d.status,children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-3",children:[e.jsx(ae,{tone:de.tone,children:de.label}),e.jsx("span",{className:"text-[14px] text-slate-500",children:d.template_key===X?"📎 Your own form":`${R.icon} ${R.name}`}),r.deal&&e.jsxs(Le,{to:`/realtoragent/deals?open=${r.deal.id}&tab=documents`,className:"text-[14px] font-bold text-teal-700 hover:underline",children:["🗂️ ",r.deal.title]}),r.client&&e.jsxs("span",{className:"text-[14px] text-slate-500",children:["· 👤 ",r.client.name]})]}),Z&&e.jsx(tt,{reading:w,onFiles:we,onPrefill:()=>Q("doc_prefill",{},"Filled from the deal"),hasDeal:!!d.deal_id||!!d.client_id,onFromFiles:r!=null&&r.client?()=>F(!0):void 0,clientName:((xe=r==null?void 0:r.client)==null?void 0:xe.name)||""}),p&&(r==null?void 0:r.client)&&e.jsx(st,{ownerId:s,clientId:r.client.id,clientName:r.client.name,onClose:()=>F(!1),onRead:async t=>{F(!1),await Y();const o=await C(s,"doc_fill_start",{id:l,files:t});if(!(o!=null&&o.ok)){S(E(o),"bad");return}T({id:o.extraction_id,files:t.length})}}),(ce.length>0||ue.length>0)&&Z&&e.jsxs("div",{className:"mb-4 space-y-2","data-rt-doc-conflicts":!0,children:[ce.map(t=>{const o=se(R).find(v=>v.key===t.key);return!o||String(i[t.key]??"")===String(t.value??"")?null:e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 px-3 py-2 text-[14px] text-amber-900 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{children:[e.jsxs("b",{children:[o.label,":"]}
1)," ",t.file?`${t.file} says`:"their files say"," “",ye(o,t.value),"” — you have “",ye(o,i[t.key]),"”."]}),e.jsx("button",{type:"button",className:"ml-auto font-bold underline",onClick:()=>re(t.key,t.value),children:"Use theirs"})]},t.key)}),ue.map((t,o)=>e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 px-3 py-2 text-[14px] text-amber-900",children:["⚠ ",t]},o))]}),d.status==="out_for_signature"||d.status==="completed"||d.status==="declined"?e.jsx(lt,{signers:r.signers||[],doc:d}):null,e.jsxs("div",{className:"grid lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)] gap-5 items-start",children:[e.jsxs("div",{className:"space-y-4","data-rt-doc-fields":!0,children:[R.notice&&e.jsx(H,{tone:"amber",children:R.notice}),R.sections.map(t=>e.jsxs("div",{className:G+" p-4",children:[e.jsx("div",{className:"font-extrabold text-[15.5px] text-slate-900 mb-3",children:t.title}),e.jsx("div",{className:"grid sm:grid-cols-2 gap-3",children:t.fields.map(o=>e.jsx(at,{f:o,value:i[o.key],ai:De[o.key],disabled:!Z,missing:u.includes(o.key),onChange:v=>re(o.key,v)},o.key))})]},t.title)),Z&&oe.length>0&&e.jsxs("div",{className:"text-[14px] text-slate-500","data-rt-doc-missing":!0,children:["Still needed before you can approve: ",oe.map(t=>t.label).join(", "),"."]})]}),e.jsxs("div",{className:"lg:sticky lg:top-2","data-rt-doc-preview":!0,children:[e.jsxs("div",{className:"text-[13px] font-bold uppercase tracking-wider text-slate-500 mb-1.5",children:["The document",d.template_key===X?" — your PDF is filled with these values when it goes out":""]}),e.jsx("div",{className:"bg-white rounded-xl ring-1 ring-slate-200 shadow-sm px-6 py-5 max-h-[70vh] overflow-y-auto text-slate-900 text-[14.5px] leading-relaxed [&_h1]:font-display [&_h1]:font-extrabold [&_h1]:text-[20px] [&_h1]:mb-3 [&_h2]:font-bold [&_h2]:text-[15.5px] [&_h2]:text-blue-700 [&_h2]:mt-4 [&_h2]:mb-1 [&_p]:mb-2.5 [&_ul]:list-disc [&_ul]:pl-5 [&_ul]:mb-2.5 [&_table]:w-full [&_table]:mb-3 [&_th]:text-left [&_th]:align-top [&_th]:font-semibold [&_th]:text-slate-500 [&_th]:pr-3 [&_th]:py-1 [&_th]:w-2/5 [&_td]:py-1 [&_td]:align-top [&_.td-doc-blank]:text-amber-600 [&_.td-doc-notice]:text-[12.5px] [&_.td-doc-notice]:text-slate-500 [&_.td-doc-notice]:italic [&_.td-doc-notice]:mt-4",dangerouslySetInnerHTML:{__html:Ce}}),d.template_key!==X&&e.jsx("div",{className:"text-[12.5px] text-slate-400 mt-2",children:Ke})]})]})]}),M&&d&&R&&e.jsx(nt,{ownerId:s,doc:d,tpl:R,client:r.client,agent:_,onClose:()=>$(!1),onSent:t=>{$(!1),S(t||"Sent — each signer has their own link"),z(),n()}})]})}function tt({reading:s,onFiles:l,onPrefill:c,hasDeal:n,onFromFiles:y,clientName:g}){const[r,j]=m.useState(!1);return e.jsx("div",{className:"mb-4 rounded-2xl border-2 border-dashed p-4 transition "+(r?"border-teal-500 bg-teal-50":"border-slate-300 bg-white"),onDragOver:h=>{h.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:h=>{var b;h.preventDefault(),j(!1),(b=h.dataTransfer.files)!=null&&b.length&&l(h.dataTransfer.files)},"data-rt-fill-bar":!0,children:s?e.jsxs("div",{className:"flex items-center gap-3","data-rt-reading":!0,children:[e.jsx("span",{className:"inline-block w-5 h-5 rounded-full border-2 border-slate-300 border-t-teal-600 animate-spin"}),e.jsxs("div",{className:"text-[15px] text-slate-700",children:[e.jsxs("b",{children:["Reading ",s.files," file",s.files===1?"":"s","…"]})," usually 20–60 seconds. The blanks fill in by themselves — keep working meanwhile."]})]}):e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("span",{className:"text-[26px]",children:"✨"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-extrabold text-[15.5px] text-slate-900",children:"Fill from their files"}),e.jsx("div",{className:"text-[14px] text-slate-500",children:"Drop in what the client sent — a photo of their ID, a pre-approval letter, a pay stub, a tax bill. PDFs or photos, up to 8. Blanks are filled; nothing you typed is overwritten. Files stay private to your account."})]}),e.jsxs("label",{className:B+" cursor-pointer",children:["⬆ Choose files",e.jsx("input",{type:"file",multiple:!0,accept:Qe,className:"hidden",onChange:h=>{const b=h.target.files;b!=null&&b.length&&l(Array.from(b)),h.target.value=""}
1,"data-rt-fill-input":!0})]}),y&&e.jsxs("button",{type:"button",className:U,onClick:y,"data-rt-fill-from-files":!0,children:["📂 From ",g?`${g.split(/\s+/)[0]}'s`:"their"," files"]}),n&&e.jsx("button",{type:"button",className:U,onClick:c,"data-rt-prefill":!0,children:"↻ Fill from the deal"})]})})}function st({ownerId:s,clientId:l,clientName:c,onClose:n,onRead:y}){const[g,r]=m.useState(null),[j,h]=m.useState([]);m.useEffect(()=>{C(s,"files_list",{client_id:l}).then(i=>r(i!=null&&i.ok?(i.files||[]).filter(k=>Ze(k.mime)):[]))},[s,l]);const b=(g||[]).filter(i=>j.includes(i.id)).slice(0,8);return e.jsx(ne,{open:!0,onClose:n,title:`📂 ${c||"Their"} files`,footer:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:le,onClick:n,children:"Cancel"}),e.jsxs("button",{type:"button",className:B+" ml-auto",disabled:!b.length,onClick:()=>y(b.map(i=>({path:i.storage_path,name:i.name,mime:i.mime}))),"data-rt-saved-files-read":!0,children:["✨ Read ",b.length||""," into this form"]})]}),children:g===null?e.jsx(I,{}):g.length===0?e.jsxs("div",{className:"text-[14.5px] text-slate-600",children:["No saved PDFs or photos for ",c||"this client"," yet. Add them in Clients → their household → Files, or drop them into the box above."]}):e.jsxs("div",{className:"space-y-1.5","data-rt-saved-files":!0,children:[g.map(i=>{var k,D;return e.jsxs("label",{className:"flex items-center gap-2.5 rounded-xl ring-1 ring-slate-200 px-3 py-2 cursor-pointer hover:bg-slate-50",children:[e.jsx("input",{type:"checkbox",checked:j.includes(i.id),onChange:f=>h(w=>f.target.checked?[...w,i.id]:w.filter(T=>T!==i.id))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14.5px] font-bold text-slate-900",children:i.name}),e.jsxs("span",{className:"text-[12.5px] text-slate-500",children:[(k=ve[i.folder])==null?void 0:k.icon," ",(D=ve[i.folder])==null?void 0:D.label," · ",V(i.created_at)]})]})]},i.id)}),e.jsx("div",{className:"text-[13px] text-slate-500 pt-1",children:"Up to 8. Blanks are filled; nothing you typed is overwritten."})]})})}function at({f:s,value:l,ai:c,disabled:n,missing:y,onChange:g}){const r=s.type==="textarea"||s.label.length>38,j=c&&String(c.value??"")===String(l??"")&&l!==""&&l!=null&&l!==!1,h=q+(y?" !border-rose-400 !ring-rose-200":j?" !border-violet-300 !bg-violet-50/40":"");let b;return s.type==="checkbox"?b=e.jsxs("label",{className:"flex items-center gap-2.5 text-[15px] text-slate-800 py-1.5",children:[e.jsx("input",{type:"checkbox",className:"w-5 h-5",checked:Ge(l),disabled:n,onChange:i=>g(i.target.checked),"data-rt-field":s.key})," ",s.label,s.required?" *":""]}):s.type==="textarea"?b=e.jsx("textarea",{className:h+" min-h-[80px]",value:l??"",disabled:n,onChange:i=>g(i.target.value),placeholder:s.placeholder||"","data-rt-field":s.key}):s.type==="select"?b=e.jsxs("select",{className:h,value:l??"",disabled:n,onChange:i=>g(i.target.value),"data-rt-field":s.key,children:[e.jsx("option",{value:"",children:"—"}),l&&s.options&&!s.options.includes(l)&&e.jsx("option",{value:l,children:l}),(s.options||[]).map(i=>e.jsx("option",{value:i,children:i},i))]}):b=e.jsx("input",{className:h,type:s.type==="date"?"date":s.type==="time"?"time":s.type==="email"?"email":s.type==="phone"?"tel":"text",inputMode:s.type==="money"||s.type==="number"?"decimal":void 0,value:l??"",disabled:n,onChange:i=>g(i.target.value),placeholder:s.placeholder||(s.type==="money"?"$":""),"data-rt-field":s.key}),e.jsxs("div",{className:r?"sm:col-span-2":"","data-rt-field-wrap":s.key,"data-ai":j?"1":"0",children:[s.type!=="checkbox"&&e.jsxs("label",{className:ie,children:[s.label,s.required?" *":"",s.sensitive?" 🔒":""]}),b,j&&e.jsxs("div",{className:"text-[12.5px] mt-1 "+(Number(c.confidence)<.7?"text-amber-700 font-semibold":"text-violet-700"),title:c.evidence?`Read as: “${c.evidence}”`:void 0,"data-rt-ai-note":s.key,children:["✨ ",Number(c.confidence)<.7?"Check this — ":"","read from ",c.file||"their files",c.evidence?` (“${String(c.evidence).slice(0,60)}”)`:""]}),s.sensitive&&!j&&e.jsx("div",{className:"text-[12px] text-slate-400 mt-1",children:"Kept private — never written to your activity log."})]})}function lt({signers:s,doc:l}){var c;return e.jsxs("div",{className:G+" p-4 mb-4","data-rt-signers":!0,
1children:[e.jsxs("div",{className:"font-extrabold text-[15.5px] text-slate-900 mb-2",children:["✍️ Signatures",l.sent_at?e.jsxs("span",{className:"font-semibold text-slate-500 text-[14px]",children:[" · sent ",V(l.sent_at)]}):null]}),e.jsx("div",{className:"divide-y divide-slate-100",children:s.map(n=>e.jsxs("div",{className:"flex items-center gap-3 py-2","data-rt-signer":n.status,children:[e.jsx("span",{className:"text-[18px]",children:n.status==="signed"?"✅":n.status==="declined"?"⛔":n.status==="viewed"?"👀":"📨"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"font-bold text-[14.5px] text-slate-900",children:[n.name," ",e.jsxs("span",{className:"font-semibold text-slate-500",children:["· ",ze[n.role]||n.role]})]}),e.jsxs("div",{className:"text-[13px] text-slate-500 truncate",children:[n.email,n.reminders?` · reminded ${n.reminders}×`:""]})]}),e.jsx(ae,{tone:n.status==="signed"?"green":n.status==="declined"?"rose":n.status==="viewed"?"blue":"amber",children:n.status==="signed"?`Signed ${V(n.signed_at)}`:n.status==="declined"?"Declined":n.status==="viewed"?"Opened it":"Sent"})]},n.id))}),l.status==="declined"&&((c=s.find(n=>n.status==="declined"))==null?void 0:c.decline_reason)&&e.jsxs("div",{className:"mt-2 text-[14px] text-rose-800",children:["Their reason: “",s.find(n=>n.status==="declined").decline_reason,"”"]}),l.status==="out_for_signature"&&e.jsxs("div",{className:"text-[13px] text-slate-500 mt-2",children:["Reminders go by themselves every ",l.remind_every_days||2," day",l.remind_every_days===1?"":"s"," (9am–6pm, three at most). You are told the moment everyone has signed."]}),l.status==="completed"&&e.jsxs("div",{className:"text-[13px] text-slate-500 mt-2",children:["Signed by everyone ",V(l.completed_at),". The signed PDF, with its signature certificate, is filed on this document",l.deal_id?" and the deal":"","."]})]})}function nt({ownerId:s,doc:l,tpl:c,client:n,agent:y,onClose:g,onSent:r}){const j=c.signers.filter(p=>!p.optional).map(p=>({role:p.role,name:p.role==="agent"||p.role==="referring_agent"?y.name:["buyer","seller","tenant","client","landlord"].includes(p.role)&&n?n.name:"",email:p.role==="agent"||p.role==="referring_agent"?y.email:["buyer","seller","tenant","client","landlord"].includes(p.role)&&n&&n.email||""})),[h,b]=m.useState(j.length?j:[{role:"client",name:(n==null?void 0:n.name)||"",email:(n==null?void 0:n.email)||""}]),[i,k]=m.useState(""),[D,f]=m.useState(2),[w,T]=m.useState(!1),[O,P]=m.useState(""),M=(p,F)=>b(_=>_.map((a,u)=>u===p?{...a,...F}:a));async function $(){T(!0),P("");const p=await C(s,"doc_send",{id:l.id,signers:h,message:i,remind_every_days:D});T(!1),p!=null&&p.ok?r(p.warning):P(E(p))}return e.jsxs(ne,{open:!0,onClose:g,max:"max-w-2xl",title:`Send “${l.title}” for signature`,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:U,onClick:g,children:"Cancel"}),e.jsx("button",{type:"button",className:B,onClick:$,disabled:w,"data-rt-send-go":!0,children:w?"Sending…":`✍️ Send to ${h.length} signer${h.length===1?"":"s"}`})]}),children:[e.jsxs("div",{className:"space-y-2.5","data-rt-send-signers":!0,
1children:[h.map((p,F)=>e.jsxs("div",{className:"grid grid-cols-[8.5rem_minmax(0,1fr)_minmax(0,1.2fr)_auto] gap-2 items-center",children:[e.jsx("select",{className:q+" !py-2 !px-2",value:p.role,onChange:_=>M(F,{role:_.target.value}),children:Je.map(_=>e.jsx("option",{value:_.key,children:_.label},_.key))}),e.jsx("input",{className:q+" !py-2",value:p.name,onChange:_=>M(F,{name:_.target.value}),placeholder:"Full name","data-rt-signer-name":F}),e.jsx("input",{className:q+" !py-2",type:"email",value:p.email,onChange:_=>M(F,{email:_.target.value}),placeholder:"[email protected]","data-rt-signer-email":F}),e.jsx("button",{type:"button",className:"px-2 text-slate-400 hover:text-rose-600 text-[18px]",onClick:()=>b(_=>_.filter((a,u)=>u!==F)),disabled:h.length<=1,"aria-label":"Remove signer",children:"✕"})]},F)),e.jsx("button",{type:"button",className:le,onClick:()=>b(p=>[...p,{role:"client",name:"",email:""}]),disabled:h.length>=8,children:"+ Add a signer"})]}),e.jsx("label",{className:ie+" mt-4",children:"A note with it (optional)"}),e.jsx("textarea",{className:q+" min-h-[70px]",value:i,onChange:p=>k(p.target.value),placeholder:"e.g. Here are the offer instructions we went over — have a look and sign when you’re ready."}),e.jsxs("div",{className:"flex items-center gap-2 mt-3 text-[14px] text-slate-600",children:["Remind anyone who hasn’t signed every",e.jsx("select",{className:"rounded-lg border border-slate-300 px-2 py-1",value:D,onChange:p=>f(Number(p.target.value)),children:[1,2,3,5,7].map(p=>e.jsxs("option",{value:p,children:[p," day",p===1?"":"s"]},p))}),"(up to 3 times, 9am–6pm)"]}),e.jsx("div",{className:"text-[13.5px] text-slate-500 mt-3",children:"Each person gets their own private link by email. They read the document, agree to sign electronically, and sign with their finger or by typing their name. You get the signed PDF with a signature certificate (who, when, from where)."}),O&&e.jsx("div",{className:"mt-3",children:e.jsx(H,{tone:"rose",children:O})})]})}export{ut as default,C as docs};

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.