PageSourceSearch

https://dealassist.replit.app/assets/deal-new-Ciw7Dp_g.js

js dealassist.replit.app collected 2026-10-03 03:49:52 UTC 49,808 bytes, 1 lines download raw bytes

1import{c as _e,r as d,j as e,Q as ze,Y as lt,F as Je,B as P,_ as He,Z as it,$ as dt,i as ot,b as ke,k as ct,C as q,d as re,e as le,a as H,I as f,M as T,h as Ne,q as We}from"./index-ymGASxfw.js";import{B as Ie}from"./badge-3CC9CLqT.js";import{T as mt}from"./textarea-CrXdz7g7.js";import{P as Be,a as be}from"./party-autocomplete-Ba1rRY7A.js";import{A as ut,s as xt}from"./party-duplicate-dialog-BpLXWAEQ.js";import{S as W,a as B,b as K,c as Y,d as b}from"./select-Uo3n-gk9.js";import{T as ht,a as pt,b as Ke,c as Le,d as jt,e as Me}from"./table-_V7mEsov.js";import{S as Te}from"./skeleton-q6F7ptfe.js";import{C as ft}from"./chevron-left-BjK6UCdQ.js";import{C as gt}from"./chevron-right-CdIo0__w.js";import{D as G,M as vt}from"./deal-date-input-BTBOGLdN.js";import{u as yt,F as Nt,a as m,b as u,c,d as x,e as h,t as bt,f as Ct,s as St}from"./form-DzaIW43p.js";import{A as wt}from"./arrow-left-B-j62kpW.js";import{T as Tt}from"./triangle-alert-Cvmo0pHU.js";import{P as Ce}from"./dialog-CD0WaQq7.js";import{T as Se}from"./trash-2-DPZLFrCn.js";import{S as Dt}from"./save-BOpK0Fpu.js";import{D as Pt}from"./dollar-sign-B3-8x30S.js";import"./index-pfSpv1nM.js";import"./index-DEMw4C8u.js";import"./format-D9kDN5iQ.js";import"./eye-Bgm0Lnfu.js";import"./arrow-right-kCfMbPPa.js";import"./chevron-up-Xz_mYCrv.js";import"./check-BQ84uMGu.js";const At=_e("TextCursor",[["path",{d:"M17 22h-1a4 4 0 0 1-4-4V6a4 4 0 0 1 4-4h1",key:"uvaxm9"}],["path",{d:"M7 22h1a4 4 0 0 0 4-4v-1",key:"11xy8d"}],["path",{d:"M7 2h1a4 4 0 0 1 4 4v1",key:"1uw06m"}]]);const Et=_e("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);const Rt=_e("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);function we(g){if(typeof g!="string")return null;const v=g.trim(),j=/^(\d{4})-(\d{1,2})-(\d{1,2})(?:T.*)?$/.exec(v);if(j)return $e(+j[1],+j[2],+j[3]);const N=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(v);if(N)return $e(+N[3],+N[1],+N[2]);const M=/^(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+(\d{4})$/i.exec(v);if(M){const ie=["january","february","march","april","may","june","july","august","september","october","november","december"].indexOf(M[1].toLowerCase())+1;return $e(+M[3],ie,+M[2])}return null}function $e(g,v,j){const N=new Date(Date.UTC(g,v-1,j));return g<1900||N.getUTCFullYear()!==g||N.getUTCMonth()+1!==v||N.getUTCDate()!==j?null:`${g}-${String(v).padStart(2,"0")}-${String(j).padStart(2,"0")}`}function pe(g,v=!1){const j=String(g??"").trim().replace(/[$,%\s,]/g,"");if(!j||!/^-?\d+(?:\.\d+)?$/.test(j))return null;const N=Number(j);return!Number.isFinite(N)||v&&(!Number.isSafeInteger(N)||N<0)?null:j}const kt=lt("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Fe=d.forwardRef(({className:g,variant:v,...j},N)=>e.jsx("div",{ref:N,role:"alert",className:ze(kt({variant:v}),g),...j}));Fe.displayName="Alert";const It=d.forwardRef(({className:g,...v},j)=>e.jsx("h5",{ref:j,className:ze("mb-1 font-medium leading-none tracking-tight",g),...v}));It.displayName="AlertTitle";const Ve=d.forwardRef(({className:g,...v},j)=>e.jsx("div",{ref:j,className:ze("text-sm [&_p]:leading-relaxed",g),...v}));Ve.displayName="AlertDescription";let Oe=null;async function Ye(){return Oe||(Oe=(async()=>{const g=await He(()=>import("./pdf-D4X9PViX.js"),[]),v=await He(()=>import("./pdf.worker.min-U1dOgrqT.js"),[]);return g.GlobalWorkerOptions.workerSrc=v.default,g})()),Oe}function Ge(g,v){if(!v||v<=0)return;const j=g.offsetWidth;j>0&&(g.style.transform=`scaleX(${v/j})`)}function Lt({fileUrl:g,fileName:v,documentId:j,hasOcrLayout:N}){const M=d.useRef(null),ie=d.useRef(null),je=d.useRef(null),$=d.useRef(null),J=d.useRef(null),Z=d.useRef(null),Q=d.useRef(0),[X,ue]=d.useState(0),[O,D]=d.useState(1),[R,xe]=d.useState(1),[de,fe]=d.useState(!0),[y,ge]=d.useState(null);d.useEffect(()=>{let C=!1;return fe(!0),ge(null),(async()=>{try{const k=await Ye();if(N)try{const V=await fetch(`/api/deal-documents/${j}/ocr-layout`,{credentials:"include"});if(V.ok){const ee=await V.json();Z.current=Array.isArray(ee?.pages)?ee.pages:null}}catch{}const I=await k.getDocument(g).promise;if(C){I.destroy();return}$.current=I,ue(I.numPages),D(1),fe(!1)}catch{C||(ge("Could not load the PDF preview. You can still fill in the form manually."),fe(!1))}})(),()=>{C=!0,J.current?.cancel?.(),$.current?.destroy?.(),$.current=null}},[g,j,N]);const oe=d.useCallback(async()=>{const C=$.current,k=ie.current,I=je.current,V=M.current;if(!C||!k||!I||!V)return;const ee=++Q.current,ve=await Ye();let _;try{_=await C.getPage(O)}catch{return}if(ee!==Q.current)return;const ye=_.getViewport({scale:1}),te=Math.max(V.clientWidth-2,100)/ye.width*R,S=_.getViewport({scale:te}),A=window.devicePixelRatio||1;k.width=Math.floor(S.width*A),k.height=Math.floor(S.height*A),k.style.width=`${Math.floor(S.width)}px`,k.style.height=`${Math.floor(S.height)}px`,I.style.width=`${Math.floor(S.width)}px`,I.style.height=`${Math.floor(S.height)}px`,J.current?.cancel?.();const se=k.getContext("2d");if(!se)return;const ce=_.render({canvasContext:se,viewport:S,transform:A!==1?[A,0,0,A,0,0]:void 0});J.current=ce;try{await ce.promise}catch{return}if(ee!==Q.current)return;I.innerHTML="";const ae=Z.current?.[O-1];if(ae&&ae.width>0&&ae.words.length>0){const z=S.width/ae.width,l=S.height/ae.height;for(const w of ae.words){const E=document.createElement("span");E.textContent=w.text,E.className="pdf-overlay-word";const L=Math.max((w.y1-w.y0)*l,4);E.style.left=`${w.x0*z}px`,E.style.top=`${w.y0*l}px`,E.style.fontSize=`${Math.max(L*.9,4)}px`,E.style.lineHeight=`${L}px`,I.appendChild(E),Ge(E,(w.x1-w.x0)*z)}}else{let z;try{z=await _.getTextContent()}catch{return}if(ee!==Q.current)return;for(const l of z.items){if(!l.str||!l.str.trim())continue;const w=ve.Util.transform(S.transform,l.transform),E=Math.hypot(w[2],w[3]);if(E<=0)continue;const L=document.createElement("span");L.textContent=l.str,L.className="pdf-overlay-word",L.style.left=`${w[4]}px`,L.style.top=`${w[5]-E}px`,L.style.fontSize=`${E}px`,I.appendChild(L),l.width&&Ge(L,l.width*te)}}},[O,R]);return d.useEffect(()=>{!de&&!y&&oe()},[de,y,oe]),d.useEffect(()=>{const C=()=>{oe()};return window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[oe]),e.jsxs("div",{className:"rounded-md border bg-card flex flex-col","data-testid":"pdf-review-pane",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b px-3 py-2",children:[e.jsx(Je,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-sm font-medium truncate flex-1",title:v,"data-testid":"text-pdf-file-name",children:v}),e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:R<=.5,onClick:()=>xe(C=>Math.max(.5,+(C-.25).toFixed(2))),"data-testid":"button-pdf-zoom-out",children:e.jsx(Rt,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-center","data-testid":"text-pdf-zoom",children:[Math.round(R*100),"%"]}),e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:R>=3,onClick:()=>xe(C=>Math.min(3,+(C+.25).toFixed(2))),"data-testid":"button-pdf-zoom-in",children:e.jsx(Et,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2 ml-1",children:[e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:O<=1,onClick:()=>D(C=>Math.max(1,C-1)),"data-testid":"button-pdf-prev-page",children:e.jsx(ft,{className:"h-4 w-4"})}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap","data-testid":"text-pdf-page",children:X>0?`${O} / ${X}`:"–"}),e.jsx(P,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",disabled:O>=X,onClick:()=>D(C=>Math.min(X,C+1)),"data-testid":"button-pdf-next-page",children:e.jsx(gt,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b bg-muted/50",children:[e.jsx(At,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select text in the document (double-click a word), then drag the selection into a supported form field to fill it."})]}),e.jsxs("div",{ref:M,className:"relative overflow-auto max-h-[75vh] bg-muted/30 p-0",children:[de&&e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(Te,{className:"h-64 w-full"}),e.jsx(Te,{className:"h-4 w-1/2"})]}),y&&e.jsx("div",{className:"p-6 text-sm text-muted-foreground","data-testid":"text-pdf-error",children:y}),!de&&!y&&e.jsxs("div",{className:"relative inline-block",children:[e.jsx("canvas",{ref:ie,className:"block"}),e.jsx("div",{ref:je,className:"pdf-text-overlay","data-testid":"pdf-text-overlay"})]})]})]})}const Mt=["SALE","LEASE"],$t=["LISTING_SIDE","BUYER_REP","TENANT_REP","DUAL"],Ot=["NEGOTIATION","LOI","EXECUTED","IN_ESCROW","CLOSED","TERMINATED"],Ft=Ct.extend({addressStreet:St().trim().min(1,"Street address is required")}),Vt={"input-deal-number":"dealNumber","input-deal-name":"dealName","input-deal-address-street":"addressStreet","input-deal-address-city":"addressCity","input-deal-address-province":"addressProvince","input-deal-address-postal":"addressPostalCode","input-lessor-name":"lessorName","
1input-lessee-name":"lesseeName","input-deal-property-desc":"propertyDescription","input-deal-execution-date":"closeOrStartDate","input-deal-date":"closeOrStartDate","input-deal-lease-start":"leaseStartDate","input-deal-lease-end":"leaseEndDate","input-deal-lease-months":"leaseTermMonths","input-deal-volume":"volume","input-deal-commission":"grossCommission","input-seller-name":"sellerName","input-buyer-name":"buyerName","input-referral-income":"referralIncome","input-total-funds-received":"totalFundsReceived","input-trust-account-name":"trustAccountName","input-trust-account-number":"trustAccountNumber","input-operating-account":"operatingAccount","input-internal-file-reference":"internalFileReference","input-deal-notes":"notes"};function ms(){const[,g]=it(),v=dt(),j=new URLSearchParams(v),N=j.get("listingId"),M=j.get("fromPdf")==="true",[ie,je]=d.useState([]),[$,J]=d.useState([]),[Z,Q]=d.useState([]),[X,ue]=d.useState([]),[O,D]=d.useState([]),[R,xe]=d.useState([]),[de,fe]=d.useState(M),[y,ge]=d.useState(null),[oe,C]=d.useState(null),[k,I]=d.useState([]),[V,ee]=d.useState(null),ve=d.useRef(!1),_=d.useRef(!1),ye=d.useRef(!1),De=d.useRef(null),te=d.useRef(null),{toast:S}=ot(),{data:A}=ke({queryKey:["/api/parties"]}),{data:se}=ke({queryKey:["/api/listings"]}),{data:ce,isLoading:ae}=ke({queryKey:["/api/deals/next-number"]}),z=A?.filter(t=>(t.role==="AGENT"||t.role==="BROKER")&&t.isActive)||[];A?.filter(t=>t.role==="CLIENT");const l=yt({resolver:bt(Ft),defaultValues:{dealNumber:"",dealName:"",dealType:"SALE",representationType:void 0,status:"NEGOTIATION",addressStreet:"",addressCity:"",addressProvince:"",addressPostalCode:"",listingId:N?parseInt(N):void 0,clientId:void 0,primaryAgentId:null,closeOrStartDate:"",volume:"",grossCommission:"",leaseStartDate:"",leaseEndDate:"",leaseTermMonths:null,propertyDescription:"",commissionPercent:"",rentBreakdown:"",customCommissions:"",leaseOptionsRenewals:"",sellerName:"",buyerName:"",lessorName:"",lesseeName:"",referralIncome:"",totalFundsReceived:"",trustAccountName:"",trustAccountNumber:"",operatingAccount:"",paymentRecords:"",internalFileReference:"",notes:""}});d.useEffect(()=>{ce?.nextNumber&&!l.getValues("dealNumber")&&l.setValue("dealNumber",ce.nextNumber)},[ce]),d.useEffect(()=>{if(!N||!se||l.getValues("addressStreet")?.trim())return;const t=se.find(s=>s.id===parseInt(N));t?.address&&l.setValue("addressStreet",t.address)},[N,se]),d.useEffect(()=>{if(!M||ve.current)return;const t=sessionStorage.getItem("pdfExtraction");if(t){ve.current=!0;try{const s=JSON.parse(t);sessionStorage.removeItem("pdfExtraction");const a=s?.pdfDocument||s?.extraction!==void 0?s.extraction:s;if(s?.pdfDocument?.id&&ge(s.pdfDocument),s?.extractionError&&C(s.extractionError),s?.partyMatches&&Object.keys(s.partyMatches).length>0&&ee(s.partyMatches),!a)return;const n=[],i=[],r=(o,p,F)=>{if(["closeOrStartDate","leaseStartDate","leaseEndDate"].includes(o)){const U=we(p);if(!U){i.push(o);return}p=U}else if(["leaseTermMonths","volume","grossCommission","commissionPercent"].includes(o)){const U=pe(p,o==="leaseTermMonths");if(U===null){i.push(o);return}p=o==="leaseTermMonths"?Number(U):U}l.setValue(o,p,{shouldDirty:!0,shouldValidate:!0}),F&&n.push(F)};if((a.propertyAddressStreet||a.propertyAddress)&&r("addressStreet",a.propertyAddressStreet||a.propertyAddress,"input-deal-address-street"),a.propertyAddressCity&&r("addressCity",a.propertyAddressCity,"input-deal-address-city"),a.propertyAddressState&&r("addressProvince",a.propertyAddressState,"input-deal-address-province"),a.propertyAddressZip&&r("addressPostalCode",a.propertyAddressZip,"input-deal-address-postal"),a.dealName&&r("dealName",a.dealName,"input-deal-name"),a.notes&&r("notes",a.notes,"input-deal-notes"),a.documentType==="LEASE"){if(l.setValue("dealType","LEASE"),a.propertyDescription&&r("propertyDescription",a.propertyDescription,"input-deal-property-desc"),a.executionDate&&r("closeOrStartDate",a.executionDate,"input-deal-execution-date"),a.leaseStartDate&&r("leaseStartDate",a.leaseStartDate,"input-deal-lease-start"),a.leaseEndDate&&r("leaseEndDate",a.leaseEndDate,"input-deal-lease-end"),a.leaseTermMonths!=null&&r("leaseTermMonths",a.leaseTermMonths,"input-deal-lease-months"),a.commissionPercent&&r("commissionPercent",a.commissionPercent),a.grossCommission&&r("grossCommission",a.grossCommission),a.lessorName&&r("lessorName",String(a.lessorName),"input-lessor-name"),a.lesseeName&&r("lesseeName",
1String(a.lesseeName),"input-lessee-name"),a.monthlyRent){const o=pe(a.monthlyRent);o===null&&i.push("monthlyRent"),J([{startDate:we(a.leaseStartDate)||"",endDate:we(a.leaseEndDate)||"",rate:o||"",months:pe(a.leaseTermMonths,!0)||"",commissionPercent:a.commissionPercent&&pe(a.commissionPercent)||""}]),n.push("input-rent-rate-0","input-rent-months-0","input-rent-start-0","input-rent-end-0")}a.milestones&&Array.isArray(a.milestones)&&xe(a.milestones)}else a.documentType==="SALE"&&(l.setValue("dealType","SALE"),a.closeDate&&r("closeOrStartDate",a.closeDate,"input-deal-date"),a.salePrice&&r("volume",a.salePrice,"input-deal-volume"),a.grossCommission&&r("grossCommission",a.grossCommission,"input-deal-commission"),a.commissionPercent&&r("commissionPercent",a.commissionPercent),a.sellerName&&r("sellerName",a.sellerName,"input-seller-name"),a.buyerName&&r("buyerName",a.buyerName,"input-buyer-name"),a.milestones&&Array.isArray(a.milestones)&&xe(a.milestones));I(n),i.length&&S({title:"Review PDF fields",description:`Could not use ${i.join(", ")}. Enter valid dates and numbers manually.`,variant:"destructive"})}catch{C("The imported deal details could not be read. Please enter them manually.")}}},[M]),d.useEffect(()=>{if(k.length===0)return;const t=setTimeout(()=>{for(const s of k){const a=document.querySelector(`[data-testid="${s}"]`);if(!a)continue;a.setAttribute("data-pdf-filled","true");const n=()=>{a.removeAttribute("data-pdf-filled"),a.removeEventListener("input",n)};a.addEventListener("input",n)}},150);return()=>clearTimeout(t)},[k]);const w=d.useCallback(()=>{te.current?.classList.remove("pdf-drop-highlight"),te.current=null},[]),E=d.useCallback(t=>{if(!y)return;const s=t.target.closest?.("input, textarea");s&&!s.readOnly&&!s.disabled&&s.type!=="file"?(t.preventDefault(),t.dataTransfer.dropEffect="copy",te.current!==s&&(te.current?.classList.remove("pdf-drop-highlight"),s.classList.add("pdf-drop-highlight"),te.current=s)):w()},[y,w]),L=d.useCallback(t=>{if(!y)return;const s=t.target.closest?.("input, textarea");if(w(),!s||s.readOnly||s.disabled)return;const a=t.dataTransfer.getData("text/plain");if(!a||!a.trim())return;t.preventDefault();const n=Vt[s.dataset.testid||""],i=s.dataset.dealCollection,r=Number(s.dataset.dealIndex),o=s.dataset.dealKey;let p=a.replace(/\s+/g," ").trim();if(s instanceof HTMLInputElement&&s.type==="date"){const F=we(p);if(!F){S({title:"Date not recognized",description:"Use a date such as 01/05/2025 or January 5, 2025.",variant:"destructive"});return}p=F}else if(s instanceof HTMLInputElement&&s.type==="number"){const F=pe(p,o==="months"||n==="leaseTermMonths");if(F===null){S({title:"Number not recognized",description:"Use a valid number (whole months for term fields).",variant:"destructive"});return}p=F}if(n)l.setValue(n,n==="leaseTermMonths"?Number(p):p,{shouldDirty:!0,shouldValidate:!0});else if(i&&o&&Number.isInteger(r)&&r>=0)if(i==="rent")me(r,o,p);else if(i==="option")ne(r,o,p);else if(i==="payment")D(F=>F.map((U,rt)=>rt===r?{...U,[o]:p}:U));else if(i==="custom")Re(r,o,p);else{S({title:"Cannot fill this field from the PDF",description:"Please enter this value manually.",variant:"destructive"});return}else{S({title:"Cannot fill this field from the PDF",description:"Please enter this value manually.",variant:"destructive"});return}s.removeAttribute("data-pdf-filled"),s.focus()},[y,w,l,S]),Pe=l.watch("dealType"),he=Pe==="LEASE",Ae=l.watch("representationType");d.useEffect(()=>{if(!V||ye.current)return;const t=Ae==="TENANT_REP"||Ae==="BUYER_REP",a=V[Pe==="LEASE"?t?"lessee":"lessor":t?"buyer":"seller"],n=a&&a.role==="CLIENT"?a.id:null,i=l.getValues("clientId")??null;if(i!==null&&i!==De.current)return;n!==i&&l.setValue("clientId",n??void 0),De.current=n;const r=setTimeout(()=>{const o=document.querySelector('[data-testid="select-deal-client"]');o&&(n?o.setAttribute("data-pdf-filled","true"):o.removeAttribute("data-pdf-filled"))},150);return()=>clearTimeout(r)},[V,Ae,Pe]);const Ue=d.useCallback(t=>{const s=Number(t.rate)||0,a=Number(t.months)||0,n=Number(t.commissionPercent)||0;return{rentTotal:s*a,commission:s*a*(n/100)}},[]),Ee=ct({mutationFn:t=>Ne("POST","/api/deals",t),onSuccess:async t=>{const s=await t.json();if(y&&!_.current)try{await Ne("POST",`/api/deals/${s.id}/documents/attach`,{documentId:y.id}),_.current=!0}catch{}if(R.length>0)for(const a of R)try{await Ne("POST",`/api/deals/${s.id}/milestones`,{dealId:s.id,name:a.name,description:a.description||null,dueDate:a.dueDate,status:"PENDING"})}catch{}
1We.invalidateQueries({queryKey:["/api/deals"]}),We.invalidateQueries({queryKey:["/api/deals/next-number"]}),S({title:"Deal created successfully"}),g(`/deals/${s.id}`)},onError:t=>{t.message.includes("already in use")?l.setError("dealNumber",{message:t.message.replace(" Please choose a different number.","")}):S({title:"Error",description:t.message,variant:"destructive"})}}),Ze=t=>{const s={...t,agentIds:ie};if(t.dealType==="LEASE"){$.length>0&&(s.rentBreakdown=JSON.stringify($)),s.customCommissions=JSON.stringify(Z),s.leaseOptionsRenewals=JSON.stringify(X);const n=$.reduce((i,r)=>{const o=(Number(r.rate)||0)*(Number(r.months)||0);return i+o*((Number(r.commissionPercent)||0)/100)},0)+Z.reduce((i,r)=>i+(Number(r.amount)||0),0);s.grossCommission=String(n.toFixed(2))}O.length>0&&(s.paymentRecords=JSON.stringify(O));const a=["volume","grossCommission","referralIncome","totalFundsReceived","commissionPercent"];for(const n of a)(!s[n]||s[n]==="")&&(s[n]=null);Ee.mutate(s)},Qe=()=>{J(t=>[...t,{startDate:"",endDate:"",rate:"",months:"",commissionPercent:""}])},me=(t,s,a)=>{J(n=>n.map((i,r)=>r===t?{...i,[s]:a}:i))},Xe=t=>{J(s=>s.filter((a,n)=>n!==t))},et=()=>{Q(t=>[...t,{description:"",amount:""}])},Re=(t,s,a)=>{Q(n=>n.map((i,r)=>r===t?{...i,[s]:a}:i))},tt=t=>{Q(s=>s.filter((a,n)=>n!==t))},st=()=>{ue(t=>[...t,{type:"OPTION",description:"",startDate:"",endDate:"",rate:"",months:"",commissionPercent:""}])},ne=(t,s,a)=>{ue(n=>n.map((i,r)=>r===t?{...i,[s]:a}:i))},at=t=>{ue(s=>s.filter((a,n)=>n!==t))},nt=t=>{je(s=>s.includes(t)?s.filter(a=>a!==t):[...s,t])},qe=()=>{y&&!_.current&&Ne("DELETE",`/api/deal-documents/${y.id}`).catch(()=>{}),g("/deals")};return ae?e.jsxs("div",{className:"p-6 space-y-6 max-w-5xl mx-auto",children:[e.jsx(Te,{className:"h-8 w-48"}),e.jsx(Te,{className:"h-64 w-full"})]}):e.jsxs("div",{className:y?"p-6 space-y-6":"p-6 space-y-6 max-w-5xl mx-auto","data-testid":"page-deal-new",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(P,{variant:"ghost",size:"icon",onClick:qe,"data-testid":"button-back-to-deals",children:e.jsx(wt,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight","data-testid":"text-new-deal-title",children:"New Deal"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:y?"Review the document and complete the deal details":"Create a new transaction"})]}),e.jsx(Ie,{variant:"secondary",children:"DRAFT"})]}),de&&!oe&&e.jsxs(Fe,{"data-testid":"alert-pdf-prefilled",children:[e.jsx(Je,{className:"h-4 w-4"}),e.jsxs(Ve,{children:["Pre-filled from PDF — highlighted fields were filled automatically. Review and adjust before saving.",y&&e.jsx("span",{className:"block mt-1 text-muted-foreground",children:"Tip: select text in the document on the left, then drag it into a supported form field."}),R.length>0&&e.jsxs("span",{className:"block mt-1 text-muted-foreground",children:[R.length," milestone",R.length!==1?"s":""," will be created with this deal."]})]})]}),de&&oe&&e.jsxs(Fe,{"data-testid":"alert-pdf-extraction-error",children:[e.jsx(Tt,{className:"h-4 w-4"}),e.jsxs(Ve,{children:["We couldn't read this document's details automatically, so the form starts blank.",y?" Use the PDF on the left as a reference — select text and drag it into a supported form field.":" Please fill in the deal details manually."]})]}),e.jsxs("div",{className:y?"flex flex-col xl:flex-row gap-6 items-start":"",children:[y&&e.jsx("div",{className:"w-full xl:w-[45%] xl:max-w-[720px] shrink-0 xl:sticky xl:top-4",children:e.jsx(Lt,{fileUrl:y.filePath,fileName:y.fileName,documentId:y.id,hasOcrLayout:y.hasOcrLayout})}),e.jsx("div",{className:y?"flex-1 min-w-0":"",onDragOverCapture:E,onDropCapture:L,onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||w()},children:e.jsx(Nt,{...l,children:e.jsx("form",{onSubmit:l.handleSubmit(Ze,()=>S({title:"Review deal fields",description:"Check the marked fields and enter valid dates and numbers before saving.",variant:"destructive"})),children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(q,{children:[e.jsx(re,{children:e.jsx(le,{className:"text-base",children:"Deal Details"})}
1),e.jsxs(H,{className:"space-y-4",children:[e.jsx(m,{control:l.control,name:"dealType",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Deal Type *"}),e.jsxs(W,{onValueChange:t.onChange,value:t.value,children:[e.jsx(x,{children:e.jsx(B,{"data-testid":"select-deal-type",children:e.jsx(K,{})})}),e.jsx(Y,{children:Mt.map(s=>e.jsx(b,{value:s,children:s},s))})]}),e.jsx(h,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(m,{control:l.control,name:"dealNumber",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Deal Number *"}),e.jsx(x,{children:e.jsx(f,{...t,"data-testid":"input-deal-number"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"dealName",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Deal Name *"}),e.jsx(x,{children:e.jsx(f,{...t,"data-testid":"input-deal-name"})}),e.jsx(h,{})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(m,{control:l.control,name:"representationType",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Rep Type"}),e.jsxs(W,{onValueChange:s=>t.onChange(s==="none"?null:s),value:t.value||"none",children:[e.jsx(x,{children:e.jsx(B,{"data-testid":"select-deal-rep-type",children:e.jsx(K,{})})}),e.jsxs(Y,{children:[e.jsx(b,{value:"none",children:"—"}),$t.map(s=>e.jsx(b,{value:s,children:s.replace(/_/g," ")},s))]})]}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"status",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Status *"}),e.jsxs(W,{onValueChange:t.onChange,value:t.value,children:[e.jsx(x,{children:e.jsx(B,{"data-testid":"select-deal-status",children:e.jsx(K,{})})}),e.jsx(Y,{children:Ot.map(s=>e.jsx(b,{value:s,children:s},s))})]}),e.jsx(h,{})]})})]}),e.jsx(m,{control:l.control,name:"listingId",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Linked Listing (optional)"}),e.jsxs(W,{onValueChange:s=>{if(s==="none"){t.onChange(null);return}const a=parseInt(s);t.onChange(a);const n=se?.find(i=>i.id===a);n?.address&&!l.getValues("addressStreet")?.trim()&&l.setValue("addressStreet",n.address,{shouldValidate:!0})},value:t.value?String(t.value):"none",children:[e.jsx(x,{children:e.jsx(B,{"data-testid":"select-deal-listing",children:e.jsx(K,{placeholder:"Standalone"})})}),e.jsxs(Y,{children:[e.jsx(b,{value:"none",children:"Standalone"}),se?.map(s=>e.jsxs(b,{value:String(s.id),children:[e.jsx("span",{children:s.propertyName}),s.address&&e.jsx("span",{className:"block text-xs text-muted-foreground",children:s.address})]},s.id))]})]}),e.jsx(h,{})]})}),e.jsxs("div",{className:"space-y-3 rounded-md border p-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:"Property Address"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Auto-filled from the linked listing when available. Street address is required."})]}),e.jsx(m,{control:l.control,name:"addressStreet",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Street Address *"}),e.jsx(x,{children:e.jsx(ut,{...t,value:t.value||"",onSelected:(s,a)=>{const n=xt(s,a);l.setValue("addressStreet",n.street,{shouldDirty:!0,shouldValidate:!0}),n.city&&l.setValue("addressCity",n.city,{shouldDirty:!0}),n.province&&l.setValue("addressProvince",n.province,{shouldDirty:!0}),n.postalCode&&l.setValue("addressPostalCode",n.postalCode,{shouldDirty:!0})},placeholder:"123 Main St","data-testid":"input-deal-address-street"})}),e.jsx(h,{})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(m,{control:l.control,name:"addressCity",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"City"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-deal-address-city"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"addressProvince",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Province / State"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-deal-address-province"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"addressPostalCode",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Postal Code"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-deal-address-postal"})}),e.jsx(h,{})]})})]})]}),e.jsx(m,{control:l.control,name:"clientId",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:he?"Lessee / Tenant":"Client"}),e.jsx(x,{children:e.jsx(Be,{value:t.value??null,onChange:s=>{ye.current=!0,document.querySelector('[data-testid="select-deal-client"]')?.removeAttribute("data-pdf-filled"),t.onChange(s)},parties:A||[],filterRoles:["CLIENT"],placeholder:he?"Search lessee / tenant...":"Search client...","data-testid":"select-deal-client",defaultNewPartyRole:"CLIENT"})}),e.jsx(h,{})]})}),he?e.jsxs(e.Fragment,{children:[e.jsx(m,{control:l.control,name:"lessorPartyId",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Lessor / Landlord"}),e.jsx(x,{children:e.jsx(Be,{value:t.value??null,onChange:s=>t.onChange(s),parties:A||[],placeholder:"Search lessor / landlord...","data-testid":"select-lessor-party",defaultNewPartyRole:"CLIENT"})}),e.jsx(h,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(m,{control:l.control,name:"lessorName",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Lessor Name (as on document)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",placeholder:"e.g. ABC Properties LLC","data-testid":"input-lessor-name"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"lesseeName",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Lessee Name (as on document)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",placeholder:"e.g. 
1XYZ Retail Inc","data-testid":"input-lessee-name"})}),e.jsx(h,{})]})})]}),e.jsx(m,{control:l.control,name:"propertyDescription",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Property Description"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",placeholder:"e.g. Suite 200, 5,000 SF Office","data-testid":"input-deal-property-desc"})}),e.jsx(h,{})]})}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsx(m,{control:l.control,name:"closeOrStartDate",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Execution Date"}),e.jsx(x,{children:e.jsx(G,{...t,value:t.value,"data-testid":"input-deal-execution-date"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"leaseStartDate",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Lease Start"}),e.jsx(x,{children:e.jsx(G,{...t,value:t.value,"data-testid":"input-deal-lease-start"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"leaseEndDate",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Lease End"}),e.jsx(x,{children:e.jsx(G,{...t,value:t.value,"data-testid":"input-deal-lease-end"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"leaseTermMonths",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Term (Months)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value??"",type:"number",min:"0",step:"1",onChange:s=>t.onChange(s.target.value===""?null:s.target.valueAsNumber),"data-testid":"input-deal-lease-months"})}),e.jsx(h,{})]})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(m,{control:l.control,name:"closeOrStartDate",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Close Date"}),e.jsx(x,{children:e.jsx(G,{...t,value:t.value,"data-testid":"input-deal-date"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"volume",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Sale Volume ($)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",type:"number",step:"0.01","data-testid":"input-deal-volume"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"grossCommission",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Gross Commission ($)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",type:"number",step:"0.01","data-testid":"input-deal-commission"})}),e.jsx(h,{})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(m,{control:l.control,name:"sellerName",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Seller Name"}),e.jsx(x,{children:e.jsx(be,{value:t.value||"",onChange:t.onChange,parties:A||[],placeholder:"Type to search parties...","data-testid":"input-seller-name"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"buyerName",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Buyer Name"}),e.jsx(x,{children:e.jsx(be,{value:t.value||"",onChange:t.onChange,parties:A||[],placeholder:"Type to search parties...","data-testid":"input-buyer-name"})}),e.jsx(h,{})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(m,{control:l.control,name:"referralIncome",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Additional Referral Income ($)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",type:"number",step:"0.01","data-testid":"input-referral-income"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"totalFundsReceived",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Total Funds Received ($)"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"",type:"number",step:"0.01","data-testid":"input-total-funds-received"})}),e.jsx(h,{})]})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(m,{control:l.control,name:"trustAccountName",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Trust Account Name"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-trust-account-name"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"trustAccountNumber",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Trust Account Number"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-trust-account-number"})}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"operatingAccount",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Operating Account"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-operating-account"})}),e.jsx(h,{})]})})]}),e.jsx(m,{control:l.control,name:"internalFileReference",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Internal File Reference"}),e.jsx(x,{children:e.jsx(f,{...t,value:t.value||"","data-testid":"input-internal-file-reference"})}),e.jsx(h,{})]})})]}),z.length>0&&e.jsxs("div",{children:[e.jsx(c,{children:"Assigned Agents"}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:z.map(t=>e.jsx(Ie,{variant:ie.includes(t.id)?"default":"secondary",className:"cursor-pointer",onClick:()=>nt(t.id),"data-testid":`badge-deal-agent-${t.id}`,children:t.name},t.id))})]}),e.jsx(m,{control:l.control,name:"primaryAgentId",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Primary Agent"}),e.jsxs(W,{onValueChange:s=>t.onChange(s==="none"?null:parseInt(s)),value:t.value?String(t.value):"none",children:[e.jsx(x,{children:e.jsx(B,{"data-testid":"select-deal-primary-agent",children:e.jsx(K,{placeholder:"No primary agent"})})}),e.jsxs(Y,{children:[e.jsx(b,{value:"none",children:"No primary agent"}),z.map(s=>e.jsx(b,{value:String(s.id),children:s.name},s.id))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Agent of record for this deal. Their phone and email appear in the invoice footer."}),e.jsx(h,{})]})}),e.jsx(m,{control:l.control,name:"notes",render:({field:t})=>e.jsxs(u,{children:[e.jsx(c,{children:"Notes"}),e.jsx(x,{children:e.jsx(mt,{...t,value:t.value||"",rows:3,"data-testid":"input-deal-notes"})}),e.jsx(h,{})]})})]})]}),he&&e.jsxs(q,{children:[e.jsx(re,{className:"flex flex-row items-center justify-between gap-1 space-y-0",children:e.jsx(le,{className:"text-base",children:"Rent & Commission Breakdown"})}),e.jsx(H,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-sm font-medium",children:"Custom Commissions"}),e.jsxs(P,{type:"button",size:"sm",variant:"secondary",onClick:et,"data-testid":"button-add-custom-commission",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"})," Add Custom"]})]}),Z.map((t,s)=>e.jsxs("div",{className:"border rounded-md p-3 space-y-2","data-testid":`custom-comm-${s}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Custom Commission ",s+1]}),e.jsx(P,{type:"button",size:"icon",variant:"ghost",onClick:()=>tt(s),children:e.jsx(Se,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx(T,{className:"text-xs",children:"Description"}),e.jsx(f,{value:t.description,placeholder:"e.g. Equipment sale commission",onChange:a=>Re(s,"description",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Amount ($)"}),e.jsx(f,{type:"number",step:"0.01",value:t.amount,onChange:a=>Re(s,"amount",a.target.value),"data-deal-collection":"custom","data-deal-index":s,"data-deal-key":"amount"})]})]})]},s)),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx(T,{className:"text-sm font-medium",children:"Rent Terms"}),e.jsxs(P,{type:"button",size:"sm",variant:"secondary",onClick:Qe,"data-testid":"button-add-rent-term",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"})," Add Term"]})]}),$.map((t,s)=>{const{rentTotal:a,commission:n}=Ue(t);return e.jsxs("div",{className:"border rounded-md p-3 space-y-2","data-testid":`rent-term-${s}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Term ",s+1]}),e.jsx(P,{type:"button",size:"icon",variant:"ghost",onClick:()=>Xe(s),"data-testid":`button-remove-rent-term-${s}`,children:e.jsx(Se,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Start Date"}),e.jsx(G,{value:t.startDate,onChange:i=>me(s,"startDate",i),"data-testid":`input-rent-start-${s}`,"data-deal-collection":"rent","data-deal-index":s,"data-deal-key":"startDate"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"End Date"}
1),e.jsx(G,{value:t.endDate,onChange:i=>me(s,"endDate",i),"data-testid":`input-rent-end-${s}`,"data-deal-collection":"rent","data-deal-index":s,"data-deal-key":"endDate"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Monthly Rate ($)"}),e.jsx(f,{type:"number",step:"0.01",value:t.rate,onChange:i=>me(s,"rate",i.target.value),"data-testid":`input-rent-rate-${s}`,"data-deal-collection":"rent","data-deal-index":s,"data-deal-key":"rate"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Months"}),e.jsx(f,{type:"number",min:"0",step:"1",value:t.months,onChange:i=>me(s,"months",i.target.value),"data-testid":`input-rent-months-${s}`,"data-deal-collection":"rent","data-deal-index":s,"data-deal-key":"months"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Commission %"}),e.jsx(f,{type:"number",step:"0.01",value:t.commissionPercent||"",placeholder:"e.g. 5",onChange:i=>me(s,"commissionPercent",i.target.value),"data-deal-collection":"rent","data-deal-index":s,"data-deal-key":"commissionPercent"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground flex justify-between",children:[e.jsxs("span",{children:["Rent Total: $",a.toLocaleString(void 0,{minimumFractionDigits:2})]}),e.jsxs("span",{children:["Commission: $",n.toLocaleString(void 0,{minimumFractionDigits:2})]})]})]},s)}),($.length>0||Z.length>0)&&(()=>{const t=$.reduce((n,i)=>{const{commission:r}=Ue(i);return n+r},0),s=Z.reduce((n,i)=>n+(Number(i.amount)||0),0),a=t+s;return e.jsx("div",{className:"pt-2 border-t",children:e.jsxs("span",{className:"text-sm font-bold","data-testid":"text-total-lease-commission",children:["Total Commission: $",a.toLocaleString(void 0,{minimumFractionDigits:2})]})})})()]})})]}),he&&e.jsxs(q,{children:[e.jsxs(re,{className:"flex flex-row items-center justify-between gap-1 space-y-0",children:[e.jsx(le,{className:"text-base",children:"Lease Options & Renewals"}),e.jsxs(P,{type:"button",size:"sm",variant:"secondary",onClick:st,"data-testid":"button-add-option",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"})," Add"]})]}),e.jsx(H,{children:e.jsxs("div",{className:"space-y-3",children:[X.map((t,s)=>{const a=Number(t.rate)||0,n=Number(t.months)||0,i=Number(t.commissionPercent)||0,r=a*n,o=r*(i/100);return e.jsxs("div",{className:"border rounded-md p-3 space-y-2","data-testid":`option-term-${s}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:[t.type==="RENEWAL"?"Renewal":"Option"," ",s+1]}),e.jsx(P,{type:"button",size:"icon",variant:"ghost",onClick:()=>at(s),children:e.jsx(Se,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Type"}),e.jsxs(W,{value:t.type,onValueChange:p=>ne(s,"type",p),children:[e.jsx(B,{children:e.jsx(K,{})}),e.jsxs(Y,{children:[e.jsx(b,{value:"OPTION",children:"Option"}),e.jsx(b,{value:"RENEWAL",children:"Renewal"})]})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Description"}),e.jsx(f,{value:t.description,placeholder:"e.g. 3-year renewal option",onChange:p=>ne(s,"description",p.target.value),"data-deal-collection":"option","data-deal-index":s,"data-deal-key":"description"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Start Date"}),e.jsx(G,{value:t.startDate,onChange:p=>ne(s,"startDate",p),"data-deal-collection":"option","data-deal-index":s,"data-deal-key":"startDate"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"End Date"}),e.jsx(G,{value:t.endDate,onChange:p=>ne(s,"endDate",p),"data-deal-collection":"option","data-deal-index":s,"data-deal-key":"endDate"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Monthly Rate ($)"}),e.jsx(f,{type:"number",step:"0.01",value:t.rate,onChange:p=>ne(s,"rate",p.target.value),"data-deal-collection":"option","data-deal-index":s,"data-deal-key":"rate"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Months"}),e.jsx(f,{type:"number",min:"0",step:"1",value:t.months,onChange:p=>ne(s,"months",p.target.value),"data-deal-collection":"option","data-deal-index":s,"data-deal-key":"months"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"Commission %"}),e.jsx(f,{type:"number",step:"0.01",value:t.commissionPercent,placeholder:"e.g. 2.5",onChange:p=>ne(s,"commissionPercent",p.target.value),"data-deal-collection":"option","data-deal-index":s,"data-deal-key":"commissionPercent"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground flex justify-between",children:[e.jsxs("span",{children:["Rent Total: $",r.toLocaleStr
1ing(void 0,{minimumFractionDigits:2})]}),e.jsxs("span",{children:["Commission: $",o.toLocaleString(void 0,{minimumFractionDigits:2})]})]})]},s)}),X.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:'Click "Add" to create an option or renewal term.'})]})})]}),e.jsxs(q,{children:[e.jsxs(re,{className:"flex flex-row items-center justify-between gap-1 space-y-0",children:[e.jsx(le,{className:"text-base",children:"Payments Received"}),e.jsxs(P,{type:"button",size:"sm",variant:"outline",onClick:()=>D(t=>[...t,{method:"",checkNumber:"",date:"",payor:"",payee:"",depositAccount:"",amount:"",paymentType:""}]),"data-testid":"button-add-payment-record",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"})," Add Payment"]})]}),e.jsx(H,{className:"space-y-3",children:O.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:'No payments recorded yet. Click "Add Payment" to add one.'}):O.map((t,s)=>{const a=t.payor.toLowerCase().includes("wiese");return e.jsxs("div",{className:"border rounded-md p-3 space-y-2","data-testid":`payment-record-${s}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Payment ",s+1,a?" (Payout)":""]}),e.jsx(P,{type:"button",size:"icon",variant:"ghost",onClick:()=>D(n=>n.filter((i,r)=>r!==s)),"data-testid":`button-remove-payment-${s}`,children:e.jsx(Se,{className:"h-3 w-3 text-destructive"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Method"}),e.jsxs(W,{value:t.method||"none",onValueChange:n=>D(i=>i.map((r,o)=>o===s?{...r,method:n==="none"?"":n,checkNumber:n!=="CHECK"?"":r.checkNumber}:r)),children:[e.jsx(B,{"data-testid":`select-payment-method-${s}`,children:e.jsx(K,{placeholder:"Select method"})}),e.jsxs(Y,{children:[e.jsx(b,{value:"none",children:"Select..."}),e.jsx(b,{value:"CHECK",children:"Check"}),e.jsx(b,{value:"WIRE",children:"Wire"}),e.jsx(b,{value:"CASH",children:"Cash"})]})]})]}),t.method==="CHECK"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Check Number"}),e.jsx(f,{value:t.checkNumber,onChange:n=>D(i=>i.map((r,o)=>o===s?{...r,checkNumber:n.target.value}:r)),"data-testid":`input-payment-check-number-${s}`,"data-deal-collection":"payment","data-deal-index":s,"data-deal-key":"checkNumber"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Date Received"}),e.jsx(G,{value:t.date,onChange:n=>D(i=>i.map((r,o)=>o===s?{...r,date:n}:r)),"data-testid":`input-payment-date-${s}`,"data-deal-collection":"payment","data-deal-index":s,"data-deal-key":"date"})]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Payor"}),e.jsx(be,{value:t.payor,onChange:n=>D(i=>i.map((r,o)=>o===s?{...r,payor:n}:r)),parties:[{id:-1,name:"Wiese & Associates",company:null},...A||[]],placeholder:"Type to search...","data-testid":`input-payment-payor-${s}`})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Payee"}),e.jsx(be,{value:t.payee,onChange:n=>D(i=>i.map((r,o)=>o===s?{...r,payee:n}:r)),parties:[{id:-1,name:"Wiese & Associates",company:null},...A||[]],placeholder:"Type to search...","data-testid":`input-payment-payee-${s}`})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Deposit Account"}),e.jsxs(W,{value:t.depositAccount||"none",onValueChange:n=>D(i=>i.map((r,o)=>o===s?{...r,depositAccount:n==="none"?"":n}:r)),children:[e.jsx(B,{"data-testid":`select-payment-account-${s}`,children:e.jsx(K,{placeholder:"Select account"})}),e.jsxs(Y,{children:[e.jsx(b,{value:"none",children:"Select..."}),e.jsx(b,{value:"TRUST",children:"W&A Trust Account"}),e.jsx(b,{value:"COMPANY",children:"W&A Company Account"})]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs text-muted-foreground",children:["Amount ($)",a?" (negative)":""]}),e.jsx(f,{type:"number",step:"0.01",value:t.amount,onChange:n=>D(i=>i.map((r,o)=>o===s?{...r,amount:n.target.value}:r)),"data-testid":`input-payment-amount-${s}`,"data-deal-collection":"payment","data-deal-index":s,"data-deal-key":"amount"})]})]}),e.jsx("div",{className:"flex items-center gap-2 pt-1",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Payment Type"}),e.jsxs(W,{value:t.paymentType||"none",onValueChange:n=>D(i=>i.map((r,o)=>o===s?{...r,paymentType:n==="none"?"":n}:r)),children:[e.jsx(B,{"data-testid":`select-payment-type-${s}`,children:e.jsx(K,{placeholder:"Select type"})}),e.jsxs(Y,{children:[e.jsx(b,{value:"none",children:"Select..."}),e.jsx(b,{value:"COMMISSION",children:"Commission"}),e.jsx(b,{value:"SECURITY_DEPOSIT",children:"Security Deposit"}),e.jsx(b,{value:"RENT",children:"Rent"}),e.jsx(b,{value:"REIMBURSEMENT",children:"Reimbursement"}),e.jsx(b,{value:"OTHER",children:"Other"})]})]})]})})]},s)})})]}),e.jsxs(q,{children:[e.jsx(re,{children:e.jsx(le,{className:"text-base",children:"Commission Recipients"})}),e.jsx(H,{children:e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6","data-testid":"text-recipients-placeholder",children:"Save the deal first, then add commission recipients from the deal detail page."})})]}),e.jsxs(q,{children:[e.jsx(re,{children:e.jsxs(le,{className:"text-base flex items-center gap-2",children:[e.jsx(vt,{className:"h-4 w-4"}),"Milestones & Contingencies"]}
1)}),e.jsx(H,{children:R.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"The following milestones will be created with this deal:"}),e.jsxs(ht,{children:[e.jsx(pt,{children:e.jsxs(Ke,{children:[e.jsx(Le,{className:"text-xs",children:"Name"}),e.jsx(Le,{className:"text-xs",children:"Due Date"}),e.jsx(Le,{className:"text-xs",children:"Status"})]})}),e.jsx(jt,{children:R.map((t,s)=>e.jsxs(Ke,{"data-testid":`row-pdf-milestone-${s}`,children:[e.jsx(Me,{children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.description})]})}),e.jsx(Me,{className:"text-sm",children:t.dueDate}),e.jsx(Me,{children:e.jsx(Ie,{variant:"secondary",children:"PENDING"})})]},s))})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6","data-testid":"text-milestones-placeholder",children:"Save the deal first, then add milestones from the deal detail page."})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(q,{children:e.jsx(H,{className:"pt-6",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs(P,{type:"submit",className:"w-full",disabled:Ee.isPending,"data-testid":"button-save-deal",children:[e.jsx(Dt,{className:"h-4 w-4 mr-2"}),Ee.isPending?"Creating...":"Create Deal"]}),e.jsx(P,{type:"button",variant:"secondary",className:"w-full",onClick:qe,"data-testid":"button-cancel-deal",children:"Cancel"})]})})}),e.jsxs(q,{children:[e.jsx(re,{children:e.jsxs(le,{className:"text-base flex items-center gap-2",children:[e.jsx(Pt,{className:"h-4 w-4"}),"Generate Invoices"]})}),e.jsx(H,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Save the deal and add commission recipients before generating invoices."})})]}),e.jsxs(q,{children:[e.jsx(re,{children:e.jsx(le,{className:"text-base",children:"Invoice History"})}),e.jsx(H,{children:e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No invoices generated yet"})})]})]})]})})})})]})]})}export{ms 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.