1import{c as ke,N as ze,O as Ve,q as e,s as he,F as De,w as Le,aC as He,r,Q as Ge,aq as We,a2 as N,U as Ce,aG as Te,aH as qe,aI as Re,aJ as Ae,ba as Ie,ar as l,b0 as $e,ay as o,at as ve,au as fe,av as ye,aw as be,ax as L,as as me,aN as Be,B as de,ae as Ze,V as Je,al as Xe,bb as Pe,bc as Ye}from"./index-RQZfdGSV.js";import{u as Qe,C as Ke,B as et}from"./ConsoleSidebar-CrydHVXV.js";import{W as tt}from"./wallet-CFkmYcPh.js";import{D as st,a as at,b as rt,c as Me}from"./dropdown-menu-D9mbcrJs.js";import{P as xe}from"./types-ewSoxauB.js";import{E as it}from"./ellipsis-vertical-DI2tbuzn.js";import{P as nt}from"./pencil-DZwwnk3k.js";import{T as lt}from"./trash-2-B5L3aDOx.js";import{L as dt}from"./LegacyUpgradeModal-B9Dq_Gs8.js";import{T as ot}from"./TierGate-B342dcPq.js";import{A as ct,b as ut,c as ht,d as mt,e as xt,f as pt,g as gt,h as jt}from"./alert-dialog-BmdSQsbw.js";import"./settings-Cl1wpAwS.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const _e=ke("ImagePlus",[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const vt=ke("Percent",[["line",{x1:"19",x2:"5",y1:"5",y2:"19",key:"1x9vlm"}],["circle",{cx:"6.5",cy:"6.5",r:"2.5",key:"4mh3h7"}],["circle",{cx:"17.5",cy:"17.5",r:"2.5",key:"1mdrzq"}]]);function Ne(t,d=!0){if(!Number.isFinite(t))return"$0";const i=Math.abs(t);return d&&i>=1e6?`${t<0?"-":""}$${(i/1e6).toFixed(2)}M`:d&&i>=1e3?`${t<0?"-":""}$${Math.round(i/1e3)}k`:`${t<0?"-":""}$${Math.round(i).toLocaleString()}`}function ft(t,d=1){return t==null||!Number.isFinite(t)?"â":`${(t*100).toFixed(d)}%`}function yt({rollup:t}){const d=[{label:"Total equity",value:Ne(t.totalEquity),icon:tt},{label:"Monthly cash flow",value:Ne(t.totalMonthlyCashFlow,!1),icon:ze,tone:t.totalMonthlyCashFlow>0?"text-emerald-600":t.totalMonthlyCashFlow<0?"text-destructive":"text-foreground"},{label:"Weighted cap rate",value:ft(t.weightedAvgCapRate,2),icon:vt},{label:"Total appreciation",value:Ne(t.totalAppreciation),icon:Ve,tone:t.totalAppreciation>0?"text-emerald-600":t.totalAppreciation<0?"text-destructive":"text-foreground"}],i=t.topMarketShare&&t.topMarketShare.pct>.5&&t.count>1;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:d.map(c=>e.jsx(he,{className:"border-border/60",children:e.jsxs(De,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(c.icon,{className:"h-3.5 w-3.5"}),c.label]}),e.jsx("div",{className:`mt-1.5 text-2xl font-semibold ${c.tone??"text-foreground"}`,children:c.value})]})},c.label))}),t.topMarketShare&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsxs(Le,{variant:"secondary",className:"font-normal",children:["Top market: ",t.topMarketShare.market," ·"," ",(t.topMarketShare.pct*100).toFixed(0),"%"]}),i&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-600",children:[e.jsx(He,{className:"h-3.5 w-3.5"}),"Heavy concentration in a single market"]})]})]})}function we(t,d=!0){if(!Number.isFinite(t))return"$0";const i=Math.abs(t);return d&&i>=1e6?`${t<0?"-":""}$${(i/1e6).toFixed(2)}M`:d&&i>=1e3?`${t<0?"-":""}$${Math.round(i/1e3)}k`:`${t<0?"-":""}$${Math.round(i).toLocaleString()}`}function bt({property:t,onClick:d,onEdit:i,onDelete:c}){const{metrics:u}=t,[p,g]=r.useState(!1);r.useEffect(()=>{g(!1)},[t.primary_photo_url]);const h=t.is_primary_residence?"Owner-occupied":t.is_rented?`${we(u.monthlyCashFlow,!1)}/mo`:"Not rented";return e.jsxs(he,{onClick:d,className:"overflow-hidden cursor-pointer hover:shadow-md transition-shadow border-border/60",children:[e.jsxs("div",{className:"relative aspect-[16/10] bg-muted",children:[t.primary_photo_url&&!p?e.jsx("img",{src:t.primary_photo_url,alt:t.address_line1,className:"w-full h-full object-cover",loading:"lazy",onError:()=>g(!0)}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-muted-foreground",children:e.jsx(Ge,{className:"h-10 w-10"})}),u.activeAlertsCount>0&&e.jsx("div",{className:"absolute top-2 right-10",children:e.jsxs(Le,{className:"bg-amber-500/95 hover:bg-amber-500 text-white border-0 inline-flex items-center gap-1",children:[e.jsx(We,{className:"h-3 w-3"}),u.activeAlertsCount]})}),(i||c)&&e.jsx("div",{className:"absolute top-2 right-2",children:e.jsxs(st,{children:[e.jsx(at,{asChild:!0,children:e.jsx("button",{type:"button",onClick:f=>f.stopPropagation(),"aria-label":"Property actions",className:"h-8 w-8 inline-flex items-center justify-center rounded-md bg-background/90 backdrop-blur hover:bg-background border border-border/60 shadow-sm",children:e.jsx(it,{className:"h-4 w-4"})})}),e.jsxs(rt,{align:"end",onClick:f=>f.stopPropagation(),children:[i&&e.jsxs(Me,{onSelect:()=>i(t),children:[e.jsx(nt,{className:"h-4 w-4 mr-2"})," Edit details"]}
11),c&&e.jsxs(Me,{onSelect:()=>c(t),className:"text-destructive focus:text-destructive",children:[e.jsx(lt,{className:"h-4 w-4 mr-2"})," Delete"]})]})]})})]}),e.jsxs(De,{className:"p-4 space-y-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium truncate",children:t.address_line1}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:[t.city,", ",t.state," · ",xe[t.property_type]]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-1 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Value"}),e.jsx("div",{className:"font-semibold",children:we(u.currentValue)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Equity"}),e.jsx("div",{className:"font-semibold",children:we(u.equity)})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Cash flow"}),e.jsx("div",{className:t.is_rented&&u.monthlyCashFlow<0?"font-medium text-destructive":t.is_rented&&u.monthlyCashFlow>0?"font-medium text-emerald-600":"font-medium text-foreground",children:h})]})]})]})]})}const Ee={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",avif:"image/avif",heic:"image/heic",heif:"image/heif"};function Se(t){var c;const d=(c=t.name.split(".").pop())==null?void 0:c.toLowerCase();if(d&&Ee[d])return d;const i=(t.type||"").toLowerCase();return i.startsWith("image/")&&i.split("/")[1]||"jpg"}function Nt(t){if(t.type)return t.type;const d=Se(t);return Ee[d]}function Oe(t){const d=Se(t);return d==="heic"||d==="heif"}async function Ue(t){const{file:d,userId:i,propertyId:c}=t,u=Se(d),p=`${i}/${c}/cover-${Date.now()}.${u}`,g=Nt(d),{error:h}=await N.storage.from("owned-property-photos").upload(p,d,{upsert:!0,...g?{contentType:g}:{}});if(h)throw console.error("[cover-image] upload failed",h),h;return p}const je=()=>new Date().toISOString().slice(0,10);function wt({open:t,onOpenChange:d,onCreated:i}){const{toast:c}=Ce(),[u,p]=r.useState(!1),[g,h]=r.useState(""),[f,y]=r.useState(""),[T,q]=r.useState(""),[S,R]=r.useState(""),[A,v]=r.useState("single_family"),[F,P]=r.useState(""),[k,I]=r.useState(""),[D,n]=r.useState(""),[m,x]=r.useState(je()),[j,Z]=r.useState(""),[$,J]=r.useState(""),[w,_]=r.useState(!0),[X,Y]=r.useState(""),[B,Q]=r.useState(""),[K,ee]=r.useState("30"),[oe,te]=r.useState(je()),[O,se]=r.useState(!1),[ae,U]=r.useState(""),[z,re]=r.useState(null),[ie,V]=r.useState(null),ce=a=>{if(!a){re(null),V(null);return}if(a.size>5*1024*1024){c({title:"Image too large",description:"Max 5MB",variant:"destructive"});return}re(a),V(URL.createObjectURL(a))},ue=()=>{h(""),y(""),q(""),R(""),v("single_family"),P(""),I(""),n(""),x(je()),Z(""),J(""),_(!0),Y(""),Q(""),ee("30"),te(je()),se(!1),U(""),re(null),V(null)},ne=!!g.trim()&&!!f.trim()&&!!T.trim()&&!!S.trim()&&!!m&&Number(j)>0,pe=async()=>{if(ne){p(!0);try{const{data:{user:a}}=await N.auth.getUser();if(!a){c({title:"Please sign in",variant:"destructive"});return}const H={user_id:a.id,address_line1:g.trim(),city:f.trim(),state:T.trim().toUpperCase().slice(0,2),zip:S.trim(),property_type:A,beds:F?Number(F):null,baths:k?Number(k):null,sqft:D?Number(D):null,purchase_date:m,purchase_price:Number(j),down_payment:$?Number($):null,has_mortgage:w,loan_original_principal:w&&X?Number(X):null,loan_rate_apr:w&&B?Number(B)/100:null,loan_term_years:w&&K?Number(K):null,loan_start_date:w?oe:null,is_rented:O,current_value_estimate:Number(j),current_value_source:"seed"},{data:G,error:le}=await N.from("investor_owned_properties").insert(H).select("id").single();if(le)throw le;if(z)try{const M=await Ue({file:z,userId:a.id,propertyId:G.id}),{error:ge}=await N.from("investor_owned_properties").update({primary_photo_url:M}).eq("id",G.id);if(ge)throw ge;Oe(z)&&c({title:"Cover uploaded",description:"HEIC images don't render in most browsers â convert to JPG/PNG for a visible cover."})}catch(M){console.error("[AddPropertyDialog] cover upload failed",M),c({title:"Cover image upload failed",description:(M==null?void 0:M.message)??String(M),variant:"destructive"})}O&&ae&&await N.from("investor_owned_property_rental").insert({property_id:G.id,monthly_rent:Number(ae)}),await N.from("investor_owned_property_events").insert({property_id:G.id,event_type:"purchased",event_date:m,details:{purchase_price:Number(j),down_payment:$?Number($):null,loan_rate:w&&B?Number(B)/100:null}}),c({title:"Property added",description:g}),ue(),d(!1),i==null||i(G.id)}catch(a){c({title:"Could not save property",description:(a==null?void 0:a.message)??String(a),variant:"destructive"})}finally{p(!1)}}};return e.jsx(Te,{open:t,onOpenChange:d,children:e.jsxs(qe,{className:"max-w-xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Re,{children:[e.jsx(Ae,{children:"Add a property"}),e.jsx(Ie,{children:"Identity and acquisition are required. Everything else is optional."})]}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Identity"}),e.jsxs("div",{children:[e.jsx(l,{children:"Cover image (optional)"}),ie?e.jsxs("div",{className:"mt-1 relative w-full aspect-[16/10] rounded-md overflow-hidden border border-border",children:[e.jsx("img",{src:ie,alt:"Cover preview",className:"w-full h-full object-cover"}),e.jsx("button",{type:"button",onClick:()=>ce(null),className:"absolute top-2 right-2 h-7 w-7 inline-flex items-center justify-center rounded-md bg-background/90 border border-border shadow-sm","aria-label":"Remove c
11over image",children:e.jsx($e,{className:"h-4 w-4"})})]}):e.jsxs("label",{className:"mt-1 flex items-center gap-2 justify-center cursor-pointer border border-dashed border-border rounded-md p-4 text-sm text-muted-foreground hover:bg-muted/40",children:[e.jsx(_e,{className:"h-4 w-4"}),e.jsx("span",{children:"Click to upload (max 5MB)"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:a=>{var H;return ce(((H=a.target.files)==null?void 0:H[0])??null)}})]})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"addr",children:"Street address"}),e.jsx(o,{id:"addr",value:g,onChange:a=>h(a.target.value),placeholder:"1814 Cedar St"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx(l,{htmlFor:"city",children:"City"}),e.jsx(o,{id:"city",value:f,onChange:a=>y(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"state",children:"State"}),e.jsx(o,{id:"state",value:T,onChange:a=>q(a.target.value),placeholder:"TX",maxLength:2})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"zip",children:"Zip"}),e.jsx(o,{id:"zip",value:S,onChange:a=>R(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Property type"}),e.jsxs(ve,{value:A,onValueChange:a=>v(a),children:[e.jsx(fe,{children:e.jsx(ye,{})}),e.jsx(be,{children:Object.keys(xe).map(a=>e.jsx(L,{value:a,children:xe[a]},a))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"beds",children:"Beds"}),e.jsx(o,{id:"beds",type:"number",value:F,onChange:a=>P(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"baths",children:"Baths"}),e.jsx(o,{id:"baths",type:"number",step:"0.5",value:k,onChange:a=>I(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"sqft",children:"Sqft"}),e.jsx(o,{id:"sqft",type:"number",value:D,onChange:a=>n(a.target.value)})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Acquisition"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"pdate",children:"Purchase date"}),e.jsx(o,{id:"pdate",type:"date",value:m,onChange:a=>x(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"pprice",children:"Purchase price"}),e.jsx(o,{id:"pprice",type:"number",value:j,onChange:a=>Z(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"down",children:"Down payment"}),e.jsx(o,{id:"down",type:"number",value:$,onChange:a=>J(a.target.value)})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Loan"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Cash"}),e.jsx(me,{checked:w,onCheckedChange:_}),e.jsx("span",{children:"Mortgage"})]})]}),w&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"lp",children:"Original principal"}),e.jsx(o,{id:"lp",type:"number",value:X,onChange:a=>Y(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"lr",children:"Rate (%)"}),e.jsx(o,{id:"lr",type:"number",step:"0.001",value:B,onChange:a=>Q(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"lt",children:"Term (years)"}),e.jsx(o,{id:"lt",type:"number",value:K,onChange:a=>ee(a.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"ls",children:"Loan start"}),e.jsx(o,{id:"ls",type:"date",value:oe,onChange:a=>te(a.target.value)})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Rental"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"No"}),e.jsx(me,{checked:O,onCheckedChange:se}),e.jsx("span",{children:"Currently rented"})]})]}),O&&e.jsxs("div",{children:[e.jsx(l,{htmlFor:"rent",children:"Monthly rent"}),e.jsx(o,{id:"rent",type:"number",value:ae,onChange:a=>U(a.target.value)})]})]})]}),e.jsxs(Be,{children:[e.jsx(de,{variant:"ghost",onClick:()=>d(!1),disabled:u,children:"Cancel"}),e.jsx(de,{onClick:pe,disabled:!ne||u,children:u?"Savingâ¦":"Add property"})]})]})})}const b=t=>t==null?"":String(t);function _t({property:t,open:d,onOpenChange:i,onSaved:c}){const{toast:u}=Ce(),[p,g]=r.useState(!1),[h,f]=r.useState(""),[y,T]=r.useState(""),[q,S]=r.useState(""),[R,A]=r.useState(""),[v,F]=r.useState("single_family"),[P,k]=r.useState(""),[I,D]=r.useState(""),[n,m]=r.useState(""),[x,j]=r.useState(""),[Z,$]=r.useState(""),[J,w]=r.useState(""),[_,X]=r.useState(!1),[Y,B]=r.useState(""),[Q,K]=r.useState(""),[ee,oe]=r.useState(""),[te,O]=r.useState(""),[se,ae]=r.useState(""),[U,z]=r.useState(!1),[re,ie]=r.useState(!1),[V,ce]=r.useState(""),[ue,ne]=r.useState(null),[pe,a]=r.useState(null),[H,G]=r.useState(null),le=s=>{if(!s){ne(null),a(null);return}if(s.size>5*1024*1024){u({title:"Image too large",description:"Max 5MB",variant:"destructive"});return}ne(s),a(URL.createObjectURL(s))};r.useEffect(()=>{var s,C,E;t&&(f(t.address_line1??""),T(t.city??""),S(t.state??""),A(b(t.zip)),F(t.property_type??"single_family"),k(b(t.beds)),D(b(t.baths)),m(b(t.sqft)),j(((s=b(t.purchase_date))==null?void 0:s.slice(0,10))??""),$(b(t.purchase_price)),w(b(t.down_payment)),X(!!t.has_mortgage),B(b(t.loan_original_principal)),K(t.loan_rate_apr!=null?String(Number(t.loan_rate_apr)*100):""),oe(b(t.loan_term_years)),O(((C=b(t.loan_start_date))==null?void 0:C.slice(0,10))??""),ae(b(t.loan_current_balance)),z(!!t.is_rented),ie(!!t.is_primary_residence),ce(b((E=t.rental)==null?void 0:E.monthly_rent)),ne(null),a(null),G(t.primary_photo_url??null))},[t]);const M=!!t&&!!h.trim()&&!!y.trim()&&!!q.trim()&&!!x&&Number(Z)>0,ge=async()=>
11{if(!(!M||!t)){g(!0);try{const s={address_line1:h.trim(),city:y.trim(),state:q.trim().toUpperCase().slice(0,2),zip:R.trim()||null,property_type:v,beds:P?Number(P):null,baths:I?Number(I):null,sqft:n?Number(n):null,purchase_date:x,purchase_price:Number(Z),down_payment:J?Number(J):null,has_mortgage:_,loan_original_principal:_&&Y?Number(Y):null,loan_rate_apr:_&&Q?Number(Q)/100:null,loan_term_years:_&&ee?Number(ee):null,loan_start_date:_&&te?te:null,loan_current_balance:_&&se?Number(se):null,is_rented:U,is_primary_residence:re},{error:C}=await N.from("investor_owned_properties").update(s).eq("id",t.id);if(C)throw C;if(ue){const{data:{user:E}}=await N.auth.getUser();if(E)try{const W=await Ue({file:ue,userId:E.id,propertyId:t.id}),{error:Fe}=await N.from("investor_owned_properties").update({primary_photo_url:W}).eq("id",t.id);if(Fe)throw Fe;Oe(ue)&&u({title:"Cover uploaded",description:"HEIC images don't render in most browsers â convert to JPG/PNG for a visible cover."})}catch(W){console.error("[EditPropertyDialog] cover upload failed",W),u({title:"Cover image upload failed",description:(W==null?void 0:W.message)??String(W),variant:"destructive"})}}if(U&&V){const E=Number(V);t.rental?await N.from("investor_owned_property_rental").update({monthly_rent:E}).eq("property_id",t.id):await N.from("investor_owned_property_rental").insert({property_id:t.id,monthly_rent:E})}u({title:"Property updated",description:h}),i(!1),c==null||c()}catch(s){u({title:"Could not update property",description:(s==null?void 0:s.message)??String(s),variant:"destructive"})}finally{g(!1)}}};return e.jsx(Te,{open:d,onOpenChange:i,children:e.jsxs(qe,{className:"max-w-xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Re,{children:[e.jsx(Ae,{children:"Edit property"}),e.jsx(Ie,{children:"Update details, loan, or rental info. Changes refresh portfolio metrics."})]}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Identity"}),e.jsxs("div",{children:[e.jsx(l,{children:"Cover image"}),pe?e.jsxs("div",{className:"mt-1 relative w-full aspect-[16/10] rounded-md overflow-hidden border border-border",children:[e.jsx("img",{src:pe,alt:"Cover preview",className:"w-full h-full object-cover"}),e.jsx("button",{type:"button",onClick:()=>le(null),className:"absolute top-2 right-2 h-7 w-7 inline-flex items-center justify-center rounded-md bg-background/90 border border-border shadow-sm","aria-label":"Remove new cover image",children:e.jsx($e,{className:"h-4 w-4"})})]}):H?e.jsxs("div",{className:"mt-1 space-y-2",children:[e.jsx("div",{className:"w-full aspect-[16/10] rounded-md overflow-hidden border border-border bg-muted",children:e.jsx("img",{src:H,alt:"Current cover",className:"w-full h-full object-cover"})}),e.jsxs("label",{className:"flex items-center gap-2 justify-center cursor-pointer border border-dashed border-border rounded-md p-3 text-sm text-muted-foreground hover:bg-muted/40",children:[e.jsx(_e,{className:"h-4 w-4"}),e.jsx("span",{children:"Replace cover image (max 5MB)"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:s=>{var C;return le(((C=s.target.files)==null?void 0:C[0])??null)}})]})]}):e.jsxs("label",{className:"mt-1 flex items-center gap-2 justify-center cursor-pointer border border-dashed border-border rounded-md p-4 text-sm text-muted-foreground hover:bg-muted/40",children:[e.jsx(_e,{className:"h-4 w-4"}),e.jsx("span",{children:"Click to upload (max 5MB)"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:s=>{var C;return le(((C=s.target.files)==null?void 0:C[0])??null)}})]})]}
11),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-addr",children:"Street address"}),e.jsx(o,{id:"e-addr",value:h,onChange:s=>f(s.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx(l,{htmlFor:"e-city",children:"City"}),e.jsx(o,{id:"e-city",value:y,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-state",children:"State"}),e.jsx(o,{id:"e-state",value:q,onChange:s=>S(s.target.value),maxLength:2})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-zip",children:"Zip"}),e.jsx(o,{id:"e-zip",value:R,onChange:s=>A(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Property type"}),e.jsxs(ve,{value:v,onValueChange:s=>F(s),children:[e.jsx(fe,{children:e.jsx(ye,{})}),e.jsx(be,{children:Object.keys(xe).map(s=>e.jsx(L,{value:s,children:xe[s]},s))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-beds",children:"Beds"}),e.jsx(o,{id:"e-beds",type:"number",value:P,onChange:s=>k(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-baths",children:"Baths"}),e.jsx(o,{id:"e-baths",type:"number",step:"0.5",value:I,onChange:s=>D(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-sqft",children:"Sqft"}),e.jsx(o,{id:"e-sqft",type:"number",value:n,onChange:s=>m(s.target.value)})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Acquisition"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-pdate",children:"Purchase date"}),e.jsx(o,{id:"e-pdate",type:"date",value:x,onChange:s=>j(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-pprice",children:"Purchase price"}),e.jsx(o,{id:"e-pprice",type:"number",value:Z,onChange:s=>$(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-down",children:"Down payment"}),e.jsx(o,{id:"e-down",type:"number",value:J,onChange:s=>w(s.target.value)})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Loan"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Cash"}),e.jsx(me,{checked:_,onCheckedChange:X}),e.jsx("span",{children:"Mortgage"})]})]}),_&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-lp",children:"Original principal"}),e.jsx(o,{id:"e-lp",type:"number",value:Y,onChange:s=>B(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-lr",children:"Rate (%)"}),e.jsx(o,{id:"e-lr",type:"number",step:"0.001",value:Q,onChange:s=>K(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-lt",children:"Term (years)"}),e.jsx(o,{id:"e-lt",type:"number",value:ee,onChange:s=>oe(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-ls",children:"Loan start"}),e.jsx(o,{id:"e-ls",type:"date",value:te,onChange:s=>O(s.target.value)})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(l,{htmlFor:"e-lb",children:"Current balance (optional)"}),e.jsx(o,{id:"e-lb",type:"number",value:se,onChange:s=>ae(s.target.value)})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Occupancy"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Owner-occupied"}),e.jsx(me,{checked:re,onCheckedChange:s=>{ie(s),s&&z(!1)}})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Rental"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Not rented"}),e.jsx(me,{checked:U,onCheckedChange:s=>{z(s),s&&ie(!1)}}),e.jsx("span",{children:"Currently rented"})]})]}),U&&e.jsxs("div",{children:[e.jsx(l,{htmlFor:"e-rent",children:"Monthly rent"}),e.jsx(o,{id:"e-rent",type:"number",value:V,onChange:s=>ce(s.target.value)})]})]})]}),e.jsxs(Be,{children:[e.jsx(de,{variant:"ghost",onClick:()=>i(!1),disabled:p,children:"Cancel"}),e.jsx(de,{onClick:ge,disabled:!M||p,children:p?"Savingâ¦":"Save changes"})]})]})})}function It(){const t=Ze(),{toast:d}=Ce(),{properties:i,rollup:c,loading:u,reload:p}=Qe(),{loading:g}=Je(),[h,f]=r.useState("all"),[y,T]=r.useState("updated"),[q,S]=r.useState(!1),[R,A]=r.useState(null),[v,F]=r.useState(null),[P,k]=r.useState(!1),I=async()=>
11{if(v){k(!0);try{const{error:n}=await N.from("investor_owned_properties").update({status:"archived"}).eq("id",v.id);if(n)throw n;d({title:"Property removed",description:v.address_line1}),F(null),p()}catch(n){d({title:"Could not delete property",description:(n==null?void 0:n.message)??String(n),variant:"destructive"})}finally{k(!1)}}},D=r.useMemo(()=>{let n=i;h==="rented"&&(n=n.filter(x=>x.is_rented)),h==="owner_occupied"&&(n=n.filter(x=>x.is_primary_residence));const m=[...n];return y==="equity"?m.sort((x,j)=>j.metrics.equity-x.metrics.equity):y==="cashFlow"?m.sort((x,j)=>j.metrics.monthlyCashFlow-x.metrics.monthlyCashFlow):y==="purchase"&&m.sort((x,j)=>j.purchase_date>x.purchase_date?1:-1),m},[i,h,y]);return e.jsxs("div",{className:"min-h-screen bg-background flex flex-col",children:[e.jsx(Xe,{}),e.jsxs("div",{className:"flex flex-row flex-1",children:[e.jsx(Ke,{}),e.jsx("main",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"container mx-auto px-4 py-6 lg:py-8 max-w-6xl space-y-6",children:[e.jsx("header",{className:"flex flex-wrap items-start justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold mb-2",children:"My properties"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Track equity, cash flow, and strategic opportunities across what you own."})]})}),g?e.jsx(he,{className:"h-96 animate-pulse bg-muted/30"}):e.jsx(ot,{feature:"INVESTOR_CALCULATOR",featureName:"My Properties",description:"Track equity, cash flow, refi opportunities and tax exports across every property you own â included with the Investor plan.",children:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs(de,{onClick:()=>S(!0),className:"gap-1",children:[e.jsx(Pe,{className:"h-4 w-4"}),"Add property"]})}),i.length>0&&e.jsx(yt,{rollup:c}),i.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Filter"]}),e.jsxs(ve,{value:h,onValueChange:n=>
11f(n),children:[e.jsx(fe,{className:"h-8 w-[160px]",children:e.jsx(ye,{})}),e.jsxs(be,{children:[e.jsx(L,{value:"all",children:"All"}),e.jsx(L,{value:"rented",children:"Rented"}),e.jsx(L,{value:"owner_occupied",children:"Owner-occupied"})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground ml-2",children:"Sort"}),e.jsxs(ve,{value:y,onValueChange:n=>T(n),children:[e.jsx(fe,{className:"h-8 w-[180px]",children:e.jsx(ye,{})}),e.jsxs(be,{children:[e.jsx(L,{value:"updated",children:"Recently updated"}),e.jsx(L,{value:"equity",children:"Most equity"}),e.jsx(L,{value:"cashFlow",children:"Best cash flow"}),e.jsx(L,{value:"purchase",children:"Most recent purchase"})]})]})]}),u?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[0,1,2].map(n=>e.jsx(he,{className:"h-72 animate-pulse bg-muted/30"},n))}):D.length===0?e.jsxs(he,{className:"p-10 text-center border-dashed",children:[e.jsx(et,{className:"h-10 w-10 mx-auto text-muted-foreground"}),e.jsx("h2",{className:"mt-3 text-lg font-medium",children:i.length===0?"No properties yet":"Nothing matches this filter"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 max-w-md mx-auto",children:i.length===0?"Add your first property to track equity, cash flow, and strategic alerts in one place.":"Try changing the filter to see other properties."}),i.length===0&&e.jsxs(de,{className:"mt-4 gap-1",onClick:()=>S(!0),children:[e.jsx(Pe,{className:"h-4 w-4"}),"Add property"]})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:D.map(n=>e.jsx(bt,{property:n,onClick:()=>t(`/investor/properties/${n.id}`),onEdit:m=>A(m),onDelete:m=>F(m)},n.id))})]})})]})})]}),e.jsx(wt,{open:q,onOpenChange:S,onCreated:()=>p()}),e.jsx(_t,{property:R,open:!!R,onOpenChange:n=>{n||A(null)},onSaved:()=>p()}),e.jsx(ct,{open:!!v,onOpenChange:n=>{n||F(null)},children:e.jsxs(ut,{children:[e.jsxs(ht,{children:[e.jsx(mt,{children:"Remove this property?"}),e.jsxs(xt,{children:[v==null?void 0:v.address_line1," will be archived and removed from your portfolio metrics. You can re-add it later â historical events are preserved."]})]}),e.jsxs(pt,{children:[e.jsx(gt,{disabled:P,children:"Cancel"}),e.jsx(jt,{disabled:P,onClick:n=>{n.preventDefault(),I()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:P?"Removingâ¦":"Remove"})]})]})}),e.jsx(dt,{surface:"my_properties"})]})}export{It 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.