1import{j as e,b as U,r as S,u as C,d as P}from"./query-vendor-CqOtiPNe.js";import{h as m,m as x,A as z,i as f,k as N,l as v,x as K,L as R,B as w,s as y,X as J}from"./index-CgiuONvO.js";import{T as W,a as Y,b as D,c as _}from"./tabs-DhAXdYsK.js";import{B as L}from"./badge-CSzvBtO5.js";import{A as Z,b as ee}from"./avatar-B9y0eyOh.js";import{M as se}from"./mail-dnbKMUvE.js";import{P as te}from"./phone-CCpZm87m.js";import{C as q}from"./calendar-njTWr43i.js";import{M as ae}from"./map-pin-C3B4zHzE.js";import{H as I}from"./house-C9sHcoTX.js";import{F as A}from"./file-text-BqBFGr3S.js";import{D as T}from"./dollar-sign-BoJmMuTa.js";import{I as O}from"./input-oPoHA7Fw.js";import{U as re}from"./upload-B2TjyuSq.js";import{D as ie}from"./download-CVkjVrJo.js";import{T as G}from"./trash-2-XdlKjO4t.js";import{B as ne}from"./building-2-Dhg-JMoH.js";import{u as le}from"./useCurrency-BwCXcmAr.js";import{C as de}from"./credit-card-B4XMcBmh.js";import{C as oe}from"./check-EsNBkSFR.js";import{T as ce}from"./textarea-CxLaKExY.js";import{P as me}from"./plus-DhJDBkeB.js";import{S as xe,D as E}from"./DashboardLayout-bhpyg6kK.js";import{e as ue,a as pe}from"./react-vendor-Oyj1q24G.js";import{A as he}from"./arrow-left-Cg5pwYzI.js";import"./ui-vendor-C92kXd7i.js";import"./chart-vendor-De-uRwFm.js";import"./index-DBVc4pCm.js";import"./use-mobile-Bs-uMLmp.js";import"./separator-BBHmpRWz.js";import"./sheet-Dt5T48FQ.js";import"./skeleton-B97PTBMn.js";import"./tooltip-DukMi9Yb.js";import"./Logo-BMQirxBI.js";import"./calendar-days-BvC5INej.js";import"./users-BKG6ZMTq.js";import"./wrench-BveqLzJ6.js";import"./wifi-off--tLv87Xm.js";import"./message-square-BqIfb2eA.js";import"./panel-top-C_rCNK16.js";import"./log-out-BzS-CLno.js";import"./scroll-area-Cf6pvS46.js";import"./index-BdQq_4o_.js";import"./bell-CJIBHycy.js";import"./check-check-XSobeTl0.js";import"./formatDistanceToNow-DExfhm_y.js";import"./en-US-5rFTtd83.js";import"./LanguageSwitcher-k7A6VFzv.js";import"./dropdown-menu-D-1fS2hr.js";import"./chevron-right-Cl4Mx2Wq.js";import"./circle-QNrbGPhh.js";import"./languages-1QBd6nWm.js";import"./message-circle-C3Kdh8KU.js";import"./activity-DmUxG0fV.js";import"./arrow-down-C4HxAdL9.js";import"./arrow-right-left-tf9Dbt9n.js";import"./arrow-right-CcjvJnjH.js";import"./banknote-wg82AAG7.js";import"./bed--FRu_ZOR.js";import"./list-ordered-CD-hc5AR.js";import"./book-open-check-DeGSCDpn.js";import"./book-open-CkJItcBu.js";import"./brain-QP504LxU.js";import"./building-B1y8ifkf.js";import"./calculator-BuA7e-mZ.js";import"./car-BBeSSily.js";import"./landmark-DVOwzqRj.js";import"./chart-no-axes-column-increasing-DINm0A4J.js";import"./chart-pie-BH1JXQN4.js";import"./chevron-down-C04YKbFY.js";import"./chevron-left-ChhJq7GD.js";import"./chevron-up-YEko4sQ9.js";import"./circle-check-big-B-nqExcc.js";import"./circle-check-DJQ0aRpE.js";import"./message-square-text-CGi8Ghec.js";import"./circle-help-C7Zpw0pA.js";import"./circle-x-BuyswQ-Z.js";import"./clipboard-check-BqHgjlQp.js";import"./clipboard-list-Csw_7fPS.js";import"./clipboard-BrLc9XKt.js";import"./clock-DZbyb8Zh.js";import"./copy-B3hQhSgM.js";import"./database-BFqeg3FR.js";import"./zoom-out-CZzr-t9-.js";import"./external-link-DLbL3mEn.js";import"./twitter-DZP3beY2.js";import"./file-chart-column-increasing-B5g6evDe.js";import"./file-check-2P_f7S4-.js";import"./file-spreadsheet-BbKDqPhp.js";import"./filter-DOTkE5Cb.js";import"./folder-open-CQAcdSBr.js";import"./tree-pine-BPQJJftn.js";import"./globe-CnUNDEKq.js";import"./video-CEw6mOAP.js";import"./hammer-wk7AQWqX.js";import"./heart-BnQgcucT.js";import"./hotel-GOTEiWOT.js";import"./image-plus-DfX-_AyQ.js";import"./image-DrO_YHf9.js";import"./infinity-BeOXN0LM.js";import"./key-round-Cl3pyXjD.js";import"./pen-tool-ErvG_pvg.js";import"./keyboard-CzV9enBr.js";import"./layers-BFQ0OLI3.js";import"./lightbulb-IBP3Qpkq.js";import"./list-checks-CsRR_GQp.js";import"./list-Cj3mFARp.js";import"./lock-rMWs3zu_.js";import"./map-pinned-DBhEITMu.js";import"./map-Dml-fuwB.js";import"./maximize-2-BAo6X0VP.js";import"./maximize-DllRQL4I.js";import"./menu-B6QavzjZ.js";import"./minus-BWhsihkF.js";import"./mouse-pointer-click-BX0OFv2U.js";import"./mouse-z7gxK0yj.js";import"./navigation-CE5W2bfp.js";import"./pause-DMf9J0er.js";import"./pencil-s0UamddO.js";import"./ruler-PMZpHEX4.js";import"./play-jGttOVZX.js";import"./printer-DPItEGKX.js";import"./refresh-ccw-D8-NZbc0.js";import"./rocket-o5dk1x7z.js";import"./rotate-ccw-D5LvpNON.js";import"./rotate-cw-qBQXdDzU.js";import"./route-BHkgA-GC.js";import"./save-CD5NOpBU.js";import"./scale-ChbaOrX5.js";import"./search-CT8fLn3_.js";import"./send-Dev9pED3.js";import"./share-2-CZ8fruyy.js";import"./square-plus-BYoTN96c.js";import"./skip-forward-B2g28Adz.js";import"./smartphone-BVaS8Ogf.js";import"./square-check-big-S7f3xHqK.js";import"./square-pen-Cd8FE6iD.js";import"./square-DpPlSXOl.js";import"./star-DgTF5ai2.js";import"./trending-down-BOTbmgUi.js";import"./trending-up-BVHf_RoK.js";import"./user-check-DLa2T6BS.js";import"./user-C4n8hF8r.js";import"./volume-2-CyzFl9Wm.js";import"./volume-x-DwUdAb_B.js";import"./wallet-DFZjOwp1.js";import"./workflow-eRF_Iozj.js";import"./zap-CZwSyBya.js";import"./useIsRTL-CvXztNyx.js";import"./useOrganization-BfvJJCCq.js";function je({tenant:a}){var n,s,l,o,u;const d=p=>{switch(p){case"active":return"bg-green-500";
1case"pending":return"bg-yellow-500";case"expired":return"bg-red-500";case"terminated":return"bg-gray-500";default:return"bg-gray-400"}},r=p=>p.split(" ").map(i=>i[0]).join("").toUpperCase().slice(0,2);return e.jsx(m,{children:e.jsx(x,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row items-start md:items-center gap-4",children:[e.jsx(Z,{className:"h-20 w-20",children:e.jsx(ee,{className:"bg-primary text-primary-foreground text-2xl",children:r(a.full_name)})}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-2xl font-bold",children:a.full_name}),e.jsx(L,{className:`${d(((n=a.lease)==null?void 0:n.status)||"none")} text-white`,children:((s=a.lease)==null?void 0:s.status)||"No Lease"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2 text-sm text-muted-foreground",children:[a.email&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{children:a.email})]}),a.phone&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4"}),e.jsx("span",{children:a.phone})]}),((l=a.lease)==null?void 0:l.start_date)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),e.jsxs("span",{children:["Lease Start: ",new Date(a.lease.start_date).toLocaleDateString()]})]}),((o=a.lease)==null?void 0:o.unit)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4"}),e.jsxs("span",{children:[a.lease.unit.unit_number," - ",(u=a.lease.unit.property)==null?void 0:u.name]})]})]})]})]})})})}function fe({tenantId:a}){const{tenants:d}=z(),r=d.find(n=>n.id===a);return r?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Lease Information"]}),e.jsx(v,{children:"Current lease details"})]}),e.jsx(x,{className:"space-y-3",children:r.lease?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Start Date:"}),e.jsx("span",{className:"font-medium",children:new Date(r.lease.start_date).toLocaleDateString()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"End Date:"}),e.jsx("span",{className:"font-medium",children:new Date(r.lease.end_date).toLocaleDateString()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Monthly Rent:"}),e.jsxs("span",{className:"font-medium",children:["$",Number(r.lease.monthly_rent).toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Security Deposit:"}),e.jsxs("span",{className:"font-medium",children:["$",Number(r.lease.security_deposit).toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status:"}),e.jsx("span",{className:"font-medium capitalize",children:r.lease.status})]})]}):e.jsx("p",{className:"text-muted-foreground",children:"No active lease"})})]}),e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-5 w-5"}),"Contact Information"]}),e.jsx(v,{children:"Tenant contact details"})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Email:"}),e.jsx("span",{className:"font-medium",children:r.email||"Not provided"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Phone:"}),e.jsx("span",{className:"font-medium",children:r.phone||"Not provided"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Full Name:"}),e.jsx("span",{className:"font-medium",children:r.full_name})]})]})]}),r.lease&&e.jsxs(e.Fragment,{children:[e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),"Lease Duration"]}),e.jsx(v,{children:"Time remaining on lease"})]}),e.jsx(x,{children:e.jsx("div",{className:"space-y-2",children:(()=>{const n=new Date(r.lease.start_date),s=new Date(r.lease.end_date),l=new Date,o=Math.floor((s.getTime()-n.getTime())/(1e3*60*60*24)),u=Math.floor((s.getTime()-l.getTime())/(1e3*60*60*24)),p=Math.max(0,Math.min(100,(o-u)/o*100));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Progress:"}),e.jsxs("span",{className:"font-medium",children:[Math.round(p),"%"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:"bg-primary h-2 rounded-full transition-all",style:{width:`${p}%`}})}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Days Remaining:"}),e.jsxs("span",{className:"font-medium",children:[u>0?u:0," days"]})]})]})})()})})]}),e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-5 w-5"}),"Payment Summary"]}),e.jsx(v,{children:"Financial overview"})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total Rent:"}),e.jsxs("span",{className:"font-medium",children:["$",Number(r.lease.monthly_rent*12).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Payment Method:"}),e.jsx("span",{className:"font-medium",children:"Bank Transfer"})]})]})]})]})]}):null}function Ne({tenantId:a}){const{toast:d}=K(),r=U(),[n,s]=S.useState(!1),[l,o]=S.useState(""),[u,p]=S.useState("lease"),{data:i}=C({queryKey:["tenant-lease",a],queryFn:async()=>{const{data:j,error:g}=await y.from("leases").select("id").eq("tenant_id",a).maybeSingle();if(g)throw g;return j}}),{data:c,isLoading:t}=C({queryKey:["tenant-documents",a,i==null?void 0:i.id],queryFn:async()=>{if(!(i!=null&&i.id))return[];const{data:j,error:g}=await y.from("documents").select("*").eq("lease_id",i.id);if(g)throw g;return j||[]},enabled:!!(i!=null&&i.id)}),h=async j=>{var $;const g=($=j.target.files)==null?void 0:$[0];if(!g||!l){d({title:"Error",description:"Please provide a title and select a file",variant:"destructive"});return}s(!0);try{const F=g.name.split(".").pop(),V=`${Math.random()}.${F}`,B=`tenant-documents/${a}/${V}`,{error:Q}=await y.storage.from("lease-documents").upload(B,g);if(Q)throw Q;const{data:{publicUrl:X}}=y.storage.from("lease-documents").getPublicUrl(B),{data:M}=await y.from("leases").select("id").eq("tenant_id",a).maybeSingle(),{data:{user:k}}=await y.auth.getUser(),{error:H}=await y.from("documents").insert({title:l,category:u,file_url:X,file_name:g.name,file_size:g.size,lease_id:M==null?void 0:M.id,uploaded_by:k==null?void 0:k.id});if(H)throw H;d({title:"Success",description:"Document uploaded successfully"}),o(""),r.invalidateQueries({queryKey:["tenant-documents",a]})}catch(F){d({title:"Error",description:F.message,variant:"destructive"})}finally{s(!1)}},b=P({mutationFn:async j=>{const{error:g}=await y.from("documents").delete().eq("id",j);if(g)throw g},onSuccess:()=>{d({title:"Success",description:"Document deleted successfully"}),r.invalidateQueries({queryKey:["tenant-documents",a]})}});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-5 w-5"}),"Upload Document"]}),e.jsx(v,{children:"Add documents for this tenant"})]}),e.jsx(x,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"title",children:"Document Title"}),e.jsx(O,{id:"title",value:l,onChange:j=>o(j.target.value),placeholder:"e.g., Lease Agreement"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"file",children:"Select File"}),e.jsx(O,{id:"file",type:"file",onChange:h,disabled:n})]})]})})]}),e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-5 w-5"}),"Documents"]}),e.jsx(v,{children:"All documents for this tenant"})]}),e.jsx(x,{children:t?e.jsx("div",{className:"text-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"})}):c&&c.length>0?e.jsx("div",{className:"space-y-2",children:c.map(j=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:j.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j.file_name})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"outline",size:"sm",onClick:()=>window.open(j.file_url,"_blank"),children:e.jsx(ie,{className:"h-4 w-4"})}),e.jsx(w,{variant:"destructive",size:"sm",onClick:()=>b.mutate(j.id),children:e.jsx(G,{className:"h-4 w-4"})})]})]},j.id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No documents uploaded yet"})})]})]})}function ge({tenantId:a}){var o,u;const{tenants:d}=z(),r=d.find(p=>p.id===a);if(!(r!=null&&r.lease))return e.jsx(m,{children:e.jsx(x,{className:"py-12 text-center text-muted-foreground",children:"No active lease found for this tenant"})});const n=r.lease,s=(o=n.unit)==null?void 0:o.property,l=n.unit;return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5"}),"Property Details"]}
1),e.jsx(v,{children:"Information about the property"})]}),e.jsx(x,{className:"space-y-3",children:s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Property Name"}),e.jsx("p",{className:"font-medium",children:s.name})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Address"}),e.jsx("p",{className:"font-medium",children:s.address})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Property Type"}),e.jsx("p",{className:"font-medium capitalize",children:(u=s.property_type)==null?void 0:u.replace("_"," ")})]})]}):e.jsx("p",{className:"text-muted-foreground",children:"Property information not available"})})]}),e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Unit Details"]}),e.jsx(v,{children:"Information about the unit"})]}),e.jsx(x,{className:"space-y-3",children:l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Unit Number"}),e.jsx("p",{className:"font-medium",children:l.unit_number})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status"}),e.jsx(L,{variant:l.status==="occupied"?"default":"secondary",children:l.status})]}),l.bedrooms&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Bedrooms"}),e.jsx("p",{className:"font-medium",children:l.bedrooms})]}),l.bathrooms&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Bathrooms"}),e.jsx("p",{className:"font-medium",children:l.bathrooms})]}),l.square_feet&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Square Feet"}),e.jsxs("p",{className:"font-medium",children:[Number(l.square_feet).toLocaleString()," sq ft"]})]})]}):e.jsx("p",{className:"text-muted-foreground",children:"Unit information not available"})})]}),e.jsxs(m,{className:"md:col-span-2",children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),"Lease Timeline"]}),e.jsx(v,{children:"Lease duration and key dates"})]}),e.jsx(x,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Start Date"}),e.jsx("p",{className:"font-medium",children:new Date(n.start_date).toLocaleDateString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"End Date"}),e.jsx("p",{className:"font-medium",children:new Date(n.end_date).toLocaleDateString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Lease Status"}),e.jsx(L,{variant:"default",className:"capitalize",children:n.status})]})]}),e.jsx("div",{className:"mt-6",children:(()=>{const p=new Date(n.start_date),i=new Date(n.end_date),c=new Date,t=Math.floor((i.getTime()-p.getTime())/(1e3*60*60*24)),h=Math.floor((c.getTime()-p.getTime())/(1e3*60*60*24)),b=Math.max(0,Math.min(100,h/t*100));return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Progress: ",Math.round(b),"%"]}),e.jsxs("span",{children:[Math.max(0,t-h)," days remaining"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-3",children:e.jsx("div",{className:"bg-primary h-3 rounded-full transition-all",style:{width:`${b}%`}})})]})})()})]})})]})]})}function ye({tenantId:a}){const{toast:d}=K(),r=U(),{formatCurrency:n}=le(),{data:s,isLoading:l}=C({queryKey:["tenant-payments",a],queryFn:async()=>{const{data:t,error:h}=await y.from("payments").select("*").eq("tenant_id",a).order("due_date",{ascending:!1});if(h)throw h;return t||[]}}),o=P({mutationFn:async({paymentId:t,status:h})=>{const{error:b}=await y.from("payments").update({status:h,paid_date:h==="paid"?new Date().toISOString().split("T")[0]:null}).eq("id",t);if(b)throw b},onSuccess:()=>{d({title:"Payment updated",description:"Payment status has been updated successfully."}),r.invalidateQueries({queryKey:["tenant-payments",a]}),r.invalidateQueries({queryKey:["payments"]})},onError:t=>{d({title:"Error",description:t.message||"Failed to update payment",variant:"destructive"})}}),u=t=>{switch(t){case"paid":return"bg-green-500";
1case"pending":return"bg-yellow-500";case"late":return"bg-red-500";case"overdue":return"bg-red-700";default:return"bg-gray-500"}},p=(s==null?void 0:s.filter(t=>t.status==="paid").reduce((t,h)=>t+Number(h.amount),0))||0,i=(s==null?void 0:s.filter(t=>t.status==="pending").reduce((t,h)=>t+Number(h.amount),0))||0,c=(s==null?void 0:s.filter(t=>t.status==="overdue"||t.status==="late").reduce((t,h)=>t+Number(h.amount),0))||0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs(m,{children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(N,{className:"text-sm font-medium",children:"Total Paid"}),e.jsx(T,{className:"h-4 w-4 text-green-600"})]}),e.jsx(x,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:n(p)})})]}),e.jsxs(m,{children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(N,{className:"text-sm font-medium",children:"Pending"}),e.jsx(T,{className:"h-4 w-4 text-yellow-600"})]}),e.jsx(x,{children:e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:n(i)})})]}),e.jsxs(m,{children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(N,{className:"text-sm font-medium",children:"Overdue"}),e.jsx(T,{className:"h-4 w-4 text-red-600"})]}),e.jsx(x,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:n(c)})})]})]}),e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-5 w-5"}),"Payment History"]}),e.jsx(v,{children:"Click the buttons to mark payments as paid or pending"})]}),e.jsx(x,{children:l?e.jsx("div",{className:"text-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"})}):s&&s.length>0?e.jsx("div",{className:"space-y-3",children:s.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(q,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:n(Number(t.amount))}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Due: ",new Date(t.due_date).toLocaleDateString()]}),t.paid_date&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Paid: ",new Date(t.paid_date).toLocaleDateString()]}),t.notes&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.notes})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(L,{className:`${u(t.status)} text-white`,children:t.status}),e.jsx("div",{className:"flex gap-1",children:t.status!=="paid"?e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>o.mutate({paymentId:t.id,status:"paid"}),disabled:o.isPending,className:"text-green-600 hover:text-green-700 hover:bg-green-50",children:[e.jsx(oe,{className:"h-4 w-4 mr-1"}),"Mark Paid"]}):e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>o.mutate({paymentId:t.id,status:"pending"}),disabled:o.isPending,className:"text-yellow-600 hover:text-yellow-700 hover:bg-yellow-50",children:[e.jsx(J,{className:"h-4 w-4 mr-1"}),"Mark Unpaid"]})})]})]},t.id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No payment records found"})})]})]})}function ve({tenantId:a}){const{toast:d}=K(),r=U(),[n,s]=S.useState(""),{data:l,isLoading:o}=C({queryKey:["tenant-notes",a],queryFn:async()=>{const{data:i,error:c}=await y.from("client_notes").select("*").eq("client_id",a).order("created_at",{ascending:!1});if(c&&c.code!=="PGRST116")throw c;return i||[]}}),u=P({mutationFn:async()=>{const{data:{user:i}}=await y.auth.getUser();if(!i)throw new Error("Not authenticated");const{error:c}=await y.from("client_notes").insert({client_id:a,agent_id:i.id,content:n});if(c)throw c},onSuccess:()=>{d({title:"Success",description:"Note added successfully"}),s(""),r.invalidateQueries({queryKey:["tenant-notes",a]})},onError:i=>{d({title:"Error",description:i.message,variant:"destructive"})}}),p=P({mutationFn:async i=>{const{error:c}=await y.from("client_notes").delete().eq("id",i);if(c)throw c},onSuccess:()=>{d({title:"Success",description:"Note deleted successfully"}),r.invalidateQueries({queryKey:["tenant-notes",a]})}});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-5 w-5"}),"Add Note"]}),e.jsx(v,{children:"Keep track of important information about this tenant"})]}),e.jsxs(x,{className:"space-y-4",children:[e.jsx(ce,{placeholder:"Enter your note here...",value:n,onChange:i=>s(i.target.value),rows:4}),e.jsx(w,{onClick:()=>u.mutate(),disabled:!n.trim()||u.isPending,children:"Add Note"})]})]}),e.jsxs(m,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5"}),"Notes History"]}),e.jsx(v,{children:"All notes for this tenant"})]}),e.jsx(x,{children:o?e.jsx("div",{className:"text-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"})}):l&&l.length>0?e.jsx("div",{className:"space-y-3",children:l.map(i=>e.jsx("div",{className:"p-4 border rounded-lg hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"whitespace-pre-wrap",children:i.content}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:new Date(i.created_at).toLocaleStr
1ing()})]}),e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>p.mutate(i.id),children:e.jsx(G,{className:"h-4 w-4 text-destructive"})})]})},i.id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No notes yet. Add your first note above."})})]})]})}function ca(){const{tenantId:a}=ue(),d=pe(),{tenants:r,isLoading:n}=z(),s=r.find(l=>l.id===a);return n?e.jsx(E,{className:"flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):s?e.jsxs(E,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>d("/tenants"),className:"p-0 h-auto",children:"Tenant Management"}),e.jsx("span",{children:"/"}),e.jsx("span",{className:"text-foreground",children:s.full_name})]}),e.jsx(je,{tenant:s}),e.jsxs(W,{defaultValue:"overview",className:"w-full",children:[e.jsxs(Y,{className:"flex w-full md:grid md:grid-cols-5",children:[e.jsx(D,{value:"overview",children:"Overview"}),e.jsx(D,{value:"lease",children:"Lease & Property"}),e.jsx(D,{value:"payments",children:"Payments"}),e.jsx(D,{value:"documents",children:"Documents"}),e.jsx(D,{value:"notes",children:"Notes"})]}),e.jsx(_,{value:"overview",className:"space-y-4",children:e.jsx(fe,{tenantId:s.id})}),e.jsx(_,{value:"lease",className:"space-y-4",children:e.jsx(ge,{tenantId:s.id})}),e.jsx(_,{value:"payments",className:"space-y-4",children:e.jsx(ye,{tenantId:s.id})}),e.jsx(_,{value:"documents",className:"space-y-4",children:e.jsx(Ne,{tenantId:s.id})}),e.jsx(_,{value:"notes",className:"space-y-4",children:e.jsx(ve,{tenantId:s.id})})]})]}):e.jsx(E,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx("h2",{className:"text-2xl font-bold mb-2",children:"Tenant not found"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"The tenant you're looking for doesn't exist."}),e.jsxs(w,{onClick:()=>d("/tenants"),children:[e.jsx(he,{className:"h-4 w-4 mr-2"}),"Back to Tenants"]})]})})}export{ca 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.