PageSourceSearch

https://reamintell.com/assets/LeaseDetailPage-B7rbimCm.js

js reamintell.com collected 2026-09-25 03:42:57 UTC 85,787 bytes, 7 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/RentEscalationModal-D5hYPFlL.js","assets/vendor-grid-ClmSNH6q.js","assets/vendor-charts-B2bLUVVL.js","assets/index-Cab6mplo.js","assets/index-CYy429hA.css","assets/Card-BUL_z2x0.js","assets/percent-BFJcsYvN.js","assets/LateFeeRuleModal-YS1cJQDf.js","assets/LeaseComparisonModal-B3kiEbyO.js","assets/Badge-CFTtQM9N.js","assets/arrow-left-right-N_XdsO5A.js","assets/file-exclamation-point-C-820EVR.js","assets/MoveInOutInspectionModal-D38Ju1qo.js","assets/InspectionComparisonView-DlukpL6c.js","assets/arrow-up-laBNBGNi.js","assets/minus-UfJ0aFe3.js"])))=>i.map(i=>d[i]);
2import{c as Da,o as he,a8 as Pa,X as Ce,w as rt,k as pe,aW as o,ag as we,R as tt,A as Ma,Z as de,aO as Jt,U as Mt,I as za,B as Oa,aT as Ba,l as nt,aP as Ua,r as zt,ac as at,a2 as Va,bl as Ia,T as Ge,Y as qa,H as Ha,a5 as Ot,b as Bt,af as Ke,a9 as Ja,a7 as Ya,aw as Ut,aN as Ga,F as Vt,aH as We,_ as ge}from"./index-Cab6mplo.js";import{j as e}from"./vendor-grid-ClmSNH6q.js";import{r}from"./vendor-charts-B2bLUVVL.js";import{b as j,C as W,a as X}from"./Card-BUL_z2x0.js";import{B as v}from"./Badge-CFTtQM9N.js";import{S as Ka,L as Wa}from"./LeaseAmendmentModal-DbTm0oB1.js";import{S as Xa}from"./SendForSignatureModal-BWX0tQpg.js";import{L as Za}from"./LeaseEditorModal-BAl9kVVI.js";import{G as _e}from"./git-compare-DlXTQ4FO.js";import{M as Qa}from"./minus-UfJ0aFe3.js";import{p as Se,f as ie}from"./dates-_biQdKXh.js";import{C as st}from"./calendar-plus-BpWtb0CY.js";import{P as It}from"./pen-line-DksZ9NyM.js";import{F as qt}from"./file-pen-h0ydPSvf.js";import{H as es}from"./history-DHqenpcx.js";import"./archive-cZuD6EXJ.js";import"./GuidedSigningControls-Guz26wsk.js";import"./circle-BjHJXJMD.js";import"./esign-send-error-3NaWfH3a.js";import"./pdf-C_v4LfPZ.js";import"./esign-validate-CjMO6LoM.js";import"./user-plus--ovXyBFL.js";import"./grip-vertical-s4yjH6Nv.js";import"./hash-DxNfpF52.js";import"./quill.snow-beW58bts.js";import"./FileSaver.min-DdHSAN6d.js";import"./jspdf.es.min-uUv-laI0.js";/**
3 * @license lucide-react v0.563.0 - ISC
4 *
5 * This source code is licensed under the ISC license.
6 * See the LICENSE file in the root directory of this source tree.
7 */const ts=[["line",{x1:"5",x2:"19",y1:"9",y2:"9",key:"1nwqeh"}],["line",{x1:"5",x2:"19",y1:"15",y2:"15",key:"g8yjpy"}]],Ht=Da("equal",ts);function as({leaseId:l,fromVersion:p,toVersion:x,onClose:m}){const[a,q]=r.useState([]),[$,A]=r.useState(null),[E,_]=r.useState(!0),[L,F]=r.useState(null),[f,T]=r.useState(!0),[u,D]=r.useState(null),Y=he();r.useEffect(()=>{S()},[l,p,x]);const S=async()=>{_(!0),F(null);try{const g=await fetch(`/api/leases/${l}/version-diff?from=${p}&to=${x}`,{headers:{"x-api-key":Y}}),h=await g.json();if(!g.ok)throw new Error(h.error||"Failed to load diff");q(h.diff||[]),A(h.stats||null),D(h.to_change_summary||null)}catch(g){F(g.message)}finally{_(!1)}},k=f?a:a.filter(g=>g.type!=="equal");return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",children:e.jsxs("div",{className:"w-full max-w-4xl bg-white dark:bg-slate-800 rounded-xl shadow-xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-5 border-b border-gray-200 dark:border-slate-700",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_e,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Version Comparison"}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:["v",p,e.jsx(Pa,{className:"inline w-3 h-3 mx-1"}),"v",x,u&&e.jsxs("span",{className:"ml-2 text-blue-600 dark:text-blue-400",children:["— ",u]})]})]})]}),e.jsx("button",{onClick:m,className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",children:e.jsx(Ce,{className:"w-5 h-5"})})]}),$&&e.jsxs("div",{className:"flex items-center gap-4 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(rt,{className:"w-3.5 h-3.5 text-green-600"}),e.jsxs("span",{className:"text-green-700 dark:text-green-400 font-medium",children:[$.additions," added"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Qa,{className:"w-3.5 h-3.5 text-red-600"}),e.jsxs("span",{className:"text-red-700 dark:text-red-400 font-medium",children:[$.deletions," removed"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Ht,{className:"w-3.5 h-3.5 text-gray-400"}),e.jsxs("span",{className:"text-gray-500 dark:text-slate-400",children:[$.unchanged," unchanged"]})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-slate-400 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:g=>T(g.target.checked),className:"rounded border-gray-300 text-blue-600 focus:ring-blue-500"}
7),"Show unchanged lines"]})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:E?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(pe,{className:"w-6 h-6 animate-spin text-blue-600"}),e.jsx("span",{className:"ml-2 text-gray-500 dark:text-slate-400",children:"Computing diff..."})]}):L?e.jsx("div",{className:"flex items-center justify-center py-16 text-red-500",children:e.jsx("p",{children:L})}):k.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500 dark:text-slate-400",children:[e.jsx(Ht,{className:"w-10 h-10 mb-3 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"font-medium",children:"No differences found"}),e.jsx("p",{className:"text-sm mt-1",children:"These two versions are identical."})]}):e.jsx("div",{className:"font-mono text-sm",children:k.map((g,h)=>e.jsxs("div",{className:`flex ${g.type==="added"?"bg-green-50 dark:bg-green-900/20 border-l-4 border-green-400":g.type==="removed"?"bg-red-50 dark:bg-red-900/20 border-l-4 border-red-400":"bg-white dark:bg-slate-800 border-l-4 border-transparent"}`,children:[e.jsx("div",{className:"w-10 flex-shrink-0 text-right pr-2 py-0.5 text-gray-400 dark:text-slate-500 select-none text-xs",children:g.lineNumber}),e.jsxs("div",{className:"w-6 flex-shrink-0 text-center py-0.5 
7select-none",children:[g.type==="added"&&e.jsx("span",{className:"text-green-600 font-bold",children:"+"}),g.type==="removed"&&e.jsx("span",{className:"text-red-600 font-bold",children:"−"})]}),e.jsx("div",{className:`flex-1 py-0.5 px-2 break-words ${g.type==="added"?"text-green-800 dark:text-green-300":g.type==="removed"?"text-red-800 dark:text-red-300 line-through":"text-gray-700 dark:text-slate-300"}`,children:g.text})]},h))})}),e.jsx("div",{className:"p-4 border-t border-gray-200 dark:border-slate-700 bg-gray-50 dark:bg-slate-800/50 flex justify-end",children:e.jsx(o,{variant:"outline",onClick:m,children:"Close"})})]})})}function ss({lease:l,onClose:p,onSuccess:x}){const[m,a]=r.useState(""),[q,$]=r.useState(!1),[A,E]=r.useState(String(l.monthly_rent_cents/100)),[_,L]=r.useState(""),[F,f]=r.useState(!1),T=he(),u=l.end_date?Se(l.end_date):null,D=h=>{const N=u||new Date,b=new Date(N);return b.setMonth(b.getMonth()+h),b.toISOString().split("T")[0]},Y=[{label:"+3 months",months:3},{label:"+6 months",months:6},{label:"+12 months",months:12}],S=async()=>{if(!m){alert("Please select a new end date.");return}f(!0);try{const h={new_end_date:m};q&&(h.rent_adjustment_cents=Math.round(parseFloat(A)*100)),_.trim()&&(h.extension_reason=_.trim());const N=await fetch(`/api/leases/${l.lease_id}/extend`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":T},body:JSON.stringify(h)}),b=await N.json();if(!N.ok)throw new Error(b.error||"Failed to extend lease");alert("Lease extended successfully!"),x()}catch(h){alert(h.message)}finally{f(!1)}},g=(()=>{if(!m||!u)return null;const N=new Date(m).getTime()-u.getTime(),b=Math.ceil(N/(1e3*60*60*24)),P=Math.round(b/30);return{days:b,months:P,text:P>0?`~${P} month${P!==1?"s":""}`:`${b} day${b!==1?"s":""}`}})();return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",children:e.jsxs("div",{className:"w-full max-w-lg bg-white dark:bg-slate-800 rounded-xl shadow-xl",children:[e.jsx("div",{className:"p-5 border-b border-gray-200 dark:border-slate-700",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center",children:e.jsx(st,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Extend Lease"}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:[l.property_name||"Property",l.tenant_name?` — ${l.tenant_name}`:""]})]})]}),e.jsx("button",{onClick:p,className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",children:e.jsx(Ce,{className:"w-5 h-5"})})]})}),e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-slate-300 mb-1",children:"Current End Date"}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-gray-50 dark:bg-slate-700 rounded-lg text-sm",children:[e.jsx(we,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-gray-900 dark:text-white font-medium",children:u?u.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"Month-to-Month (no end date)"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-slate-300 mb-1",children:"New End Date"}),e.jsx("input",{type:"date",value:m,onChange:h=>a(h.target.value),min:u?u.toISOString().split("T")[0]:new Date().toISOString().split("T")[0],className:"w-full px-3 py-2 border border-gray-300 dark:border-slate-600 dark:bg-slate-700 dark:text-white rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsx("div",{className:"flex gap-2 mt-2",children:Y.map(h=>e.jsx("button",{onClick:()=>a(D(h.months)),className:"px-3 py-1 text-xs font-medium text-blue-600 dark:text-blue-400 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-full hover:bg-blue-100 dar
7k:hover:bg-blue-900/40 transition-colors",children:h.label},h.months))})]}),g&&g.days>0&&e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg",children:[e.jsx(tt,{className:"w-4 h-4 text-green-600 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-green-800 dark:text-green-300",children:[e.jsxs("span",{className:"font-medium",children:["Extending by ",g.text]}),e.jsxs("span",{className:"text-green-600 dark:text-green-400 ml-2",children:["(",u==null?void 0:u.toLocaleDateString()," ",e.jsx(Ma,{className:"inline w-3 h-3"})," ",new Date(m).toLocaleDateString(),")"]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:q,onChange:h=>$(h.target.checked),className:"rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Adjust rent with extension"})]}),q&&e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-500 dark:text-slate-400 mb-1",children:"Current Rent"}),e.jsxs("div",{className:"flex items-center gap-1 px-3 py-2 bg-gray-50 dark:bg-slate-700 rounded-lg text-sm",children:[e.jsx(de,{className:"w-3.5 h-3.5 text-gray-400"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:[(l.monthly_rent_cents/100).toLocaleString(),"/mo"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-500 dark:text-slate-400 mb-1",children:"New Rent ($/mo)"}),e.jsxs("div",{className:"relative",children:[e.jsx(de,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-gray-400"}),e.jsx("input",{type:"number",value:A,onChange:h=>E(h.target.value),min:"0",step:"50",className:"w-full pl-8 pr-3 py-2 border border-gray-300 dark:border-slate-600 dark:bg-slate-700 dark:text-white rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]})]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-slate-300 mb-1",children:["Extension Reason ",e.jsx("span",{className:"text-gray-400 font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:_,onChange:h=>L(h.target.value),placeholder:"e.g., Tenant requested 6-month extension, mutually agreed terms",rows:2,className:"w-full px-3 py-2 border border-gray-300 dark:border-slate-600 dark:bg-slate-700 dark:text-white rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"})]})]}),e.jsxs("div",{className:"p-5 border-t border-gray-200 dark:border-slate-700 bg-gray-50 dark:bg-slate-800/50 flex justify-end gap-3 rounded-b-xl",children:[e.jsx(o,{variant:"outline",onClick:p,children:"Cancel"}),e.jsx(o,{variant:"primary",loading:F,onClick:S,icon:e.jsx(st,{className:"w-4 h-4"}),children:"Extend Lease"})]})]})})}const Xe={housing_authority:"Housing authority",government:"Government agency",employer:"Employer",family:"Family",nonprofit:"Non-profit",other:"Other"},Q=l=>`$${(l/100).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`,Ze=l=>Math.round(parseFloat(l||"0")*100)||0;function rs({leaseId:l,contractRentCents:p,canEdit:x}){const m=Jt(),a=he(),[q,$]=r.useState(!0),[A,E]=r.useState(!1),[_,L]=r.useState(!1),[F,f]=r.useState([]),[T,u]=r.useState([]),[D,Y]=r.useState([]),[S,k]=r.useState(!1),[g,h]=r.useState(""),[N,b]=r.useState("housing_authority"),[P,ee]=r.useState(!1),re=async()=>{$(!0);try{const[i,c]=await Promise.all([fetch(`/api/leases/${l}/rent-shares`,{headers:{"x-api-key":a}}),fetch("/api/billing/payers",{headers:{"x-api-key":a}})]),C=await i.json(),K=await c.json();K.ok&&f(K.payers||[]),C.ok&&(Y(C.shares||[]),u((C.shares||[]).map((Z,ye)=>({key:`r${ye}`,payer_kind:Z.payer_kind,payer_id:Z.payer_id,dollars:(Number(Z.amount_cents)/100).toFixed(2)}))))}catch{}finally{$(!1)}};r.useEffect(()=>{re()},[l]);const te=()=>{T.length===0&&u([{key:"r0",payer_kind:"tenant",payer_id:null,dollars:(p/100).toFixed(2)}]),L(!0)},ae=()=>{u(i=>[...i,{key:`r${Date.now()}`,payer_kind:"payer",payer_id:null,dollars:"0.00"}])},B=(i,c)=>u(C=>C.map(K=>K.key===i?{...K,...c}:K)),ne=i=>u(c=>c.filter(C=>C.key!==i)),M=T.reduce((i,c)=>i+Ze(c.dollars),0),G=M===p,U=T.filter(i=>i.payer_kind==="tenant").reduce((i,c)=>i+Ze(c.dollars),0),ce=async()=>
7{if(g.trim()){ee(!0);try{const c=await(await fetch("/api/billing/payers",{method:"POST",headers:{"Content-Type":"application/json","x-api-key":a},body:JSON.stringify({name:g.trim(),payer_type:N})})).json();c.ok?(f(C=>[...C,{payer_id:c.payer_id,name:c.name,payer_type:c.payer_type}]),h(""),k(!1),m.success(`Payer "${c.name}" added`)):m.error(c.error||"Could not add payer")}catch(i){m.error(i.message||"Could not add payer")}finally{ee(!1)}}},$e=async()=>{E(!0);try{const c=await(await fetch(`/api/leases/${l}/rent-shares`,{method:"PUT",headers:{"Content-Type":"application/json","x-api-key":a},body:JSON.stringify({shares:T.map(C=>({payer_kind:C.payer_kind,payer_id:C.payer_id,amount_cents:Ze(C.dollars)}))})})).json();c.ok?(c.backfill_failed?m.error(c.message||"Rent split saved, but not applied to open invoices"):m.success(c.message||"Rent split saved"),L(!1),await re()):m.error(c.error||"Could not save the split")}catch(i){m.error(i.message||"Could not save the split")}finally{E(!1)}},ue=async()=>{u([]),E(!0);try{const c=await(await fetch(`/api/leases/${l}/rent-shares`,{method:"PUT",headers:{"Content-Type":"application/json","x-api-key":a},body:JSON.stringify({shares:[]})})).json();c.ok?(m.success("Split cleared — the tenant owes the full rent"),L(!1),await re()):m.error(c.error||"Could not clear the split")}finally{E(!1)}},le=i=>{var c;return((c=F.find(C=>C.payer_id===i))==null?void 0:c.name)||"Unknown payer"};return e.jsxs(j,{children:[e.jsx(W,{children:e.jsx(X,{children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4 text-blue-600"}),"Who pays the rent"]})})}),e.jsxs("div",{className:"p-6 pt-0",children:[e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-lg border border-blue-200 bg-blue-50 p-3 dark:border-blue-900 dark:bg-blue-950/40",children:[e.jsx(za,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-blue-600"}),e.jsxs("p",{className:"text-xs text-blue-900 dark:text-blue-200",children:["This does ",e.jsx("strong",{children:"not"})," change the rent. The lease stays at"," ",e.jsxs("strong",{children:[Q(p),"/mo"]})," and the invoice still bills the full amount — this only records who is responsible for which part of it. The tenant sees and pays only their portion in the portal."]})]}),q?e.jsx("p",{className:"text-sm text-gray-500",children:"Loading…"}):_?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:T.map(i=>e.jsxs("div",{className:"flex items-center gap-2",children:[i.payer_kind==="tenant"?e.jsx("span",{className:"flex-1 rounded-lg border border-gray-200 px-3 py-2 text-sm text-gray-700 dark:border-slate-700 dark:text-slate-300",children:"Tenant's portion"}):e.jsxs("select",{value:i.payer_id||"",onChange:c=>B(i.key,{payer_id:c.target.value||null}),className:"flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-800",children:[e.jsx("option",{value:"",children:"Select a payer…"}),F.map(c=>e.jsxs("option",{value:c.payer_id,children:[c.name," — ",Xe[c.payer_type]||c.payer_type]},c.payer_id))]}),e.jsxs("div",{className:"relative w-36",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-400",children:"$"}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:i.dollars,onChange:c=>B(i.key,{dollars:c.target.value}),className:"w-full rounded-lg border border-gray-300 py-2 pl-7 pr-3 text-sm dark:border-slate-600 dark:bg-slate-800"})]}),i.payer_kind==="payer"&&e.jsx("button",{onClick:()=>ne(i.key),className:"rounded p-2 text-gray-400 hover:bg-gray-100 hover:text-red-600 dark:hover:bg-slate-700","aria-label":"Remove",children:e.jsx(Ba,{className:"h-4 w-4"})})]},i.key))}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(o,{variant:"outline",size:"sm",icon:e.jsx(rt,{className:"h-4 w-4"}),onClick:ae,children:"Add a payer"}),!S&&e.jsx("button",{onClick:()=>k(!0),className:"text-xs text-blue-600 hover:underline",children:"Register a new payer"})]}),S&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-2 rounded-lg border border-gray-200 bg-gray-50 p-3 dark:border-slate-700 dark:bg-slate-800/50",children:[e.jsxs("div",{className:"min-w-[180px] flex-1",children:[e.jsx("label",{className:"mb-1 block text-xs text-gray-600 dark:text-slate-400",children:"Payer name"}),e.jsx("input",{value:g,onChange:i=>h(i.target.value),placeholder:"e.g. Syracuse Housing Authority",className:"w-full rounded-lg border border-gray-300 px-3 py-2 text-sm dark:border-slate-600 dar
7k:bg-slate-800"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-gray-600 dark:text-slate-400",children:"Type"}),e.jsx("select",{value:N,onChange:i=>b(i.target.value),className:"rounded-lg border border-gray-300 px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-800",children:Object.entries(Xe).map(([i,c])=>e.jsx("option",{value:i,children:c},i))})]}),e.jsx(o,{variant:"primary",size:"sm",loading:P,onClick:ce,children:"Add"}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>k(!1),children:"Cancel"})]}),e.jsxs("div",{className:`mt-4 flex items-center justify-between rounded-lg border px-3 py-2 text-sm ${G?"border-green-200 bg-green-50 text-green-800 dark:border-green-900 dark:bg-green-950/40 dark:text-green-300":"border-amber-300 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-200"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[!G&&e.jsx(nt,{className:"h-4 w-4"}),"Portions total ",Q(M)," of ",Q(p)]}),!G&&e.jsx("span",{className:"font-medium",children:M<p?`${Q(p-M)} unassigned`:`${Q(M-p)} over`})]}),G&&e.jsxs("p",{className:"mt-2 text-xs text-gray-500 dark:text-slate-400",children:["The tenant will see ",e.jsx("strong",{children:Q(U)})," in their portal."]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(o,{variant:"primary",size:"sm",loading:A,disabled:!G||A,onClick:$e,children:"Save split"}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{L(!1),re()},children:"Cancel"}),D.length>0&&e.jsx(o,{variant:"outline",size:"sm",onClick:ue,disabled:A,children:"Clear split"})]})]}):e.jsxs(e.Fragment,{children:[D.length===0?e.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:["No split — the tenant is responsible for the full ",Q(p),"."]}):e.jsx("div",{className:"space-y-2",children:D.map(i=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-gray-200 px-3 py-2 dark:border-slate-700",children:[e.jsx("span",{className:"flex items-center gap-2 text-sm text-gray-800 dark:text-slate-200",children:i.payer_kind==="tenant"?e.jsxs(e.Fragment,{children:[e.jsx(Mt,{className:"h-4 w-4 text-gray-400"})," Tenant"]}):e.jsxs(e.Fragment,{children:[e.jsx(Oa,{className:"h-4 w-4 text-gray-400"})," ",i.payer_name||le(i.payer_id),i.payer_type&&e.jsxs("span",{className:"text-xs text-gray-400",children:["(",Xe[i.payer_type]||i.payer_type,")"]})]})}),e.jsxs("span",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[Q(Number(i.amount_cents)),"/mo"]})]},i.share_id))}),x&&e.jsx("div",{className:"mt-4",children:e.jsx(o,{variant:"outline",size:"sm",onClick:te,children:D.length===0?"Set up a split":"Edit split"})})]})]})]})}const ns={NY:450};function Qe(l,p){if(!l||p!=="amenity")return"";const x=ns[l.toUpperCase().trim()];return x?String(x/100):""}const et=[{value:"rent",label:"Rent"},{value:"parking",label:"Parking"},{value:"utilities",label:"Utilities"},{value:"pet_fee",label:"Pet Fee"},{value:"storage",label:"Storage"},{value:"laundry",label:"Laundry"},{value:"amenity",label:"Amenity"},{value:"other",label:"Other"}];function Os({leaseId:l,onBack:p}){var Et,Rt,At,Ft,Dt,Pt;const x=Jt(),m=Ua(),[a,q]=r.useState(null),[$,A]=r.useState([]),[E,_]=r.useState([]),[L,F]=r.useState([]),[f,T]=r.useState(null),[u,D]=r.useState([]),[Y,S]=r.useState(!0),[k,g]=r.useState("overview"),[h,N]=r.useState(!1),[b,P]=r.useState(!1),[ee,re]=r.useState(!1),[te,ae]=r.useState(!1),[B,ne]=r.useState([]),[M,G]=r.useState(!1),[U,ce]=r.useState(null),[$e,ue]=r.useState(!1),[le,i]=r.useState("parking"),[c,C]=r.useState(""),[K,Z]=r.useState("monthly"),[ye,oe]=r.useState(""),[lt,Le]=r.useState("1"),[it,Te]=r.useState(!0),[dt,Ee]=r.useState(""),[ct,Re]=r.useState(""),[fe,je]=r.useState(""),[ot,Ae]=r.useState(!1),[Yt,Fe]=r.useState(!1),[Gt,xt]=r.useState(!1),[Kt,De]=r.useState(!1),[Wt,mt]=r.useState(!1),[Xt,Pe]=r.useState(!1),[pt,Zt]=r.useState([]),[Qt,ea]=r.useState(!1),[ta,ht]=r.useState(null),[aa,be]=r.useState(!1),[H,ve]=r.useState({full_name:"",email:"",phone:""}),[ke,gt]=r.useState(!1),[Me,sa]=r.useState([]),[ra,ut]=r.useState(!1),[na,ze]=r.useState(!1),[Oe,Be]=r.useState(""),[la,yt]=r.useState(!1),[ft,ia]=r.useState({from:1,to:2}),[da,jt]=r.useState(null),[ca,Ue]=r.useState(!1),[J,oa]=r.useState(null),[xa,bt]=r.useState(!1),[vt,kt]=r.useState(!1),[R,ma]=r.useState(null),[pa,Nt]=r.useState(!1),[xe,ha]=r.useState([]),[wt,_t]=r.useState(!1),[St,ga]=r.useState(new Set),d=he();r.useEffect(()=>{V(),Ne(),Ct(),Ve(),Ie(),$t(),Lt(),qe(),ka(),Na(),_a()},[l]),r.useEffect(()=>{a!=null&&a.end_date&&wa(a.end_date)},[a==null?void 0:a.end_date]);const V=async()=>{var t;if(d){S(!0);try{const n=await(await fetch(`/api/leases/${l}`,{headers:{"x-api-key":d}})).json();if(n.ok&&n.lease){const y=(t=(await(await fetch("/api/leases/recent?limit=200",{headers:{"x-api-key":d}})).json()).leases)==null?void 0:t.find(Fa=>Fa.lease_id===l);q({...n.lease,property_name:(y==null?void 0:y.property_name)||n.lease.property_name,property_type:(y==null?void 0:y.property_type)||n.lease.property_type,property_address:(y==null?void 0:y.property_address)||n.lease.property_address,property_state:(y==null?void 0:y.property_state)??n.lease.property_state,tenant_name:(y==null?void 0:y.tenant_name)||n.lease.tenant_name,tenant_email:(y==null?void 0:y.tenant_email)||n.lease.tenant_email,has_content:(y==null?void 0:y.has_content)||n.lease.has_content})}}catch{}finally{S(!1)}}},Ne=async()=>
7{if(d)try{const s=await(await fetch(`/api/leases/${l}/amend`,{headers:{"x-api-key":d}})).json();s.ok&&A(s.amendments||[])}catch{}},ua=async()=>{if(!(!d||!l)){if(!H.full_name.trim()||!H.email.trim()){x.warning("Full name and email are required");return}gt(!0);try{const t=await fetch(`/api/leases/${l}/add-tenant`,{method:"POST",headers:{"x-api-key":d,"Content-Type":"application/json"},body:JSON.stringify(H)}),s=await t.json();if(!t.ok)throw new Error(s.error||"Failed to add co-tenant");be(!1),ve({full_name:"",email:"",phone:""}),await V()}catch(t){x.error(`Failed to add co-tenant: ${t.message}`)}finally{gt(!1)}}},ya=async(t,s)=>{if(!(!d||!l)&&await m({title:`Make ${s} the primary tenant?`,message:"The current primary tenant will be demoted to co-tenant. The lease itself stays in place.",confirmLabel:"Promote",variant:"primary"}))try{const n=await fetch(`/api/leases/${l}/promote-tenant`,{method:"POST",headers:{"x-api-key":d,"Content-Type":"application/json"},body:JSON.stringify({tenant_id:t})}),w=await n.json();if(!n.ok)throw new Error(w.error||"Failed to promote");await V()}catch(n){x.error(`Failed to promote: ${n.message}`)}},fa=async(t,s)=>{if(!(!d||!l)&&await m({title:`Remove ${s}?`,message:"They will lose portal access for this lease. Their historical activity is preserved.",confirmLabel:"Remove",variant:"destructive"}))try{const n=await fetch(`/api/leases/${l}/add-tenant?tenant_id=${t}`,{method:"DELETE",headers:{"x-api-key":d}}),w=await n.json();if(!n.ok)throw new Error(w.error||"Failed to remove co-tenant");await V()}catch(n){x.error(`Failed to remove: ${n.message}`)}},Ct=async()=>{if(d)try{const s=await(await fetch(`/api/leases/${l}/clauses`,{headers:{"x-api-key":d}})).json();s.ok&&_(s.clauses||[])}catch{}},Ve=async()=>{if(d)try{const s=await(await fetch(`/api/leases/${l}/escalations`,{headers:{"x-api-key":d}})).json();s.ok&&F(s.escalations||[])}catch{}},Ie=async()=>{if(d)try{const s=await(await fetch(`/api/leases/${l}/recurring-charges`,{headers:{"x-api-key":d}})).json();s.ok&&ne(s.charges||[])}catch{}},ja=async t=>{if(d){ue(!0);try{const s=!!U,w=await(await fetch(`/api/leases/${l}/recurring-charges`,{method:s?"PUT":"POST",headers:{"Content-Type":"application/json","x-api-key":d},body:JSON.stringify(s?{charge_id:U.charge_id,...t}:t)})).json();w.ok?(G(!1),ce(null),Ie()):x.error(w.error||"Failed to save charge")}catch{x.error("Failed to save charge")}finally{ue(!1)}}},ba=async t=>{if(d&&await m({title:"Deactivate this charge?",message:"It will stop generating invoices going forward. Existing invoices are unaffected.",confirmLabel:"Deactivate",variant:"destructive"}))try{const n=await(await fetch(`/api/leases/${l}/recurring-charges?charge_id=${t}`,{method:"DELETE",headers:{"x-api-key":d}})).json();n.ok?Ie():x.error(n.error||"Failed to deactivate")}catch{x.error("Failed to deactivate charge")}},$t=async()=>{if(d)try{const s=await(await fetch(`/api/leases/${l}/late-fee-rules`,{headers:{"x-api-key":d}})).json();s.ok&&T(s.rule||null)}catch{}},Lt=async()=>{if(d)try{const s=await(await fetch(`/api/leases/${l}/inspections`,{headers:{"x-api-key":d}})).json();s.ok&&D(s.inspections||[])}catch{}},qe=async()=>{if(d){ut(!0);try{const s=await(await fetch(`/api/leases/${l}/versions`,{headers:{"x-api-key":d}})).json();s.ok&&sa(s.versions||[])}catch{}finally{ut(!1)}}},He=async()=>{var t;if(d)try{const n=await(await fetch(`/api/leases/${l}?include_content=true`,{headers:{"x-api-key":d}})).json();if(n.ok&&n.content)Be(n.content);else{const se=await(await fetch(`/api/leases/${l}/versions?version=${(a==null?void 0:a.current_version)||1}`,{headers:{"x-api-key":d}})).json();se.ok&&((t=se.version)!=null&&t.html_content)?Be(se.version.html_content):Be("<p>Unable to load lease content. You can still make edits.</p>")}ze(!0)}catch{x.error("Failed to load lease content for editing.")}},va=async t=>{if(d&&await m({title:`Restore version ${t}?`,message:`Creates a new version (v${((a==null?void 0:a.current_version)||1)+1}) with the content from v${t}. Earlier versions are preserved.`,confirmLabel:"Restore",variant:"primary"})){jt(t);try{const n=await(await fetch(`/api/leases/${l}/versions`,{method:"POST",headers:{"x-api-key":d,"Content-Type":"application/json"},body:JSON.stringify({action:"restore",version_number:t})})).json();n.ok?(x.success(`Restored! Created v${n.new_version} from v${t}.`),qe(),V()):x.error(n.error||"Failed to restore version")}catch{x.error("Failed to restore version")}finally{jt(null)}}},ka=async()=>
7{if(d)try{const s=await(await fetch(`/api/leases/${l}/compare`,{headers:{"x-api-key":d}})).json();ea(s.ok&&s.renewal)}catch{}},Na=async()=>{if(d){bt(!0);try{const t=await fetch(`/api/leases/risk-score?lease_id=${l}`,{headers:{"x-api-key":d}}),s=await t.json();t.ok&&(s!=null&&s.risk_score)&&oa(s.risk_score)}catch{}finally{bt(!1)}}},wa=async t=>{if(!d||!t)return;const s=Se(t);if(!s)return;const n=new Date;if(!(Math.ceil((s.getTime()-n.getTime())/(1e3*60*60*24))>90)){Nt(!0);try{const se=await fetch(`/api/leases/renewal-recommendation?lease_id=${l}`,{headers:{"x-api-key":d}}),y=await se.json();se.ok&&(y!=null&&y.recommendation)&&ma(y.recommendation)}catch{}finally{Nt(!1)}}},_a=async()=>{if(d){_t(!0);try{const t=await fetch(`/api/leases/amendment-suggestions?lease_id=${l}`,{headers:{"x-api-key":d}}),s=await t.json();t.ok&&ha(s.suggestions||s||[])}catch{}finally{_t(!1)}}},Sa=async t=>{if(d){ht(t);try{const n=await(await fetch(`/api/leases/${l}/escalations`,{method:"PUT",headers:{"x-api-key":d,"content-type":"application/json"},body:JSON.stringify({escalation_id:t,action:"apply"})})).json();n.ok?(x.success(`Rent updated: $${(n.previous_rent_cents/100).toLocaleString()} → $${(n.new_rent_cents/100).toLocaleString()}`),Ve(),V(),Ne()):x.error(n.error||"Failed to apply escalation")}catch{x.error("Failed to apply escalation")}finally{ht(null)}}},Ca=async t=>{if(!(!d||t.length===0))try{(await(await fetch(`/api/leases/${l}/clauses`,{method:"POST",headers:{"x-api-key":d,"content-type":"application/json"},body:JSON.stringify({clause_ids:t})})).json()).ok&&(Ct(),Pe(!1))}catch{}},$a=async()=>{if(d)try{const s=await(await fetch("/api/leases/clause-library",{headers:{"x-api-key":d}})).json();s.ok&&Zt(s.clauses||[])}catch{}},Tt=t=>{const n={active:{variant:"success",label:"Active"},signed:{variant:"success",label:"Signed"},sent:{variant:"info",label:"Sent for Signature"},pending_signature:{variant:"info",label:"Pending Signature"},draft:{variant:"default",label:"Draft"},legal_review:{variant:"warning",label:"Legal Review"},ops_review:{variant:"warning",label:"Ops Review"},expired:{variant:"warning",label:"Expired"},terminated:{variant:"danger",label:"Terminated"}}[t]||{variant:"default",label:t};return e.jsx(v,{variant:n.variant,children:n.label})},La=t=>{const n={rent_change:{variant:"warning",label:"Rent Change"},term_extension:{variant:"info",label:"Term Extension"},clause_modification:{variant:"default",label:"Clause Modification"},rent_escalation:{variant:"warning",label:"Rent Escalation"},other:{variant:"default",label:"Other"}}[t]||{variant:"default",label:t};return e.jsx(v,{variant:n.variant,children:n.label})},Ta=t=>t==="applied"?e.jsx(v,{variant:"success",children:"Applied"}):t==="sent"?e.jsx(v,{variant:"info",children:"Sent for Signature"}):t==="signed"?e.jsx(v,{variant:"success",children:"Signed"}):t==="rejected"?e.jsx(v,{variant:"danger",children:"Rejected"}):e.jsx(v,{variant:"default",children:"Draft"}),Ea=()=>{if(!(a!=null&&a.end_date))return null;const t=Se(a.end_date);if(!t)return null;const s=new Date;return Math.ceil((t.getTime()-s.getTime())/(1e3*60*60*24))},me=L.find(t=>!t.applied),z=u.find(t=>t.inspection_type==="move_in"),O=u.find(t=>t.inspection_type==="move_out");if(Y)return e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-brand-navy"})});if(!a)return e.jsxs("div",{className:"p-6",children:[e.jsx(o,{variant:"outline",onClick:p,icon:e.jsx(zt,{className:"w-4 h-4"}),children:"Back to Leases"}),e.jsx("div",{className:"mt-6 text-center text-gray-500 dark:text-slate-400",children:"Lease not found."})]});const I=Ea(),Je=a.status==="active"||a.status==="signed",Ra=(a.status==="draft"||a.status==="pending")&&a.has_content,Ye=!!a.envelope_id,Aa=[{id:"overview",label:"Overview"},{id:"versions",label:`Versions (${Me.length||a.current_version||1})`},{id:"amendments",label:`Amendments (${$.length})`},...Ye?[{id:"signing",label:"Signing Status"}]:[],{id:"clauses",label:`Clauses (${E.length})`},{id:"escalations",label:`Escalations (${L.length})`},...a.status==="active"?[{id:"charges",label:`Charges (${B.filter(t=>t.is_active).length})`}]:[],{id:"inspections",label:`Inspections (${u.length})`}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(o,{variant:"outline",size:"sm",onClick:p,icon:e.jsx(zt,{className:"w-4 h-4"}),children:"Back to Leases"}),e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:a.property_name||`Lease #${a.lease_id.substring(0,8)}`}),Tt(a.status),xa?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-gray-100 dark:bg-slate-700 text-gray-500 dark:text-slate-400",children:[e.jsx(pe,{className:"w-3 h-3 animate-spin"})," Risk..."]}):J?e.jsxs("button",{onClick:()=>kt(!vt),className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold cursor-pointer transition-colors ${(J.overall_score??0)<=30?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":(J.overall_score??0)<=60?"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400":(J.overall_score??0)<=80?"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400":"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"}`,children:[e.jsx(at,{className:"w-3 h-3"}),"Risk: ",J.overall_score??0,J.risk_level&&e.jsxs("span",{className:"capitalize",children:[" (",J.risk_level,")"]})]}):null]}),e.jsxs("p",{className:"text-gray-500 dark:text-slate-400 mt-1",children:[a.tenant_name&&e.jsxs("span",{children:["Tenant: ",a.tenant_name]}),a.tenant_email&&e.jsxs("span",{className:"ml-2 text-sm",children:["(",a.tenant_email,")"]})]}),e.jsx(xs,{leaseId:a.lease_id,status:a.status,legalReviewedBy:a.legal_reviewed_by,legalReviewedAt:a.legal_reviewed_at,legalN
7otes:a.legal_review_notes,opsReviewedBy:a.ops_reviewed_by,opsReviewedAt:a.ops_reviewed_at,opsNotes:a.ops_review_notes,onTransition:()=>window.location.reload()})]}),e.jsxs("div",{className:"flex gap-2",children:[!!a.has_content&&e.jsx(o,{variant:"outline",size:"sm",onClick:He,icon:e.jsx(It,{className:"w-4 h-4"}),children:"Edit Lease"}),Ra&&e.jsx(o,{variant:"primary",size:"sm",onClick:He,icon:e.jsx(Va,{className:"w-4 h-4"}),children:"Send for Signature"}),Je&&e.jsx(o,{variant:"outline",size:"sm",onClick:()=>Ue(!0),icon:e.jsx(st,{className:"w-4 h-4"}),children:"Extend"}),Je&&e.jsx(o,{variant:"outline",size:"sm",onClick:()=>N(!0),icon:e.jsx(qt,{className:"w-4 h-4"}),children:"Amend"})]})]}),Qt&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-800 dark:text-blue-300",children:[e.jsx(_e,{className:"w-4 h-4"}),e.jsxs("span",{children:[e.jsx("strong",{children:"Renewal offer pending"})," — Compare current terms with the proposed renewal."]})]}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>xt(!0),children:"Compare Terms"})]}),I!==null&&I<=60&&I>=0&&e.jsxs("div",{className:`flex items-center gap-2 p-3 rounded-lg text-sm ${I<=30?"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-800 dark:text-red-300":"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 text-amber-800 dark:text-amber-300"}`,children:[e.jsx(nt,{className:"w-4 h-4 flex-shrink-0"}),e.jsxs("span",{children:["This lease expires in ",e.jsxs("strong",{children:[I," days"]})," (",new Date(a.end_date).toLocaleDateString(),").",I<=30&&" Consider extending or renewing this lease."]})]}),vt&&J&&e.jsx(j,{className:"border-blue-200 dark:border-blue-800",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-white",children:[e.jsx(at,{className:"w-4 h-4 text-blue-600"})," Risk Score Breakdown"]}),e.jsx("button",{onClick:()=>kt(!1),children:e.jsx(Ce,{className:"w-4 h-4 text-gray-400 dark:text-slate-500"})})]}),Object.entries(J.factors||{}).map(([t,s],n)=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-700 dark:text-slate-300 font-medium capitalize",children:t.replace(/_/g," ")}),e.jsx("span",{className:"text-gray-500 dark:text-slate-400",children:s.score??0})]}),e.jsx("div",{className:"w-full bg-gray-200 dark:bg-slate-700 rounded-full h-2",children:e.jsx("div",{className:`h-2 rounded-full ${(s.score??0)<=30?"bg-green-500":(s.score??0)<=60?"bg-yellow-500":(s.score??0)<=80?"bg-orange-500":"bg-red-500"}`,style:{width:`${Math.min(s.score??0,100)}%`}})}),s.detail&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400",children:s.detail})]},n)),J.ai_summary&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 italic border-t border-gray-100 dark:border-slate-700 pt-3",children:J.ai_summary})]})}),R&&e.jsx(j,{className:"border-purple-200 dark:border-purple-800 bg-purple-50/30 dark:bg-purple-900/10",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-purple-800 dark:text-purple-300",children:[e.jsx(Ia,{className:"w-4 h-4"})," AI Renewal Recommendation"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Recommended Rent"}),e.jsxs("p",{className:"text-lg font-semibold text-gray-900 dark:text-white mt-1",children:["$",(Number(R.recommended_rent_cents??0)/100).toLocaleString(),"/mo"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Term"}
7),e.jsxs("p",{className:"text-sm font-medium mt-1 dark:text-white",children:[R.recommended_term_months||"--"," months"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Rent Change"}),e.jsxs("p",{className:`text-sm font-medium mt-1 ${Number(R.rent_change_pct??0)>0?"text-red-600":"text-green-600"}`,children:[Number(R.rent_change_pct??0)>0?"+":"",Number(R.rent_change_pct??0).toFixed(1),"%"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Churn Probability"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 bg-gray-200 dark:bg-slate-700 rounded-full h-2",children:e.jsx("div",{className:`h-2 rounded-full ${Number(R.churn_probability??0)<=.3?"bg-green-500":Number(R.churn_probability??0)<=.6?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(Number(R.churn_probability??0)*100,100)}%`}})}),e.jsxs("span",{className:"text-xs font-medium dark:text-white",children:[(Number(R.churn_probability??0)*100).toFixed(0),"%"]})]})]})]}),(R.incentives||[]).length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:(R.incentives||[]).map((t,s)=>e.jsx("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium bg-purple-100 text-purple-700 dark:bg-purple-800/40 dark:text-purple-300",children:typeof t=="object"?t.description||t.type||JSON.stringify(t):String(t)},s))}),R.reasoning&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400",children:R.reasoning}),e.jsx(o,{variant:"secondary",size:"sm",children:"Create Renewal Offer"})]})}),pa&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 dark:text-slate-400",children:[e.jsx(pe,{className:"w-4 h-4 animate-spin"})," Loading renewal recommendation..."]}),e.jsx("div",{className:"border-b border-gray-200 dark:border-slate-700 overflow-x-auto",children:e.jsx("nav",{className:"flex gap-6",children:Aa.map(t=>e.jsx("button",{onClick:()=>g(t.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${k===t.id?"border-brand-navy text-brand-navy dark:text-blue-400 dark:border-blue-400":"border-transparent text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-slate-300"}`,children:t.label},t.id))})}),k==="overview"&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(j,{children:[e.jsx(W,{children:e.jsx(X,{children:"Lease Details"})}),e.jsx("div",{className:"p-6 pt-0 space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Lease Type"}),e.jsx("p",{className:"text-sm font-medium mt-1 capitalize dark:text-white",children:((Et=a.lease_type)==null?void 0:Et.replace(/_/g," "))||"N/A"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Status"}),e.jsx("div",{className:"mt-1",children:Tt(a.status)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Start Date"}),e.jsxs("p",{className:"text-sm font-medium mt-1 flex items-center gap-1 dark:text-white",children:[e.jsx(we,{className:"w-3.5 h-3.5 text-gray-400"}),ie(a.start_date)]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"End Date"}),e.jsxs("p",{className:"text-sm font-medium mt-1 flex items-center gap-1 dark:text-white",children:[e.jsx(we,{className:"w-3.5 h-3.5 text-gray-400"}),a.end_date?ie(a.end_date):"Month-to-Month"]})]})]})})]}),e.jsxs(j,{children:[e.jsx(W,{children:e.jsx(X,{children:"Financial Details"})}),e.jsxs("div",{className:"p-6 pt-0 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Monthly Rent"}),e.jsxs("p",{className:"text-lg font-semibold text-gray-900 dark:text-white mt-1 flex items-center gap-1",children:[e.jsx(de,{className:"w-4 h-4 text-green-600"}
7),"$",(a.monthly_rent_cents/100).toLocaleString(),"/mo"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Annual Rent"}),e.jsxs("p",{className:"text-sm font-medium mt-1 dark:text-white",children:["$",(a.monthly_rent_cents*12/100).toLocaleString(),"/yr"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Security Deposit"}),e.jsxs("p",{className:"text-sm font-medium mt-1 dark:text-white",children:["$",(a.security_deposit_cents/100).toLocaleString()]})]}),I!==null&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Days Remaining"}),e.jsx("p",{className:`text-sm font-medium mt-1 ${I<=30?"text-amber-600":"text-gray-900 dark:text-white"}`,children:I>0?`${I} days`:I===0?"Expires today":`Expired ${Math.abs(I)} days ago`})]})]}),me&&e.jsx("div",{className:"pt-3 border-t border-gray-100 dark:border-slate-700",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ge,{className:"w-4 h-4 text-blue-500"}),e.jsxs("span",{className:"text-gray-600 dark:text-slate-400",children:["Next escalation: ",ie(me.effective_date)," ","(",me.escalation_type==="percentage"?`+${(me.escalation_value/100).toFixed(1)}%`:`+$${(me.escalation_value/100).toLocaleString()}`,")"]})]})})]})]}),e.jsx(rs,{leaseId:l,contractRentCents:a.monthly_rent_cents,canEdit:a.status==="active"||a.status==="signed"}),e.jsxs(j,{children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx(X,{children:"Late Fee Policy"}),e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>Fe(!0),children:f?"Edit":"Configure"})]})}),e.jsxs("div",{className:"p-6 pt-0",children:[f?e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Grace Period"}),e.jsxs("p",{className:"font-medium dark:text-white mt-1",children:[f.grace_period_days," days"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Fee"}),e.jsx("p",{className:"font-medium dark:text-white mt-1",children:f.fee_type==="flat"?`$${((f.fee_amount_cents||0)/100).toLocaleString()} flat`:`${((f.fee_percentage||0)/100).toFixed(1)}% of invoice`})]}),!!f.max_fee_cents&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Max Cap"}),e.jsxs("p",{className:"font-medium dark:text-white mt-1",children:["$",(f.max_fee_cents/100).toLocaleString()]})]})]}):e.jsxs("div",{className:"text-center py-4 text-gray-500 dark:text-slate-400",children:[e.jsx(qa,{className:"w-8 h-8 mx-auto mb-2 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"text-sm",children:"No late fee policy configured"}),e.jsx("p",{className:"text-xs mt-1",children:"Set up automatic late fees for overdue payments"})]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-3 pt-3 border-t border-gray-100 dark:border-slate-700",children:["Property/org-level late-fee policies now apply when no lease rule is set — manage them in"," ",e.jsx("button",{onClick:()=>window.dispatchEvent(new CustomEvent("ream-navigate",{detail:{page:"late-fees"}})),className:"text-brand-navy dark:text-brand-gold hover:underline font-medium",children:"Late Fees"}),"."]})]})]}),e.jsxs(j,{children:[e.jsx(W,{children:e.jsx(X,{children:"Property & Tenant"})}),e.jsxs("div",{className:"p-6 pt-0 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ha,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium dark:text-white",children:a.property_name||a.property_id})]}),a.property_address&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 ml-6",children:a.property_address}),e.jsxs("div",{className:"border-t border-gray-100 dark:border-slate-700 pt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-slate-400 tracking-wide",children:["Tenants (",((Rt=a.tenants)==null?void 0:Rt.length)||0||(a.tenant_name?1:0),")",["active","signed","sent","terminated","expired"].includes(String(a.status||"").toLowerCase())&&e.jsx("span",{className:"ml-2 normal-case text-[10px] font-normal text-gray-400",children:"(locked — signed lease)"})]}),!["active","signed","sent","terminated","expired"].includes(String(a.status||"").toLowerCase())&&e.jsx("button",{onClick:()=>be(!0),className:"text-xs text-brand-navy dark:text-brand-gold hover:underline font-medium",children:"+ Add Co-Tenant"})]}),a.tenants&&a.tenants.length>0?e.jsx("div",{className:"space-y-2",children:a.tenants.map(t=>e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ot,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium dark:text-white",children:t.full_name||t.tenant_id}),(t.is_primary===1||t.is_primary===!0)&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-navy
7/10 text-brand-navy dark:bg-brand-gold/10 dark:text-brand-gold rounded font-semibold",children:"PRIMARY"})]}),t.email&&e.jsxs("div",{className:"flex items-center gap-2 ml-6 mt-1",children:[e.jsx(Bt,{className:"w-3.5 h-3.5 text-gray-400"}),e.jsx("span",{className:"text-sm text-gray-500 dark:text-slate-400",children:t.email})]})]}),!(t.is_primary===1||t.is_primary===!0)&&!["active","signed","sent","terminated","expired"].includes(String(a.status||"").toLowerCase())&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>ya(t.tenant_id,t.full_name),className:"text-xs text-brand-navy hover:underline",title:"Make this tenant the primary on the lease",children:"Make primary"}),e.jsx("button",{onClick:()=>fa(t.tenant_id,t.full_name),className:"text-xs text-red-600 hover:text-red-700",title:"Remove co-tenant",children:"Remove"})]})]},t.tenant_id))}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ot,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium dark:text-white",children:a.tenant_name||a.tenant_id})]}),a.tenant_email&&e.jsxs("div",{className:"flex items-center gap-2 ml-6 mt-1",children:[e.jsx(Bt,{className:"w-3.5 h-3.5 text-gray-400"}),e.jsx("span",{className:"text-sm text-gray-500 dark:text-slate-400",children:a.tenant_email})]})]})]})]})]}),e.jsxs(j,{className:"lg:col-span-2",children:[e.jsx(W,{children:e.jsx(X,{children:"Document & Signing"})}),e.jsxs("div",{className:"p-6 pt-0",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Signed"}),e.jsx("p",{className:"text-sm font-medium mt-1 flex items-center gap-1 dark:text-white",children:a.signed_at?e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"w-3.5 h-3.5 text-green-500"}),new Date(a.signed_at).toLocaleDateString()]}):e.jsx("span",{className:"text-gray-400 dark:text-slate-500",children:"Not yet signed"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Envelope ID"}),e.jsx("p",{className:"text-sm font-medium mt-1 font-mono dark:text-white",children:a.envelope_id?a.envelope_id.substring(0,12)+"...":"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Document"}),e.jsx("p",{className:"text-sm font-medium mt-1 dark:text-white",children:a.document_url?e.jsxs("button",{onClick:()=>window.open(`/api/leases/${a.lease_id}/download-signed`,"_blank"),className:"text-brand-navy hover:underline flex items-center gap-1 dark:text-blue-400",children:[e.jsx(Ja,{className:"w-3.5 h-3.5"})," Download PDF"]}):e.jsx("span",{className:"text-gray-400 dark:text-slate-500",children:"No document"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 uppercase tracking-wide",children:"Created"}),e.jsxs("p",{className:"text-sm font-medium mt-1 flex items-center gap-1 dark:text-white",children:[e.jsx(tt,{className:"w-3.5 h-3.5 text-gray-400"}),new Date(a.created_at).toLocaleDateString()]})]})]}),Ye&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-100 dark:border-slate-700",children:e.jsx(o,{variant:"secondary",size:"sm",onClick:()=>g("signing"),icon:e.jsx(Ya,{className:"w-4 h-4"}),children:"View Signing Status"})})]})]}),(xe.length>0||wt)&&e.jsxs(j,{className:"lg:col-span-2",children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"w-4 h-4 text-amber-500"}),e.jsx(X,{children:"AI Suggestions"})]})}),e.jsx("div",{className:"p-6 pt-0",children:wt?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-gray-500 dark:text-slate-400",children:[e.jsx(pe,{className:"w-4 h-4 animate-spin"})," Analyzing lease for suggestions..."]}):e.jsxs("div",{className:"space-y-3",children:[(Array.isArray(xe)?xe:[]).filter(t=>!St.has(t.id||t.suggestion_id)).map((t,s)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-gray-200 dark:border-slate-700 bg-gray-50 dark:bg-slate-800/50",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 ${(t.suggestion_type||t.type)==="rent_adju
7stment"?"bg-green-100 dark:bg-green-900/30":(t.suggestion_type||t.type)==="clause_addition"?"bg-blue-100 dark:bg-blue-900/30":(t.suggestion_type||t.type)==="term_change"||(t.suggestion_type||t.type)==="term_extension"?"bg-purple-100 dark:bg-purple-900/30":"bg-gray-100 dark:bg-slate-700"}`,children:e.jsx(Ut,{className:`w-4 h-4 ${(t.suggestion_type||t.type)==="rent_adjustment"?"text-green-600":(t.suggestion_type||t.type)==="clause_addition"?"text-blue-600":(t.suggestion_type||t.type)==="term_change"||(t.suggestion_type||t.type)==="term_extension"?"text-purple-600":"text-gray-500"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:t.title||t.suggestion_type||t.type}),e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold uppercase ${t.priority==="high"||t.priority<=2?"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400":t.priority==="medium"||t.priority<=3?"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400":"bg-gray-100 text-gray-500 dark:bg-slate-700 dark:text-slate-400"}`,children:typeof t.priority=="number"?t.priority<=2?"high":t.priority<=3?"medium":"low":t.priority||"low"})]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400",children:t.description}),t.impact_estimate&&e.jsxs("p",{className:"text-xs text-gray-500 dark:text-slate-500 mt-1",children:["Impact: ",typeof t.impact_estimate=="object"?[t.impact_estimate.monthly_revenue_change?`$${t.impact_estimate.monthly_revenue_change}/mo`:null,t.impact_estimate.risk_reduction?`Risk: ${t.impact_estimate.risk_reduction}`:null,t.impact_estimate.tenant_satisfaction?`Satisfaction: ${t.impact_estimate.tenant_satisfaction}`:null].filter(Boolean).join(" · "):String(t.impact_estimate)]})]}),e.jsx("button",{onClick:()=>ga(n=>new Set([...n,t.id||t.suggestion_id||String(s)])),className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300 flex-shrink-0",children:e.jsx(Ce,{className:"w-4 h-4"})})]},t.id||t.suggestion_id||s)),(Array.isArray(xe)?xe:[]).filter(t=>!St.has(t.id||t.suggestion_id)).length===0&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 text-center py-4",children:"All suggestions dismissed."})]})})]})]}),k==="versions"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Version History"}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400 mt-0.5",children:["Current version: v",a.current_version||1]})]}),!!a.has_content&&e.jsx(o,{variant:"primary",size:"sm",onClick:He,icon:e.jsx(It,{className:"w-4 h-4"}),children:"Edit & Save New Version"})]}),ra?e.jsxs("div",{className:"flex items-center gap-2 py-8 justify-center text-gray-500 dark:text-slate-400",children:[e.jsx(pe,{className:"w-4 h-4 animate-spin"})," Loading versions..."]}):Me.length===0?e.jsx(j,{padding:"lg",children:e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-slate-400",children:[e.jsx(es,{className:"w-10 h-10 mx-auto mb-3 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"font-medium",children:"No version history yet"}),e.jsx("p",{className:"text-sm mt-1",children:"Edit and save the lease to start tracking versions."})]})}):e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-4 top-0 bottom-0 w-0.5 bg-gray-200 dark:bg-slate-700"}),e.jsx("div",{className:"space-y-4",children:Me.map((t,s)=>{var w;const n=t.version_number===(a.current_version||1);return e.jsxs("div",{className:"relative pl-10",children:[e.jsx("div",{className:`absolute left-2.5 top-3 w-3 h-3 rounded-full border-2 ${n?"bg-blue-600 border-blue-600 dark:bg-blue-400 dark:border-blue-400":"bg-white dark:bg-slate-800 border-gray-300 dark:border-slate-600"}`}),e.jsx(j,{padding:"md",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:["Version ",t.version_number]}),n&&e.jsx(v,{variant:"success",children:"Current"}),((w=t.change_summary)==null?void 0:w.includes("Restored from"))&&e.jsx(v,{variant:"info",children:"Restored"})]}),t.change_summary&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400",children:t.change_summary}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-500 dark:text-slate-400",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(tt,{className:"w-3 h-3"}
7),new Date(t.created_at).toLocaleString()]}),t.content_hash&&e.jsx("span",{className:"font-mono text-gray-400 dark:text-slate-500",children:t.content_hash.substring(0,8)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t.version_number>1&&e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>{ia({from:t.version_number-1,to:t.version_number}),yt(!0)},icon:e.jsx(_e,{className:"w-3.5 h-3.5"}),children:"Diff"}),!n&&e.jsx(o,{variant:"outline",size:"sm",loading:da===t.version_number,onClick:()=>va(t.version_number),icon:e.jsx(Ga,{className:"w-3.5 h-3.5"}),children:"Restore"})]})]})})]},t.version_id)})})]})]}),k==="amendments"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Amendment History"}),Je&&e.jsx(o,{variant:"primary",size:"sm",onClick:()=>N(!0),icon:e.jsx(qt,{className:"w-4 h-4"}),children:"Create Amendment"})]}),$.length===0?e.jsx(j,{padding:"lg",children:e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-slate-400",children:[e.jsx(Vt,{className:"w-10 h-10 mx-auto mb-3 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"font-medium",children:"No amendments yet"}),e.jsx("p",{className:"text-sm mt-1",children:"Amendments track changes to this lease such as rent adju
7stments or term extensions."})]})}):e.jsx("div",{className:"space-y-3",children:$.map(t=>e.jsx(j,{padding:"md",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[La(t.amendment_type),Ta(t.status)]}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-slate-300",children:t.description}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-gray-500 dark:text-slate-400",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"w-3 h-3"}),"Effective: ",ie(t.effective_date)]}),!!t.new_rent_cents&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(de,{className:"w-3 h-3"}),"Rent: $",((t.previous_rent_cents||0)/100).toLocaleString()," → $",(t.new_rent_cents/100).toLocaleString()]}),t.new_end_date&&e.jsxs("span",{children:["New end: ",ie(t.new_end_date)]}),t.created_by_name&&e.jsxs("span",{children:["By: ",t.created_by_name]})]})]}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-slate-500",children:new Date(t.created_at).toLocaleDateString()})]})},t.amendment_id))})]}),k==="signing"&&Ye&&e.jsx(Ka,{leaseId:a.lease_id,envelopeId:a.envelope_id??void 0,leaseStatus:a.status,documentUrl:a.document_url,onVoid:()=>V(),onClose:()=>g("overview"),onRefreshLease:V}),k==="clauses"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Lease Clauses"}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{Pe(!0),$a()},icon:e.jsx(rt,{className:"w-4 h-4"}),children:"Add from Library"})]}),E.length===0?e.jsx(j,{padding:"lg",children:e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-slate-400",children:[e.jsx(Vt,{className:"w-10 h-10 mx-auto mb-3 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"font-medium",children:"No clauses attached"}),e.jsx("p",{className:"text-sm mt-1",children:"Add clauses from the clause library or create custom ones."})]})}):e.jsx("div",{className:"space-y-3",children:E.map(t=>e.jsx(j,{padding:"md",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(v,{variant:"default",children:t.clause_type.replace(/_/g," ")}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-slate-300 whitespace-pre-wrap",children:t.clause_text})]})},t.lease_clause_id))})]}),k==="escalations"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Rent Escalation Schedule"}),e.jsx(o,{variant:"primary",size:"sm",onClick:()=>ae(!0),icon:e.jsx(Ge,{className:"w-4 h-4"}),children:"Add Escalation"})]}),L.length===0?e.jsx(j,{padding:"lg",children:e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-slate-400",children:[e.jsx(Ge,{className:"w-10 h-10 mx-auto mb-3 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"font-medium",children:"No escalation schedule"}),e.jsx("p",{className:"text-sm mt-1",children:"Set up annual rent increases to be built into this lease."})]})}):e.jsx("div",{className:"space-y-3",children:L.map(t=>{var n;const s=!t.applied&&(((n=Se(t.effective_date))==null?void 0:n.getTime())??1/0)<=Date.now();return e.jsx(j,{padding:"md",children:e.jsxs("div",{className:`flex items-center justify-between ${t.applied?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-3 h-3 rounded-full ${t.applied?"bg-green-400":s?"bg-amber-500 animate-pulse":"bg-gray-300 dark:bg-slate-600"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium dark:text-white",children:ie(t.effective_date)}),e.jsx(v,{variant:t.escalation_type==="percentage"?"info":"warning",children:t.escalation_type==="percentage"?`+${(t.escalation_value/100).toFixed(1)}
7%`:`+$${(t.escalation_value/100).toLocaleString()}`}),t.applied&&e.jsx(v,{variant:"success",children:"Applied"}),s&&!t.applied&&e.jsx(v,{variant:"warning",children:"Due"})]}),t.applied&&!!t.previous_rent_cents&&!!t.new_rent_cents&&e.jsxs("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-1",children:["$",(t.previous_rent_cents/100).toLocaleString()," → $",(t.new_rent_cents/100).toLocaleString(),"/mo"]}),t.notes&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-1",children:t.notes})]})]}),s&&!t.applied&&e.jsx(o,{variant:"primary",size:"sm",loading:ta===t.escalation_id,onClick:async()=>{await m({title:"Apply this rent escalation?",message:"The monthly rent will be updated immediately. Future invoices use the new amount.",confirmLabel:"Apply",variant:"primary"})&&Sa(t.escalation_id)},children:"Apply Now"})]})},t.escalation_id)})})]}),k==="charges"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Recurring Charges"}),!M&&!U&&e.jsx(o,{variant:"primary",size:"sm",onClick:()=>{var t,s;i("parking"),C(""),Z("monthly"),oe(""),Le("1"),Te(!0),Ee(((t=a.start_date)==null?void 0:t.split("T")[0])||""),Re(((s=a.end_date)==null?void 0:s.split("T")[0])||""),G(!0)},icon:e.jsx(de,{className:"w-4 h-4"}),children:"Add Charge"})]}),(M||U)&&e.jsxs(j,{padding:"md",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:U?"Edit Charge":"New Recurring Charge"}),!U&&e.jsx("button",{type:"button",onClick:()=>{i("amenity"),oe("Amenity Package (gym, parking, storage)"),Z("monthly"),Ae(!0);const t=Qe(a==null?void 0:a.property_state,"amenity");t&&je(t)},className:"text-xs font-medium text-brand-navy hover:underline",children:"+ Amenity Package preset"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Type"}),e.jsx("select",{value:le,onChange:t=>{var n;const s=t.target.value;if(i(s),U||oe(((n=et.find(w=>w.value===s))==null?void 0:n.label)||s),!U&&!fe){const w=Qe(a==null?void 0:a.property_state,s);w&&je(w)}},className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md",disabled:!!U,children:et.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Amount ($)"}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:c,onChange:t=>C(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md",placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Frequency"}),e.jsxs("select",{value:K,onChange:t=>Z(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md",children:[e.jsx("option",{value:"monthly",children:"Monthly"}),e.jsx("option",{value:"annual",children:"Annual"}),e.jsx("option",{value:"one_time",children:"One-time"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Billing Day"}),e.jsx("input",{type:"number",min:"1",max:"28",value:lt,onChange:t=>Le(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",title:"e.g. NY State fitness-center tax is 4.5%",children:"Tax (%)"}),e.jsx("input",{type:"number",step:"0.01",min:"0",max:"100",value:fe,onChange:t=>je(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md",placeholder:"0"}),(()=>{const t=Qe(a==null?void 0:a.property_state,le);return t?e.jsxs("p",{className:"text-[11px] text-gray-400 mt-0.5",children:[a==null?void 0:a.property_state," default: ",t,"%"]}):null})()]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Description"}),e.jsx("input",{type:"text",value:ye,onChange:t=>oe(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md",placeholder:"Monthly Rent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Start Date"}),e.jsx("input",{type:"date",value:dt,onChange:t=>Ee(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"End Date"}),e.jsx("input",{type:"date",value:ct,onChange:t=>Re(t.target.value),className:"w-full px-2 py-1.5 text-sm border border-gray-300 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 mt-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-600",children:[e.jsx("input",{type:"checkbox",checked:it,onChange:t=>Te(t.target.checked),className:"rounded border-gray-300"}),"Auto-generate invoice"]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-600",children:[e.jsx("input",{type:"checkbox",checked:ot,onChange:t=>Ae(t.target.checked),className:"rounded border-gray-300"}),"Bundle as Amenity Package"]}),(()=>{const t=parseFloat(c||"0"),s=parseFloat(fe||"0");if(!t||!s)return null;const n=t*(s/100);return e.jsxs("span",{className:"text-xs text-gray-500",children:["Tax $",n.toFixed(2)," → billed ",e.jsxs("span",{className:"font-medium",children:["$",(t+n).toFixed(2),"/mo"]})," (separate from rent)"]})})()]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(o,{variant:"primary",size:"sm",loading:$e,onClick:()=>{const t=Math.round(parseFloat(c||"0")*100);if(!t){x.warning("Amount is required");return}const s=Math.round((parseFloat(fe||"0")||0)*100);ja({charge_type:le,amount_cents:t,frequency:K,description:ye||le,billing_day:parseInt(lt)||1,auto_generate_invoice:it,start_date:dt||void 0,end_date:ct||void 0,tax_rate_bps:s,is_package:ot?1:0})},children:U?"Update":"Save Charge"}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{G(!1),ce(null)},children:"Cancel"})]})]}),B.filter(t=>t.is_active).length===0&&!M?e.jsx(j,{padding:"lg",children:e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-slate-400",children:[e.jsx(de,{className:"w-10 h-10 mx-auto mb-3 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"font-medium",children:"No recurring charges"}),e.jsx("p",{className:"text-sm mt-1",children:"Add charges like rent, parking, or pet fees to auto-generate invoices."})]})}):e.jsx("div",{className:"space-y-2",children:B.filter(t=>t.is_active).map(t=>{var s;return e.jsx(j,{padding:"md",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:t.charge_type==="rent"?"info":t.charge_type==="parking"?"warning":"default",children:((s=et.find(n=>n.value===t.charge_type))==null?void 0:s.label)||t.charge_type}),e.jsxs("span",{className:"text-sm font-medium dark:text-white",children:["$",(t.amount_cents/100).toLocaleStr
7ing(),"/",t.frequency==="monthly"?"mo":t.frequency==="annual"?"yr":"once"]}),!!t.is_package&&e.jsx(v,{variant:"info",children:"Package"}),!!t.tax_rate_bps&&t.tax_rate_bps>0&&e.jsxs(v,{variant:"warning",children:["+",(t.tax_rate_bps/100).toFixed(2).replace(/\.?0+$/,""),"% tax"]}),t.auto_generate_invoice&&e.jsx(v,{variant:"success",children:"Auto-invoice"})]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[t.description," — Day ",t.billing_day," of month",t.start_date&&` — from ${t.start_date.split("T")[0]}`,t.end_date&&` to ${t.end_date.split("T")[0]}`]})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{var n,w;ce(t),G(!1),i(t.charge_type),C(String(t.amount_cents/100)),Z(t.frequency),oe(t.description),Le(String(t.billing_day)),Te(t.auto_generate_invoice),Ee(((n=t.start_date)==null?void 0:n.split("T")[0])||""),Re(((w=t.end_date)==null?void 0:w.split("T")[0])||""),je(t.tax_rate_bps?String(t.tax_rate_bps/100):""),Ae(!!t.is_package)},children:"Edit"}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>ba(t.charge_id),className:"text-red-600 hover:bg-red-50",children:"Remove"})]})]})},t.charge_id)})})]}),k==="inspections"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Move-in / Move-out Inspections"}),e.jsxs("div",{className:"flex gap-2",children:[z&&O&&e.jsx(o,{variant:"outline",size:"sm",onClick:()=>mt(!0),icon:e.jsx(_e,{className:"w-4 h-4"}),children:"Compare"}),e.jsx(o,{variant:"primary",size:"sm",onClick:()=>De(!0),icon:e.jsx(We,{className:"w-4 h-4"}),children:"New Inspection"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(j,{children:[e.jsx(W,{children:e.jsx(X,{children:"Move-In Inspection"})}),e.jsx("div",{className:"p-6 pt-0",children:z?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-sm font-medium dark:text-white",children:"Completed"}),e.jsx(v,{variant:z.result==="passed"?"success":z.result==="failed"?"danger":"warning",children:z.result||"Pending"})]}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-slate-400 space-y-1",children:[e.jsxs("p",{children:["Date: ",new Date(z.performed_at).toLocaleDateString()]}),z.inspector_name&&e.jsxs("p",{children:["Inspector: ",z.inspector_name]}),e.jsxs("p",{children:["Condition: ",((At=z.checklist_result)==null?void 0:At.overall_condition)||"N/A"]}),((Ft=z.checklist_result)==null?void 0:Ft.rooms)&&e.jsxs("p",{children:[z.checklist_result.rooms.length," rooms inspected"]})]})]}):e.jsxs("div",{className:"text-center py-6 text-gray-500 dark:text-slate-400",children:[e.jsx(We,{className:"w-8 h-8 mx-auto mb-2 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"text-sm",children:"Not yet completed"})]})})]}),e.jsxs(j,{children:[e.jsx(W,{children:e.jsx(X,{children:"Move-Out Inspection"})}),e.jsx("div",{className:"p-6 pt-0",children:O?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-sm font-medium dark:text-white",children:"Completed"}),e.jsx(v,{variant:O.result==="passed"?"success":O.result==="failed"?"danger":"warning",children:O.result||"Pending"})]}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-slate-400 space-y-1",children:[e.jsxs("p",{children:["Date: ",new Date(O.performed_at).toLocaleDateString()]}),O.inspector_name&&e.jsxs("p",{children:["Inspector: ",O.inspector_name]}),e.jsxs("p",{children:["Condition: ",((Dt=O.checklist_result)==null?void 0:Dt.overall_condition)||"N/A"]}),((Pt=O.checklist_result)==null?void 0:Pt.rooms)&&e.jsxs("p",{children:[O.checklist_result.rooms.length," rooms inspected"]})]})]}):e.jsxs("div",{className:"text-center py-6 text-gray-500 dark:text-slate-400",children:[e.jsx(We,{className:"w-8 h-8 mx-auto mb-2 text-gray-300 dark:text-slate-600"}),e.jsx("p",{className:"text-sm",children:"Not yet completed"})]})})]})]})]}),Xt&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"bg-white dark:bg-slate-800 rounded-xl shadow-xl w-full max-w-2xl max-h-[80vh] overflow-y-auto p-6",children:[e.jsx("h3",{className:"text-lg font-semibold dark:text-white mb-4",children:"Add Clauses from Library"}),pt.length===0?e.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 text-center py-8",children:"No clauses available in library."}):e.jsx("div",{className:"space-y-2",children:pt.map(t=>{const s=E.some(n=>n.clause_text===t.clause_text);return e.jsx("div",{className:`p-3 rounded-lg border ${s?"border-green-200 bg-green-50 dark:bg-green-900/20 dark:border-green-800":"border-gray-200 dark:border-slate-700 hover:border-blue-300 dark:hover:border-blue-700"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-medium dark:text-white",children:t.title||t.clause_type}),e.jsx(v,{variant:"default",children:t.clause_type}),!!t.is_standard&&e.jsx(v,{variant:"info",children:"System"})]}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-slate-400 line-clamp-2",children:t.clause_text})]}),s?e.jsx("span",{className:"text-xs text-green-600 dark:text-green-400 whitespace-nowrap",children:"Added"}):e.jsx(o,{variant:"outline",size:"sm",onClick:()=>Ca([t.clause_id]),children:"Add"})]})},t.clause_id)})}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(o,{variant:"outline",onClick:()=>Pe(!1),children:"Close"})})]})}),h&&a&&e.jsx(Wa,{lease:a,onClose:()=>N(!1),onSuccess:()=>{N(!1),Ne(),V()}}),b&&a&&e.jsx(Xa,{onClose:()=>P(!1),onSuccess:()=>{P(!1),V()},leaseContext:{leaseId:a.lease_id,title:`Lease Agreement — ${a.tenant_name||"Tenant"}`,tenantName:a.tenant_name||"",tenantEmail:a.tenant_email||"",tenantPhone:a.tenant_phone||"",landlordName:a.landlord_name||"",landlordEmail
7:a.landlord_email||"",propertyName:a.property_name||"",unitNumber:a.unit_number||""}}),te&&e.jsx(ls,{leaseId:l,currentRentCents:a.monthly_rent_cents,onClose:()=>ae(!1),onSaved:()=>{ae(!1),Ve()}}),Yt&&e.jsx(is,{leaseId:l,existingRule:f,onClose:()=>Fe(!1),onSaved:()=>{Fe(!1),$t()}}),Gt&&e.jsx(ds,{leaseId:l,onClose:()=>xt(!1)}),Kt&&e.jsx(cs,{leaseId:l,propertyType:a==null?void 0:a.property_type,unitId:a==null?void 0:a.unit_id,propertyId:a==null?void 0:a.property_id,onClose:()=>De(!1),onSaved:()=>{De(!1),Lt()}}),Wt&&z&&O&&e.jsx(os,{moveIn:z,moveOut:O,onClose:()=>mt(!1)}),na&&a&&e.jsx(Za,{initialContent:Oe,propertyId:a.property_id,leaseId:a.lease_id,currentVersion:a.current_version||1,formMetadata:a.tenant_name?(()=>{let t=a.tenant_email||"";if(!t&&Oe){const n=Oe.replace(/<[^>]+>/g," ").match(/TENANT[^]*?Email:\s*([^\s,]+@[^\s,]+)/i);n&&(t=n[1])}return{tenant_name:a.tenant_name,tenant_email:t,tenant_phone:a.tenant_phone||"",unit_number:a.unit_number||"",lease_type:a.property_type||"residential",monthly_rent:a.monthly_rent_cents?a.monthly_rent_cents/100:0,security_deposit:a.security_deposit_cents?a.security_deposit_cents/100:0,start_date:a.start_date||"",end_date:a.end_date||""}})():void 0,onClose:()=>ze(!1),onSave:()=>{ze(!1),V(),qe()}}),la&&e.jsx(as,{leaseId:l,fromVersion:ft.from,toVersion:ft.to,onClose:()=>yt(!1)}),aa&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>!ke&&be(!1),children:e.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg shadow-xl max-w-md w-full p-6",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{className:"text-lg font-bold dark:text-white mb-1",children:"Add Co-Tenant"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 mb-4",children:"This person will get their own portal access to this lease."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium uppercase text-gray-500 dark:text-slate-400 mb-1",children:"Full Name *"}),e.jsx("input",{type:"text",value:H.full_name,onChange:t=>ve({...H,full_name:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-slate-700 dark:bg-slate-900 dark:text-white rounded-lg",placeholder:"Jane Smith"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium uppercase text-gray-500 dark:text-slate-400 mb-1",children:"Email *"}),e.jsx("input",{type:"email",value:H.email,onChange:t=>ve({...H,email:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-slate-700 dark:bg-slate-900 dark:text-white rounded-lg",placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium uppercase text-gray-500 dark:text-slate-400 mb-1",children:"Phone"}),e.jsx("input",{type:"tel",value:H.phone,onChange:t=>ve({...H,phone:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-slate-700 dark:bg-slate-900 dark:text-white rounded-lg",placeholder:"(555) 123-4567"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx("button",{onClick:()=>be(!1),disabled:ke,className:"px-4 py-2 text-sm text-gray-600 dark:text-slate-400 hover:bg-gray-100 dark:hover:bg-slate-800 rounded-lg",children:"Cancel"}),e.jsx("button",{onClick:ua,disabled:ke||!H.full_name.trim()||!H.email.trim(),className:"px-4 py-2 text-sm bg-brand-navy text-white rounded-lg hover:bg-brand-navy/90 disabled:opacity-50",children:ke?"Adding…":"Add & Send Invite"})]})]})}),ca&&a&&e.jsx(ss,{lease:a,onClose:()=>Ue(!1),onSuccess:()=>{Ue(!1),V(),Ne()}})]})}function ls(l){const[p,x]=r.useState(null);return r.useEffect(()=>{ge(()=>import("./RentEscalationModal-D5hYPFlL.js"),__vite__mapDeps([0,1,2,3,4,5,6])).then(m=>x(()=>m.default))},[]),p?e.jsx(p,{...l}):null}function is(l){const[p,x]=r.useState(null);return r.useEffect(()=>{ge(()=>import("./LateFeeRuleModal-YS1cJQDf.js"),__vite__mapDeps([7,1,2,3,4,6])).then(m=>x(()=>m.default))},[]),p?e.jsx(p,{...l}):null}function ds(l){const[p,x]=r.useState(null);return r.useEffect(()=>{ge(()=>import("./LeaseComparisonModal-B3kiEbyO.js"),__vite__mapDeps([8,1,2,3,4,9,10,11])).then(m=>x(()=>m.default))},[]),p?e.jsx(p,{...l}):null}function cs(l){const[p,x]=r.useState(null);return r.useEffect(()=>{ge(()=>import("./MoveInOutInspectionModal-D38Ju1qo.js"),__vite__mapDeps([12,1,2,3,4,9])).then(m=>x(()=>m.default))},[]),p?e.jsx(p,{...l}):null}function os(l){const[p,x]=r.useState(null);return r.useEffect(()=>{ge(()=>import("./InspectionComparisonView-DlukpL6c.js"),__vite__mapDeps([13,1,2,3,4,9,14,15])).then(m=>x(()=>m.default))},[]),p?e.jsx(p,{...l}):null}function xs({leaseId:l,status:p,legalReviewedBy:x,legalReviewedAt:m,legalNotes:a,opsReviewedBy:q,opsReviewedAt:$,opsNotes:A,onTransition:E}){const[_,L]=r.useState(!1),[F,f]=r.useState(""),[T,u]=r.useState(null),[D,Y]=r.useState(null),S=(localStorage.getItem("userRole")||"").toLowerCase(),k=S==="admin"||S==="landlord"||S==="legal",g=S==="admin"||S==="landlord"||S==="ops",h=S==="admin"||S==="landlord"||S==="manager",N=async(te,ae={})=>{L(!0),Y(null);try{const B=he(),ne=await fetch(`/api/leases/${l}/transition`,{method:"POST",headers:{"x-api-key":B,"Content-Type":"application/json"},body:JSON.stringify({action:te,...ae})}),M=await ne.json();if(!ne.ok)throw new Error((M==null?void 0:M.error)||"Transition failed");f(""),u(null),E()}catch(B){Y((B==null?void 0:B.message)||"Transition failed")}finally{L(!1)}},b=String(p||"").toLowerCase(),P=b==="legal_review",ee=b==="ops_review";return b==="draft"||P||ee||b==="signed"||m||$?e.jsxs("div",{className:"mt-3 p-3 bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-900 rounded-lg text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 text-blue-900 dark:text-blue-200 font-medium",children:[e.jsx(at,{className:"w-4 h-4"})," 3-Team Signoff"]}),m&&e.jsxs("div",{className:"text-xs text-gray-700 dark:text-slate-300 mb-2",children:[e.jsx("span",{className:"font-semibold text-emerald-700 dark:text-emerald-400",children:"✓ Legal review:"}
7)," ",new Date(m).toLocaleString()," by ",x||"legal",a&&e.jsxs("span",{className:"italic",children:[' — "',a,'"']})]}),$&&e.jsxs("div",{className:"text-xs text-gray-700 dark:text-slate-300 mb-2",children:[e.jsx("span",{className:"font-semibold text-emerald-700 dark:text-emerald-400",children:"✓ Ops review:"})," ",new Date($).toLocaleString()," by ",q||"ops",A&&e.jsxs("span",{className:"italic",children:[' — "',A,'"']})]}),D&&e.jsxs("div",{className:"mb-2 p-2 bg-red-50 border border-red-200 rounded text-xs text-red-700 flex items-center gap-1",children:[e.jsx(nt,{className:"w-3.5 h-3.5"})," ",D]}),e.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[b==="draft"&&h&&e.jsx(o,{size:"sm",variant:"primary",disabled:_,onClick:()=>N("submit_legal"),children:"Submit for Legal Review"}),P&&k&&T!=="legal"&&e.jsxs(e.Fragment,{children:[e.jsx(o,{size:"sm",variant:"primary",disabled:_,onClick:()=>N("legal_approve"),children:"Approve — send for e-signature"}),e.jsx(o,{size:"sm",variant:"outline",disabled:_,onClick:()=>u("legal"),children:"Reject back to draft"})]}),P&&!k&&e.jsx("span",{className:"text-xs text-gray-500",children:"Waiting for legal reviewer."}),b==="signed"&&h&&e.jsx(o,{size:"sm",variant:"primary",disabled:_,onClick:()=>N("submit_ops"),children:"Submit for Ops Review"}),ee&&g&&T!=="ops"&&e.jsxs(e.Fragment,{children:[e.jsx(o,{size:"sm",variant:"primary",disabled:_,onClick:()=>N("ops_approve"),children:"Approve — activate lease"}),e.jsx(o,{size:"sm",variant:"outline",disabled:_,onClick:()=>u("ops"),children:"Reject to punch list"})]}),ee&&!g&&e.jsx("span",{className:"text-xs text-gray-500",children:"Waiting for ops reviewer to confirm move-in."})]}),T&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsx("textarea",{value:F,onChange:te=>f(te.target.value),placeholder:T==="legal"?"Reason for rejecting back to draft…":"Punch list / reason for rejecting back to signed…",rows:2,className:"w-full px-2 py-1.5 text-xs border border-gray-300 dark:border-slate-600 rounded dark:bg-slate-900"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o,{size:"sm",variant:"danger",disabled:_||!F.trim(),onClick:()=>N(T==="legal"?"legal_reject":"ops_reject",{notes:F.trim()}),children:"Reject with notes"}),e.jsx(o,{size:"sm",variant:"outline",disabled:_,onClick:()=>{u(null),f("")},children:"Cancel"})]})]})]}):null}export{Os 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.