PageSourceSearch

https://reamintell.com/assets/StorageUnitsTab-C-A8428Q.js

js reamintell.com collected 2026-10-02 16:15:02 UTC 67,807 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-grid-ClmSNH6q.js";import{af as Se,aW as f,X as Fe,w as we,aT as kt,o as Ke,P as Ct,a5 as Pt,b as $t,z as Tt,aY as Je,$ as at,Q as mt,a$ as nt,C as rt,bz as Et}from"./index-DBBMBrQC.js";import{P as Mt}from"./PlanLimitModal-DRNymVUT.js";import{r as n}from"./vendor-charts-B2bLUVVL.js";import{b as G}from"./Card-BUL_z2x0.js";import{B as Le}from"./Badge-CFTtQM9N.js";import{U as Ge}from"./user-plus-DJtDatMs.js";import{K as xt}from"./key-BTvxHLKH.js";import{r as At,u as je,w as It}from"./xlsx-BQptaUDQ.js";import{F as Ut}from"./file-spreadsheet-BTGE79-e.js";import{A as Ot}from"./arrow-up-down-Dy-uDL-z.js";import"./api-Do_Y5Oyv.js";import"./circle-arrow-up-CX7gjgSv.js";const lt=[{value:"month-to-month",label:"Month-to-Month",months:0},{value:"3-month",label:"3 Months",months:3},{value:"6-month",label:"6 Months",months:6},{value:"annual",label:"12 Months (Annual)",months:12}];function it(){return String(Math.floor(1e3+Math.random()*9e3))}function Rt(m,w){const _=new Date(m);return _.setMonth(_.getMonth()+w),_.toISOString().slice(0,10)}const Ie=" https://reamintell.com";function Ue(){return{"x-api-key":Ke(),"Content-Type":"application/json"}}function Ft({propertyId:m,propertyName:w,unitNumber:_,unitId:b,unitType:Q,monthlyRent:S,sqFt:E,isClimateControlled:M,onClose:I,onSuccess:Y}){const A=n.useRef(!1),[q,se]=n.useState(!1),[ae,C]=n.useState(""),[d,F]=n.useState(!1),[pe,c]=n.useState(null),[$,U]=n.useState("idle"),[O,V]=n.useState(""),H=new Date().toISOString().slice(0,10),[x,k]=n.useState({tenant_name:"",tenant_email:"",tenant_phone:"",term:"month-to-month",start_date:H,monthly_rent:S,security_deposit:S,access_code:it(),insurance_required:!1}),[X,Z]=n.useState([]),J=(()=>
1{const a=lt.find(r=>r.value===x.term);return!a||a.months===0?"":Rt(x.start_date,a.months)})(),ne=async a=>{var r;if(a.preventDefault(),!A.current){A.current=!0,C(""),se(!0);try{if(!x.tenant_name.trim())throw new Error("Tenant name is required");if(!x.tenant_email.trim())throw new Error("Tenant email is required");if(!x.start_date)throw new Error("Start date is required");const y={property_id:m,unit_number:_,tenant_id:void 0,lease_type:"commercial",start_date:x.start_date,end_date:J||void 0,monthly_rent_cents:Math.round(x.monthly_rent*100),security_deposit_cents:Math.round(x.security_deposit*100),status:"active",insurance_required:x.insurance_required?1:0,tenants:[{full_name:x.tenant_name,email:x.tenant_email,phone:x.tenant_phone||void 0},...X.filter(L=>L.full_name.trim()&&L.email.trim())]},T=await fetch(`${Ie}/api/leases/create`,{method:"POST",headers:Ue(),body:JSON.stringify(y)}),h=await T.json();if(!T.ok)throw new Error(h.error||"Failed to create lease");const W=((r=h==null?void 0:h.lease)==null?void 0:r.tenant_id)??(h==null?void 0:h.tenant_id)??(h==null?void 0:h.primary_tenant_id)??null;if(c(W),!x.tenant_email.trim())U("no-email");else if(W)try{const L=await fetch(`${Ie}/api/tenants/portal-status?tenant_id=${W}`,{headers:Ue()});L.ok&&(await L.json()).has_portal_account&&U("already-has-access")}catch{}x.access_code&&await fetch(`${Ie}/api/units/update`,{method:"PUT",headers:Ue(),body:JSON.stringify({unit_id:b,property_id:m,access_code:x.access_code,status:"occupied"})}).catch(()=>{}),F(!0)}catch(y){C(y.message||"Failed to create lease")}finally{se(!1),A.current=!1}}},ie=async()=>{if(!pe){U("error"),V("No tenant id captured — cannot send invite.");return}if(!x.tenant_email.trim()){U("no-email");return}U("inviting");try{const a=await fetch(`${Ie}/api/tenant-portal/auth/invite`,{method:"POST",headers:Ue(),body:JSON.stringify({tenant_id:pe})}),r=await a.json();if(!a.ok)throw new Error((r==null?void 0:r.error)||`Invite failed (${a.status})`);U(r.already_linked||r.existing_account?"already-has-access":"sent"),V(r.message||"")}catch(a){U("error"),V((a==null?void 0:a.message)||"Invite failed")}};return d?e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-white rounded-lg max-w-md w-full overflow-hidden",children:e.jsxs("div",{className:"px-6 py-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Se,{className:"w-8 h-8 text-green-600"})}),e.jsx("h3",{className:"text-xl font-bold text-gray-900 mb-1",children:"Lease Started"}),e.jsxs("p",{className:"text-sm text-gray-600 mb-5",children:[x.tenant_name," now has an active lease on Unit ",_,"."]}),e.jsxs("div",{className:"bg-gray-50 rounded-xl p-4 mb-5",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Gate Access PIN"}),e.jsx("p",{className:"text-3xl font-mono font-bold tracking-[0.3em] text-brand-navy",children:x.access_code||"----"})]}),$==="sent"&&e.jsxs("div",{className:"p-3 bg-green-50 border border-green-200 rounded-lg text-sm text-green-800 mb-4",children:["Portal invite sent to ",x.tenant_email,". They can sign in to pay rent, view their unit, and submit maintenance."]}),$==="already-has-access"&&e.jsxs("div",{className:"p-3 bg-blue-50 border border-blue-200 rounded-lg text-sm text-blue-800 mb-4",children:["This tenant already has a portal account. Unit ",_," will appear in their portal automatically."]}),$==="no-email"&&e.jsx("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded-lg text-sm text-amber-800 mb-4",children:"No email on file — add one later to send a portal invite."}),$==="error"&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700 mb-4",children:O||"Could not send portal invite."}),e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{Y()},children:"Close"}),$==="idle"&&e.jsx(f,{variant:"primary",size:"sm",icon:e.jsx(Ge,{className:"w-4 h-4"}),onClick:ie,children:"Invite to Portal"}),$==="inviting"&&e.jsx(f,{variant:"primary",size:"sm",loading:!0,disabled:!0,children:"Inviting..."}),($==="sent"||$==="already-has-access"||$==="no-email"||$==="error")&&e.jsx(f,{variant:"primary",size:"sm",icon:e.jsx(Se,{className:"w-4 h-4"}),onClick:()=>{Y()},children:"Done"})]})]})})}):e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg max-w-lg w-full max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:["Lease Unit ",_]}),e.jsxs("p",{className:"text-sm text-gray-500",children:[w," · ",Q," · ",E," sqft",M?" · Climate":""]})]}),e.jsx("button",{onClick:I,className:"text-gray-400 hover:text-gray-600",children:e.jsx(Fe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:ne,className:"px-6 py-4 overflow-y-auto flex-1 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Tenant Name *"}),e.jsx("input",{type:"text",required:!0,value:x.tenant_name,onChange:a=>k(r=>({...r,tenant_name:a.target.value})),placeholder:"Full legal name",className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Email *"}),e.jsx("input",{type:"email",required:!0,value:x.tenant_email,onChange:a=>k(r=>({...r,tenant_email:a.target.value})),placeholder:"[email protected]",className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Phone"}),e.jsx("input",{type:"tel",value:x.tenant_phone,onChange:a=>k(r=>({...r,tenant_phone:a.target.value})),placeholder:"(555) 123-4567",className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]})]}),e.jsxs("div",{className:"border-t border-gray-100 pt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700",children:"Co-Tenants (optional)"}),e.jsxs("button",{type:"button",onClick:()=>Z(a=>[...a,{full_name:"",email:""}]),className:"text-xs text-brand-navy hover:underline flex items-center gap-1",children:[e.jsx(we,{className:"w-3 h-3"})," Add"]})]}),X.map((a,r)=>
1e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{type:"text",value:a.full_name,placeholder:"Name",onChange:y=>{const T=[...X];T[r].full_name=y.target.value,Z(T)},className:"flex-1 px-2 py-1.5 border border-gray-300 rounded text-sm"}),e.jsx("input",{type:"email",value:a.email,placeholder:"Email",onChange:y=>{const T=[...X];T[r].email=y.target.value,Z(T)},className:"flex-1 px-2 py-1.5 border border-gray-300 rounded text-sm"}),e.jsx("button",{type:"button",onClick:()=>Z(y=>y.filter((T,h)=>h!==r)),className:"text-red-400 hover:text-red-600",children:e.jsx(kt,{className:"w-4 h-4"})})]},r))]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Lease Term"}),e.jsx("select",{value:x.term,onChange:a=>k(r=>({...r,term:a.target.value})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent",children:lt.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Start Date *"}),e.jsx("input",{type:"date",required:!0,value:x.start_date,onChange:a=>k(r=>({...r,start_date:a.target.value})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]})]}),J&&e.jsxs("p",{className:"text-xs text-gray-500 -mt-2",children:["End date: ",e.jsx("strong",{children:new Date(J).toLocaleDateString()})," (auto-calculated)"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Monthly Rent ($) *"}),e.jsx("input",{type:"number",required:!0,min:"1",value:x.monthly_rent,onChange:a=>k(r=>({...r,monthly_rent:Number(a.target.value)})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Security Deposit ($)"}),e.jsx("input",{type:"number",min:"0",value:x.security_deposit,onChange:a=>k(r=>({...r,security_deposit:Number(a.target.value)})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Gate Access PIN"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(xt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:x.access_code,maxLength:6,onChange:a=>k(r=>({...r,access_code:a.target.value})),className:"w-full pl-9 pr-3 py-2 border border-gray-300 rounded-lg text-sm font-mono tracking-widest focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]}),e.jsx("button",{type:"button",onClick:()=>k(a=>({...a,access_code:it()})),className:"px-3 py-2 text-xs font-medium text-brand-navy border border-brand-navy/30 rounded-lg hover:bg-brand-navy/5",children:"Regenerate"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:x.insurance_required,onChange:a=>k(r=>({...r,insurance_required:a.target.checked})),className:"rounded border-gray-300 text-brand-navy focus:ring-brand-navy"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Require renter's insurance (enrolled via tenant portal)"})]}),ae&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:ae})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-200 flex justify-between items-center",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:["Unit ",_," · $",x.monthly_rent,"/mo"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:I,disabled:q,children:"Cancel"}),e.jsx(f,{variant:"primary",size:"sm",loading:q,onClick:ne,children:"Start Lease"})]})]})]})})}const _e=" https://reamintell.com";function Ne(){return{"x-api-key":Ke(),"Content-Type":"application/json"}}function Lt(){return String(Math.floor(1e3+Math.random()*9e3))}function zt({propertyId:m,propertyName:w,onClose:_,onSuccess:b}){const Q=n.useRef(!1),S=n.useRef(null),[E,M]=n.useState(""),[I,Y]=n.useState(""),[A,q]=n.useState(""),[se,ae]=n.useState(!1),[C,d]=n.useState(null),[F,pe]=n.useState([]),[c,$]=n.useState(null),[U,O]=n.useState(!0),[V,H]=n.useState(!1),[x,k]=n.useState(Lt()),[X,Z]=n.useState(!1),[J,ne]=n.useState(""),[ie,a]=n.useState(null),[r,y]=n.useState("idle"),[T,h]=n.useState("");n.useEffect(()=>{var i;(i=S.current)==null||i.focus()},[]),n.useEffect(()=>{(async()=>{try{const N=await(await fetch(`${_e}/api/units/list?property_id=${m}&status=vacant&limit=500`,{headers:Ne()})).json();pe((N.units||[]).filter(g=>g.status==="vacant"))}catch{}finally{O(!1)}})()},[m]),n.useEffect(()=>{if(E.replace(/\D/g,"").length<7){ae(!1),d(null);return}const i=setTimeout(async()=>{try{const p=((await(await fetch(`${_e}/api/tenants/recent?q=${encodeURIComponent(E)}&limit=1`,{headers:Ne()})).json()).tenants||[])[0];p?(d({tenant_id:p.tenant_id,full_name:p.full_name,email:p.email||""}),I||Y(p.full_name||""),A||q(p.email||"")):d(null)}catch{}ae(!0)},400);return()=>clearTimeout(i)},[E]);const W=async()=>{var i;if(!Q.current){Q.current=!0,ne(""),H(!0);try{if(!I.trim())throw new Error("Name is required");if(!c)throw new Error("Select a unit");const N={property_id:m,unit_number:c.unit_number,lease_type:"commercial",start_date:new Date().toISOString().slice(0,10),monthly_rent_cents:Math.round(c.monthly_rent*100),security_deposit_cents:Math.round(c.monthly_rent*100),status:"active",tenants:[{full_name:I.trim(),email:A.trim()||void 0,phone:E.trim()||void 0}]},g=await fetch(`${_e}/api/leases/create`,{method:"POST",headers:Ne(),body:JSON.stringify(N)}),p=await g.json();if(!g.ok)throw new Error(p.error||"Failed to create lease");const fe=((i=p==null?void 0:p.lease)==null?void 0:i.tenant_id)??(p==null?void 0:p.tenant_id)??(p==null?void 0:p.primary_tenant_id)??(C==null?void 0:C.tenant_id)??null;if(a(fe),!A.trim())y("no-email");else if((C==null?void 0:C.tenant_id)===fe)try{const ke=await fetch(`${_e}/api/tenants/portal-status?tenant_id=${fe}`,{headers:Ne()});ke.ok&&(await ke.json()).has_portal_account&&y("already-has-access")}catch{}await fetch(`${_e}/api/units/update`,{method:"PUT",headers:Ne(),body:JSON.stringify({unit_id:c.unit_id,property_id:m,access_code:x,status:"occupied"})}).catch(()=>{}),Z(!0)}catch(N){ne(N.message||"Failed")}finally{H(!1),Q.current=!1}}},L=async()=>
1{if(!ie){y("error"),h("No tenant id captured — cannot send invite.");return}if(!A.trim()){y("no-email");return}y("inviting");try{const i=await fetch(`${_e}/api/tenant-portal/auth/invite`,{method:"POST",headers:Ne(),body:JSON.stringify({tenant_id:ie})}),N=await i.json();if(!i.ok)throw new Error((N==null?void 0:N.error)||`Invite failed (${i.status})`);N.already_linked||N.existing_account?y("already-has-access"):y("sent"),h(N.message||"")}catch(i){y("error"),h((i==null?void 0:i.message)||"Invite failed")}};return X?e.jsx("div",{className:"fixed inset-0 bg-white z-50 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md px-6",children:[e.jsx("div",{className:"w-20 h-20 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-6",children:e.jsx(Se,{className:"w-10 h-10 text-green-600"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Unit Rented!"}),e.jsxs("p",{className:"text-gray-600 mb-6",children:[I," now has access to Unit ",c==null?void 0:c.unit_number," at ",w,"."]}),e.jsxs("div",{className:"bg-gray-50 rounded-xl p-6 mb-6",children:[e.jsx("p",{className:"text-sm text-gray-500 mb-1",children:"Gate Access PIN"}),e.jsx("p",{className:"text-4xl font-mono font-bold tracking-[0.3em] text-brand-navy",children:x})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm text-left bg-gray-50 rounded-xl p-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Tenant"}),e.jsx("p",{className:"font-medium",children:I})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Unit"}),e.jsxs("p",{className:"font-medium",children:[c==null?void 0:c.unit_number," (",c==null?void 0:c.length_ft,"x",c==null?void 0:c.width_ft,")"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Rent"}),e.jsxs("p",{className:"font-medium",children:["$",c==null?void 0:c.monthly_rent,"/mo"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Term"}),e.jsx("p",{className:"font-medium",children:"Month-to-Month"})]})]}),e.jsxs("div",{className:"mb-4",children:[r==="sent"&&e.jsxs("div",{className:"p-3 bg-green-50 border border-green-200 rounded-lg text-sm text-green-800",children:["Portal invite sent to ",A,". They can sign in to pay rent, view their unit, and submit maintenance."]}),r==="already-has-access"&&e.jsxs("div",{className:"p-3 bg-blue-50 border border-blue-200 rounded-lg text-sm text-blue-800",children:["This tenant already has a portal account. Unit ",c==null?void 0:c.unit_number," will appear in their portal automatically."]}),r==="no-email"&&e.jsx("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded-lg text-sm text-amber-800",children:"No email on file. Add the tenant's email later to send a portal invite — or skip for now."}),r==="error"&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:T||"Could not send portal invite."})]}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx(f,{variant:"outline",onClick:()=>{b(),_()},children:"Close"}),r!=="sent"&&r!=="already-has-access"&&r!=="no-email"&&e.jsx(f,{variant:"primary",icon:e.jsx(Ge,{className:"w-4 h-4"}),loading:r==="inviting",disabled:r==="inviting",onClick:L,children:"Invite to Portal"}),(r==="sent"||r==="already-has-access"||r==="no-email")&&e.jsx(f,{variant:"primary",icon:e.jsx(Se,{className:"w-4 h-4"}),onClick:()=>{b(),_()},children:"Done"})]})]})}):e.jsxs("div",{className:"fixed inset-0 bg-white z-50 flex flex-col",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between bg-brand-navy text-white",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold",children:["Quick Rent — ",w]}),e.jsx("p",{className:"text-sm text-blue-200",children:"Walk-in rental · fill in below · under 60 seconds"})]}),e.jsx("button",{onClick:_,className:"text-white/70 hover:text-white",children:e.jsx(Fe,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-6 py-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-1",children:[e.jsx(Ct,{className:"w-4 h-4 inline mr-1"}),"Phone"]}),e.jsx("input",{ref:S,type:"tel",value:E,onChange:i=>M(i.target.value),placeholder:"(555) 123-4567",className:"w-full px-4 py-3 border-2 border-gray-300 rounded-xl text-lg focus:ring-2 focus:ring-brand-navy focus:border-brand-navy"}),se&&C&&e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"Existing tenant found — info pre-filled"}),se&&!C&&E.replace(/\D/g,"").length>=7&&e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"New tenant"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-1",children:[e.jsx(Pt,{className:"w-4 h-4 inline mr-1"}),"Full Name *"]}),e.jsx("input",{type:"text",value:I,required:!0,onChange:i=>Y(i.target.value),placeholder:"Jane Smith",className:"w-full px-4 py-3 border-2 border-gray-300 rounded-xl text-lg focus:ring-2 focus:ring-brand-navy focus:border-brand-navy"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-1",children:[e.jsx($t,{className:"w-4 h-4 inline mr-1"}),"Email (optional)"]}),e.jsx("input",{type:"email",value:A,onChange:i=>q(i.target.value),placeholder:"[email protected]",className:"w-full px-4 py-3 border-2 border-gray-300 rounded-xl text-lg focus:ring-2 focus:ring-brand-navy focus:border-brand-navy"})]})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-700 mb-3",children:["Select a Unit (",F.length," available)"]}),U?e.jsx("div",{className:"text-center py-8 text-gray-400",children:"Loading units..."}):F.length===0?e.jsx("div",{className:"text-center py-8 text-gray-400",children:"No vacant units available"}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 ga
1p-3",children:F.map(i=>{const N=(c==null?void 0:c.unit_id)===i.unit_id,g=i.is_climate_controlled===1||i.is_climate_controlled===!0;return e.jsxs("button",{type:"button",onClick:()=>$(i),className:`text-left p-3 rounded-xl border-2 transition-all ${N?"border-brand-navy bg-blue-50 ring-2 ring-brand-navy/30":"border-gray-200 hover:border-gray-400 hover:bg-gray-50"}`,children:[e.jsx("p",{className:"font-bold text-gray-900 text-base",children:i.unit_number}),e.jsxs("p",{className:"text-xs text-gray-500 font-mono",children:[i.length_ft,"x",i.width_ft]}),e.jsxs("p",{className:"text-sm font-semibold text-brand-navy mt-1",children:["$",i.monthly_rent,"/mo"]}),e.jsxs("div",{className:"flex gap-1 mt-1 flex-wrap",children:[e.jsx(Le,{variant:"default",size:"sm",children:i.unit_type}),g&&e.jsx(Le,{variant:"info",size:"sm",children:"AC"})]})]},i.unit_id)})})]}),c&&e.jsxs("div",{className:"bg-gray-50 rounded-xl p-5 border border-gray-200",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-700 mb-3",children:"Confirm Rental"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-sm mb-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Unit"}),e.jsx("p",{className:"font-bold text-lg",children:c.unit_number})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Size"}),e.jsxs("p",{className:"font-medium",children:[c.length_ft,"x",c.width_ft," (",c.length_ft*c.width_ft," sqft)"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Monthly Rent"}),e.jsxs("p",{className:"font-bold text-lg text-brand-navy",children:["$",c.monthly_rent]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Access PIN"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xt,{className:"w-4 h-4 text-gray-400"}),e.jsx("p",{className:"font-mono font-bold text-lg tracking-widest",children:x})]})]})]}),J&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700 mb-4",children:J}),e.jsxs(f,{variant:"primary",loading:V,onClick:W,className:"w-full py-3 text-lg",disabled:!I.trim()||!c,children:["Start Lease — $",c.monthly_rent,"/mo"]})]})]})})]})}const he=" https://reamintell.com",Oe=50,ot=[{value:"",label:"All Types"},{value:"standard",label:"Standard"},{value:"climate_controlled",label:"Climate Controlled"},{value:"drive_up",label:"Drive-Up"},{value:"indoor",label:"Indoor"},{value:"locker",label:"Locker"},{value:"vehicle",label:"Vehicle"}],Dt=[{value:"",label:"All Statuses"},{value:"vacant",label:"Vacant"},{value:"occupied",label:"Occupied"},{value:"maintenance",label:"Maintenance"}],Bt=["unit_number","unit_type","length_ft","width_ft","height_ft","monthly_rent"];function ge(){return{"x-api-key":Ke(),"Content-Type":"application/json"}}function Re(m){return m.split("_").map(w=>w.charAt(0).toUpperCase()+w.slice(1)).join(" ")}function qt(m){return m==="climate_controlled"?e.jsx(Et,{className:"w-4 h-4 text-blue-500"}):e.jsx(mt,{className:"w-4 h-4 text-gray-500"})}function We(m){if(m.billing_status==="past_due"&&m.days_past_due)return{variant:"danger",label:`Past Due (${m.days_past_due}d)`};switch(m.status){case"occupied":return{variant:"info",label:"Occupied"};case"vacant":return{variant:"success",label:"Vacant"};case"reserved":return{variant:"warning",label:"Reserved"};case"maintenance":return{variant:"default",label:"Maintenance"};case"pre_lien":return{variant:"danger",label:"Pre-Lien"};default:return{variant:"default",label:m.status.charAt(0).toUpperCase()+m.status.slice(1)}}}function ct(m,w){return String(m).padStart(w,"0")}function as({propertyId:m,propertyType:w,propertyName:_}){const[b,Q]=n.useState([]),[S,E]=n.useState(null),[M,I]=n.useState(0),[Y,A]=n.useState(!0),[q,se]=n.useState(null),[ae,C]=n.useState(null),[d,F]=n.useState({search:"",unit_type:"",status:"",floor_level:"",building_section:""}),[pe,c]=n.useState([]),[$,U]=n.useState([]),[O,V]=n.useState(1),[H,x]=n.useState("unit_number"),[k,X]=n.useState("asc"),[Z,J]=n.useState(!1),[ne,ie]=n.useState(!1),[a,r]=n.useState({prefix:"U",start_number:1,end_number:10,unit_type:"standard",length_ft:10,width_ft:10,height_ft:8,floor_level:"1",building_section:"A",monthly_rent:100,climate_controlled:!1}),[y,T]=n.useState(!1),[h,W]=n.useState(null),L=n.useRef(null),[i,N]=n.useState([]),[g,p]=n.useState(null),[fe,ke]=n.useState(!1),[K,Ce]=n.useState(null),[o,Pe]=n.useState(null),[Qe,Ye]=n.useState(null),[be,ee]=n.useState("unknown"),[ut,ze]=n.useState("");n.useEffect(()=>{if(!o||!o.lease_id){Ye(null),ee("unknown"),ze("");return}(async()=>{var t;try{const s=await fetch(`${he}/api/leases/${o.lease_id}`,{headers:ge()});if(!s.ok){ee("unknown");return}const l=await s.json(),u=((t=l==null?void 0:l.lease)==null?void 0:t.tenant_id)??(l==null?void 0:l.tenant_id)??null;if(Ye(u),!u){ee("unknown");return}const v=await fetch(`${he}/api/tenants/portal-status?tenant_id=${u}`,{headers:ge()});if(v.ok){const P=await v.json();ee(P.has_portal_account?"has-access":"no-access")}else ee("unknown")}catch{ee("unknown")}})()},[o]);const ht=async()=>
1{if(Qe){ee("inviting");try{const t=await fetch(`${he}/api/tenant-portal/auth/invite`,{method:"POST",headers:ge(),body:JSON.stringify({tenant_id:Qe})}),s=await t.json();if(!t.ok)throw new Error((s==null?void 0:s.error)||`Invite failed (${t.status})`);ee(s.already_linked||s.existing_account?"has-access":"sent"),ze(s.message||"")}catch(t){ee("error"),ze((t==null?void 0:t.message)||"Invite failed")}}},[gt,De]=n.useState(!1),[z,$e]=n.useState(null),[D,Be]=n.useState(new Set),[pt,qe]=n.useState(!1),[Ve,Xe]=n.useState(!1),[re,Me]=n.useState({rental_type:"long-term",lease_type:"Month-to-Month",availability_date:new Date().toISOString().slice(0,10),amenities_csv:""}),[te,ye]=n.useState(null),ft=t=>{Be(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},bt=()=>{Be(t=>b.length>0&&b.every(l=>t.has(l.unit_id))?new Set:new Set(b.map(l=>l.unit_id)))},yt=async()=>{if(D.size!==0){Xe(!0),ye(null);try{const t=re.amenities_csv.split(",").map(u=>u.trim()).filter(Boolean),s=await fetch(`${he}/api/listings/publish-bulk`,{method:"POST",headers:ge(),body:JSON.stringify({property_id:m,unit_ids:Array.from(D),defaults:{rental_type:re.rental_type,lease_type:re.lease_type,availability_date:re.availability_date,amenities:t}})}),l=await s.json();s.ok?(ye({published:l.published,errors:l.errors}),Be(new Set)):ye({errors:[{unit_number:"-",error:l.error||"Bulk publish failed"}]})}catch(t){ye({errors:[{unit_number:"-",error:(t==null?void 0:t.message)||String(t)}]})}finally{Xe(!1)}}},oe=n.useCallback(async()=>{var t;A(!0),se(null);try{const s=new URLSearchParams({property_id:m});d.search&&s.set("search",d.search),d.unit_type&&s.set("unit_type",d.unit_type),d.status&&s.set("status",d.status),d.floor_level&&s.set("floor_level",d.floor_level),d.building_section&&s.set("building_section",d.building_section),s.set("page",String(O)),s.set("per_page",String(Oe)),s.set("sort",H),s.set("sort_dir",k);const l=await fetch(`${he}/api/units/list?${s.toString()}`,{headers:ge()});if(!l.ok)throw new Error(`Failed to fetch units (${l.status})`);const u=await l.json();if(u.ok||u.units){if(Q(u.units||[]),I(u.total_count??((t=u.units)==null?void 0:t.length)??0),u.stats&&E(u.stats),u.floor_levels)c(u.floor_levels);else{const v=[...new Set((u.units||[]).map(P=>P.floor_level).filter(Boolean))];c(v.sort())}if(u.building_sections)U(u.building_sections);else{const v=[...new Set((u.units||[]).map(P=>P.building_section).filter(Boolean))];U(v.sort())}}else throw new Error(u.error||"Unknown error loading units")}catch(s){console.error("[StorageUnitsTab] fetch error:",s),se(s.message||"Failed to load storage units")}finally{A(!1)}},[m,d,O,H,k]);n.useEffect(()=>{oe()},[oe]),n.useEffect(()=>{V(1)},[d.search,d.unit_type,d.status,d.floor_level,d.building_section]);const Ze=t=>{H===t?X(s=>s==="asc"?"desc":"asc"):(x(t),X("asc"))},ce=Math.max(0,a.end_number-a.start_number+1),et=Math.max(3,String(a.end_number).length),vt=ce>0?`Will create ${ce} units: ${a.prefix}${ct(a.start_number,et)} - ${a.prefix}${ct(a.end_number,et)}`:"Adjust start/end numbers",jt=async()=>{if(!(ce<=0)){T(!0),W(null);try{const t=await fetch(`${he}/api/units/bulk-create`,{method:"POST",headers:ge(),body:JSON.stringify({property_id:m,...a})}),s=await t.json();s.ok||s.created?(W({success:s.created??ce}),oe()):t.status===402&&s.error==="PLAN_LIMIT_REACHED"?C(s):W({errors:[s.error||"Bulk creation failed"]})}catch(t){W({errors:[t.message||"Network error"]})}finally{T(!1)}}},tt=(t,s)=>{const l=t.map(B=>B.toLowerCase().trim()),u=Bt.filter(B=>!l.includes(B));if(u.length>0){p({total:0,valid:0,errors:[{row:0,message:`Missing required columns: ${u.join(", ")}`}]});return}const v=[],P=[];s.forEach((B,Ae)=>{const j={};Object.entries(B).forEach(([le,ve])=>{j[le.toLowerCase().trim()]=(ve??"").toString().trim()});const R=Ae+2;j.unit_number||P.push({row:R,message:"Missing unit_number"}),j.unit_type||P.push({row:R,message:"Missing unit_type"}),j.length_ft&&isNaN(Number(j.length_ft))&&P.push({row:R,message:"Invalid length_ft"}),j.width_ft&&isNaN(Number(j.width_ft))&&P.push({row:R,message:"Invalid width_ft"}),j.monthly_rent&&isNaN(Number(j.monthly_rent))&&P.push({row:R,message:"Invalid monthly_rent"}),v.push(j)}),N(v),p({total:v.length,valid:v.length-new Set(P.map(B=>B.row)).size,errors:P})},_t=t=>{var v;const s=(v=t.target.files)==null?void 0:v[0];if(!s)return;Ce(null),p(null);const l=/\.(xlsx|xls|xlsm)$/i.test(s.name),u=new FileReader;u.onload=P=>{var Ae;const B=(Ae=P.target)==null?void 0:Ae.result;if(B)if(l)try{const j=At(B,{type:"array"}),R=j.Sheets[j.SheetNames[0]];if(!R){p({total:0,valid:0,errors:[{row:0,message:"Excel file has no sheets"}]});return}const le=je.sheet_to_json(R,{header:1,defval:"",raw:!1}
1);if(le.length<2){p({total:0,valid:0,errors:[{row:0,message:"Excel file is empty or has no data rows"}]});return}const ve=le[0].map(xe=>String(xe??"")),me=le.slice(1).filter(xe=>xe.some(ue=>String(ue??"").trim().length>0)).map(xe=>{const ue={};return ve.forEach((Ee,He)=>{ue[Ee]=String(xe[He]??"")}),ue});tt(ve,me)}catch(j){p({total:0,valid:0,errors:[{row:0,message:`Failed to parse Excel: ${(j==null?void 0:j.message)||j}`}]})}else{const R=B.split(/\r?\n/).filter(me=>me.trim().length>0);if(R.length<2){p({total:0,valid:0,errors:[{row:0,message:"CSV file is empty or has no data rows"}]});return}const le=R[0].split(",").map(me=>me.trim()),ve=R.slice(1).map(me=>{const xe=me.split(",").map(Ee=>Ee.trim()),ue={};return le.forEach((Ee,He)=>{ue[Ee]=xe[He]||""}),ue});tt(le,ve)}},l?u.readAsArrayBuffer(s):u.readAsText(s)},Nt=()=>{const t=[{unit_number:"A-001",unit_type:"standard",length_ft:5,width_ft:10,height_ft:8,floor_level:1,building_section:"A",monthly_rent:65,climate_controlled:"no",access_type:"drive-up"},{unit_number:"B-101",unit_type:"climate",length_ft:10,width_ft:10,height_ft:8,floor_level:2,building_section:"B",monthly_rent:145,climate_controlled:"yes",access_type:"indoor"},{unit_number:"C-201",unit_type:"large",length_ft:10,width_ft:20,height_ft:10,floor_level:2,building_section:"C",monthly_rent:235,climate_controlled:"yes",access_type:"indoor"}],s=je.json_to_sheet(t,{header:["unit_number","unit_type","length_ft","width_ft","height_ft","floor_level","building_section","monthly_rent","climate_controlled","access_type"]});s["!cols"]=[{wch:12},{wch:12},{wch:10},{wch:10},{wch:10},{wch:12},{wch:16},{wch:14},{wch:18},{wch:14}];const l=je.book_new();je.book_append_sheet(l,s,"Storage Units");const u=[["Column","Required","Description / Allowed Values"],["unit_number","YES",'Unique unit label (e.g. "A-001", "101")'],["unit_type","YES","standard | climate | large | locker | rv"],["length_ft","no","Numeric, e.g. 10"],["width_ft","no","Numeric, e.g. 10"],["height_ft","no","Numeric, e.g. 8"],["floor_level","no","Integer, e.g. 1, 2, 3"],["building_section","no",'Free text, e.g. "A", "Bldg 2"'],["monthly_rent","no","USD, no $ sign — e.g. 145"],["climate_controlled","no","yes | no | true | false (case-insensitive)"],["access_type","no","drive-up | indo
1or | outdoor | covered"],[""],["Tip","","Delete the 3 sample rows before uploading your real data."]],v=je.aoa_to_sheet(u);v["!cols"]=[{wch:22},{wch:12},{wch:60}],je.book_append_sheet(l,v,"Instructions"),It(l,"storage-units-template.xlsx")},wt=async()=>{if(i.length){ke(!0),Ce(null);try{const t=await fetch(`${he}/api/units/csv-import`,{method:"POST",headers:ge(),body:JSON.stringify({property_id:m,units:i})}),s=await t.json();s.ok||s.imported?(Ce({imported:s.imported??i.length}),N([]),p(null),L.current&&(L.current.value=""),oe()):t.status===402&&s.error==="PLAN_LIMIT_REACHED"?C(s):Ce({errors:s.errors||[s.error||"Import failed"]})}catch(t){Ce({errors:[t.message||"Network error"]})}finally{ke(!1)}}},Te=Math.max(1,Math.ceil(M/Oe)),St=()=>{const t=[];let l=Math.max(1,O-Math.floor(2.5)),u=l+5-1;u>Te&&(u=Te,l=Math.max(1,u-5+1));for(let v=l;v<=u;v++)t.push(v);return t},st=b.reduce((t,s)=>{const l=s.unit_type||"standard";return t[l]=(t[l]||0)+1,t},{}),de=S?{total_units:S.total??S.total_units??M,occupied:S.occupied??0,vacant:S.vacant??0,maintenance:S.maintenance??0,occupancy_rate:parseFloat(String(S.occupancy_rate??0)),monthly_revenue:parseFloat(String(S.monthly_revenue??0)),by_type:st}:{total_units:M,occupied:b.filter(t=>t.status==="occupied").length,vacant:b.filter(t=>t.status==="vacant").length,maintenance:b.filter(t=>t.status==="maintenance").length,occupancy_rate:M>0?Math.round(b.filter(t=>t.status==="occupied").length/M*100):0,monthly_revenue:b.filter(t=>t.status==="occupied").reduce((t,s)=>t+(s.monthly_rent||0),0),by_type:st};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-4",children:[e.jsxs(G,{padding:"sm",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Total Units"}),e.jsx("p",{className:"text-xl font-bold text-gray-900 mt-1",children:de.total_units})]}),e.jsxs(G,{padding:"sm",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Occupied"}),e.jsx("p",{className:"text-xl font-bold text-green-700 mt-1",children:de.occupied})]}),e.jsxs(G,{padding:"sm",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Vacant"}),e.jsx("p",{className:"text-xl font-bold text-blue-700 mt-1",children:de.vacant})]}),e.jsxs(G,{padding:"sm",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"By Type"}),e.jsx("div",{className:"mt-1 space-y-0.5",children:Object.entries(de.by_type).length>0?Object.entries(de.by_type).slice(0,3).map(([t,s])=>e.jsxs("p",{className:"text-xs text-gray-700 truncate",children:[Re(t),": ",e.jsx("span",{className:"font-semibold",children:s})]},t)):e.jsx("p",{className:"text-xs text-gray-400",children:"--"})})]}),e.jsxs(G,{padding:"sm",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Occupancy Rate"}),e.jsxs("p",{className:"text-xl font-bold text-brand-navy mt-1",children:[de.occupancy_rate,"%"]})]}),e.jsxs(G,{padding:"sm",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Monthly Revenue"}),e.jsxs("p",{className:"text-xl font-bold text-emerald-700 mt-1",children:["$",de.monthly_revenue.toLocaleString()]})]})]}),e.jsx(G,{padding:"sm",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[180px]",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search unit number...",value:d.search,onChange:t=>F(s=>({...s,search:t.target.value})),className:"w-full pl-9 pr-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy"})]}),e.jsx("select",{value:d.unit_type,onChange:t=>F(s=>({...s,unit_type:t.target.value})),className:"text-sm border border-gray-200 rounded-lg px-3 py-2 bg-white focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",children:ot.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("select",{value:d.status,onChange:t=>F(s=>({...s,status:t.target.value})),className:"text-sm border border-gray-200 rounded-lg px-3 py-2 bg-white focus:outline-none focus:ring-2 focus:ring-brand-navy
1/20 focus:border-brand-navy",children:Dt.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsxs("select",{value:d.floor_level,onChange:t=>F(s=>({...s,floor_level:t.target.value})),className:"text-sm border border-gray-200 rounded-lg px-3 py-2 bg-white focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",children:[e.jsx("option",{value:"",children:"All Floors"}),pe.map(t=>e.jsxs("option",{value:t,children:["Floor ",t]},t))]}),e.jsxs("select",{value:d.building_section,onChange:t=>F(s=>({...s,building_section:t.target.value})),className:"text-sm border border-gray-200 rounded-lg px-3 py-2 bg-white focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",children:[e.jsx("option",{value:"",children:"All Sections"}),$.map(t=>e.jsxs("option",{value:t,children:["Section ",t]},t))]})]})}),ae&&e.jsx(Mt,{payload:ae,onClose:()=>C(null)}),q&&e.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-700 rounded-lg px-4 py-3 text-sm",children:[q,e.jsx("button",{onClick:oe,className:"ml-3 underline font-medium hover:text-red-900",children:"Retry"})]}),e.jsxs(G,{padding:"none",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:[w==="warehouse"?"Warehouse":"Storage"," Units"]}),e.jsxs("p",{className:"text-sm text-gray-500 mt-0.5",children:[M," total unit",M!==1?"s":""]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"primary",size:"sm",onClick:()=>De(!0),title:"Rent a unit to a walk-in customer in under 60 seconds",children:"Quick Rent"}),D.size>0&&e.jsxs(f,{variant:"outline",size:"sm",icon:e.jsx(Je,{className:"w-4 h-4"}),onClick:()=>qe(!0),title:"Publish selected units to the public site",children:["Bulk Publish (",D.size,")"]}),e.jsx(f,{variant:"outline",size:"sm",icon:e.jsx(at,{className:"w-4 h-4"}),onClick:()=>ie(t=>!t),children:"Import CSV"}),e.jsx(f,{variant:"outline",size:"sm",icon:e.jsx(we,{className:"w-4 h-4"}),onClick:()=>J(t=>!t),children:"Bulk Create"})]})]}),Y&&e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-b-2 border-brand-navy mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Loading units..."})]})}),!Y&&!q&&b.length===0&&e.jsxs("div",{className:"text-center py-16",children:[e.jsx(mt,{className:"w-14 h-14 text-gray-300 mx-auto mb-4"}),e.jsx("h4",{className:"text-base font-semibold text-gray-700 mb-1",children:"No units found"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:d.search||d.unit_type||d.status||d.floor_level||d.building_section?"Try adjusting your filters.":"Get started by creating units with the Bulk Create tool or importing a CSV."}),!(d.search||d.unit_type||d.status||d.floor_level||d.building_section)&&e.jsx(f,{variant:"primary",size:"sm",icon:e.jsx(we,{className:"w-4 h-4"}),onClick:()=>J(!0),children:"Create Units"})]}),!Y&&!q&&b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 w-10",children:e.jsx("input",{type:"checkbox","aria-label":"Select all units",checked:b.length>0&&b.every(t=>D.has(t.unit_id)),onChange:bt,className:"rounded border-gray-300 text-brand-navy focus:ring-brand-navy cursor-pointer"})}),e.jsx(dt,{field:"unit_number",label:"Unit #",current:H,dir:k,onSort:Ze}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Type"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Dimensions"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase",children:"Sq Ft"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Floor"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Section"}),e.jsx(dt,{field:"monthly_rent",label:"Rent",current:H,dir:k,onSort:Ze,align:"right"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Status"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Tenant"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Access Code"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase",children:"Action"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:b.map(t=>{const s=t.length_ft&&t.width_ft?t.length_ft*t.width_ft:null;return e.jsxs("tr",{className:"hover:bg-gray-50 cursor-pointer transition-colors",onClick:()=>Pe(t),children:[e.jsx("td",{className:"px-4 py-3",onClick:l=>l.stopPropagation(),children:e.jsx("input",{type:"checkbox","aria-label":`Select unit ${t.unit_number}`,checked:D.has(t.unit_id),onChange:()=>ft(t.unit_id),className:"rounded border-gray-300 text-brand-navy focus:ring-brand-navy cursor-pointer"})}),e.jsx("td",{className:"px-4 py-3 text-sm font-medium text-gray-900",children:t.unit_number}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-700",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[qt(t.unit_type),Re(t.unit_type)]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600 font-mono",children:t.length_ft&&t.width_ft?`${t.length_ft}x${t.width_ft}${t.height_ft?`x${t.height_ft}`:""}`:"--"}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-700 text-right",children:s!=null?s.toLocaleStr
1ing():"--"}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:t.floor_level||"--"}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:t.building_section||"--"}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right font-medium",children:t.monthly_rent!=null?`$${Number(t.monthly_rent).toLocaleString()}`:"--"}),e.jsx("td",{className:"px-4 py-3",children:(()=>{const l=We(t);return e.jsx(Le,{variant:l.variant,size:"sm",children:l.label})})()}),e.jsx("td",{className:"px-4 py-3 text-sm",children:t.tenant_name?e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-900 leading-tight",children:t.tenant_name}),t.tenant_email&&e.jsx("span",{className:"text-xs text-gray-500 leading-tight",children:t.tenant_email})]}):e.jsx("span",{className:"text-gray-400",children:"—"})}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-500 font-mono",children:t.access_code||"--"}),e.jsx("td",{className:"px-4 py-3 text-right",onClick:l=>l.stopPropagation(),children:t.lease_id?e.jsx("span",{className:"text-xs text-gray-400",children:"Leased"}):t.status==="vacant"?e.jsxs("button",{type:"button",onClick:()=>$e(t),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium text-brand-navy border border-brand-navy/30 rounded hover:bg-brand-navy/5 transition-colors",title:`Create a lease for unit ${t.unit_number}`,children:[e.jsx(we,{className:"w-3 h-3"}),"Lease"]}):e.jsx("span",{className:"text-xs text-gray-400",children:"—"})})]},t.unit_id)})})]})}),Te>1&&e.jsxs("div",{className:"px-6 py-4 border-t border-gray-200 flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:["Showing ",(O-1)*Oe+1,"-",Math.min(O*Oe,M)," of ",M," units"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>V(t=>Math.max(1,t-1)),disabled:O===1,className:"px-3 py-1.5 text-sm rounded-lg border border-gray-200 text-gray-700 hover:bg-gray-50 disabled:opacity-40 disabled:cursor-not-allowed",children:"Previous"}),St().map(t=>e.jsx("button",{onClick:()=>V(t),className:`w-8 h-8 text-sm rounded-lg ${t===O?"bg-brand-navy text-white font-medium":"text-gray-700 hover:bg-gray-100"}`,children:t},t)),e.jsx("button",{onClick:()=>V(t=>Math.min(Te,t+1)),disabled:O===Te,className:"px-3 py-1.5 text-sm rounded-lg border border-gray-200 text-gray-700 hover:bg-gray-50 disabled:opacity-40 disabled:cursor-not-allowed",children:"Next"})]})]})]})]}),e.jsxs(G,{padding:"none",children:[e.jsxs("button",{onClick:()=>J(t=>!t),className:"w-full px-6 py-4 flex items-center justify-between text-left hover:bg-gray-50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(we,{className:"w-5 h-5 text-brand-navy"}),e.jsx("span",{className:"font-semibold text-gray-900",children:"Bulk Unit Generator"})]}),Z?e.jsx(nt,{className:"w-5 h-5 text-gray-400"}):e.jsx(rt,{className:"w-5 h-5 text-gray-400"})]}),Z&&e.jsxs("div",{className:"px-6 pb-6 border-t border-gray-200 pt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Prefix"}),e.jsx("input",{type:"text",value:a.prefix,onChange:t=>r(s=>({...s,prefix:t.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",placeholder:"U"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Start Number"}),e.jsx("input",{type:"number",min:1,value:a.start_number,onChange:t=>r(s=>({...s,start_number:parseInt(t.target.value)||1})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"End Number"}),e.jsx("input",{type:"number",min:1,value:a.end_number,onChange:t=>r(s=>({...s,end_number:parseInt(t.target.value)||1})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy
1/20 focus:border-brand-navy"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Unit Type"}),e.jsx("select",{value:a.unit_type,onChange:t=>r(s=>({...s,unit_type:t.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg bg-white focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",children:ot.filter(t=>t.value).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:"Length (ft)"}),e.jsx("input",{type:"number",min:1,value:a.length_ft,onChange:t=>r(s=>({...s,length_ft:parseFloat(t.target.value)||0})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Width (ft)"}),e.jsx("input",{type:"number",min:1,value:a.width_ft,onChange:t=>r(s=>({...s,width_ft:parseFloat(t.target.value)||0})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Height (ft)"}),e.jsx("input",{type:"number",min:1,value:a.height_ft,onChange:t=>r(s=>({...s,height_ft:parseFloat(t.target.value)||0})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Floor Level"}),e.jsx("input",{type:"text",value:a.floor_level,onChange:t=>r(s=>({...s,floor_level:t.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",placeholder:"1"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Building Section"}),e.jsx("input",{type:"text",value:a.building_section,onChange:t=>r(s=>({...s,building_section:t.target.value})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy",placeholder:"A"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Monthly Rent ($)"}),e.jsx("input",{type:"number",min:0,step:5,value:a.monthly_rent,onChange:t=>r(s=>({...s,monthly_rent:parseFloat(t.target.value)||0})),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-navy/20 focus:border-brand-navy"})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.climate_controlled,onChange:t=>r(s=>({...s,climate_controlled:t.target.checked})),className:"w-4 h-4 rounded border-gray-300 text-brand-navy focus:ring-brand-navy/20"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Climate Controlled"})]})})]}),e.jsxs("div",{className:"mt-4 p-3 bg-gray-50 rounded-lg border border-gray-200",children:[e.jsx("p",{className:"text-sm text-gray-700 font-medium",children:vt}),a.length_ft>0&&a.width_ft>0&&e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Each unit: ",a.length_ft,"x",a.width_ft,a.height_ft>0?`x${a.height_ft}`:""," ft (",a.length_ft*a.width_ft," sq ft) · $",a.monthly_rent,"/mo",a.climate_controlled?" &middot; Climate Controlled":""]})]}),(h==null?void 0:h.success)&&e.jsxs("div",{className:"mt-3 p-3 bg-green-50 border border-green-200 text-green-700 rounded-lg text-sm",children:["Successfully created ",h.success," units."]}),(h==null?void 0:h.errors)&&h.errors.length>0&&e.jsx("div",{className:"mt-3 p-3 bg-red-50 border border-red-200 text-red-700 rounded-lg text-sm",children:h.errors.map((t,s)=>e.jsx("p",{children:t},s))}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsxs(f,{variant:"primary",size:"sm",loading:y,disabled:ce<=0||y,onClick:jt,children:["Create ",ce," Unit",ce!==1?"s":""]})})]})]}),e.jsxs(G,{padding:"none",children:[e.jsxs("button",{onClick:()=>ie(t=>!t),className:"w-full px-6 py-4 flex items-center justify-between text-left hover:bg-gray-50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(at,{className:"w-5 h-5 text-brand-navy"}),e.jsx("span",{className:"font-semibold text-gray-900",children:"CSV Import"})]}),ne?e.jsx(nt,{className:"w-5 h-5 text-gray-400"}):e.jsx(rt,{className:"w-5 h-5 text-gray-400"})]}),ne&&e.jsxs("div",{className:"px-6 pb-6 border-t border-gray-200 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-3",children:[e.jsxs("p",{className:"text-sm text-gray-600",children:["Upload a CSV or Excel (.xlsx) file with columns:"," ",e.jsx("span",{className:"font-mono text-xs text-gray-800",children:"unit_number, unit_type, length_ft, width_ft, height_ft, floor_level, building_section, monthly_rent, climate_controlled, access_type"})]}),e.jsxs("button",{type:"button",onClick:Nt,className:"flex-shrink-0 inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-brand-navy border border-brand-navy
1/30 rounded-lg hover:bg-brand-navy/5 transition-colors",title:"Download an Excel template with sample rows",children:[e.jsx(Ut,{className:"w-4 h-4"}),"Download Excel Template"]})]}),e.jsx("input",{ref:L,type:"file",accept:".csv,.xlsx,.xls,.xlsm",onChange:_t,className:"block w-full text-sm text-gray-600 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-brand-navy file:text-white hover:file:bg-brand-navy/90 file:cursor-pointer"}),g&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"text-gray-600",children:["Total rows: ",e.jsx("span",{className:"font-semibold text-gray-900",children:g.total})]}),e.jsxs("span",{className:"text-green-700",children:["Valid: ",e.jsx("span",{className:"font-semibold",children:g.valid})]}),g.errors.length>0&&e.jsxs("span",{className:"text-red-600",children:["Errors: ",e.jsx("span",{className:"font-semibold",children:g.errors.length})]})]}),g.errors.length>0&&e.jsxs("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg max-h-32 overflow-y-auto",children:[g.errors.slice(0,10).map((t,s)=>e.jsxs("p",{className:"text-xs text-red-700",children:["Row ",t.row,": ",t.message]},s)),g.errors.length>10&&e.jsxs("p",{className:"text-xs text-red-500 mt-1",children:["...and ",g.errors.length-10," more errors"]})]}),i.length>0&&e.jsxs("div",{className:"overflow-x-auto border border-gray-200 rounded-lg",children:[e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-500",children:"#"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-500",children:"Unit #"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-500",children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-500",children:"Dimensions"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium text-gray-500",children:"Rent"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-500",children:"Floor"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-500",children:"Section"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:i.slice(0,5).map((t,s)=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-3 py-2 text-gray-400",children:s+1}),e.jsx("td",{className:"px-3 py-2 font-medium text-gray-900",children:t.unit_number}),e.jsx("td",{className:"px-3 py-2 text-gray-700",children:t.unit_type}),e.jsxs("td",{className:"px-3 py-2 text-gray-600 font-mono",children:[t.length_ft,"x",t.width_ft,t.height_ft?`x${t.height_ft}`:""]}),e.jsx("td",{className:"px-3 py-2 text-gray-900 text-right",children:t.monthly_rent?`$${t.monthly_rent}`:"--"}),e.jsx("td",{className:"px-3 py-2 text-gray-600",children:t.floor_level||"--"}),e.jsx("td",{className:"px-3 py-2 text-gray-600",children:t.building_section||"--"})]},s))})]}),i.length>5&&e.jsxs("div",{className:"px-3 py-2 bg-gray-50 border-t border-gray-200 text-xs text-gray-500",children:["Showing first 5 of ",i.length," rows"]})]})]}),(K==null?void 0:K.imported)&&e.jsxs("div",{className:"mt-3 p-3 bg-green-50 border border-green-200 text-green-700 rounded-lg text-sm",children:["Successfully imported ",K.imported," units."]}),(K==null?void 0:K.errors)&&K.errors.length>0&&e.jsx("div",{className:"mt-3 p-3 bg-red-50 border border-red-200 text-red-700 rounded-lg text-sm",children:K.errors.map((t,s)=>e.jsx("p",{children:t},s))}),i.length>0&&e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsxs(f,{variant:"primary",size:"sm",loading:fe,disabled:fe||((g==null?void 0:g.valid)??0)===0,onClick:wt,children:["Import ",(g==null?void 0:g.valid)??i.length," Unit",((g==null?void 0:g.valid)??i.length)!==1?"s":""]})})]})]}),pt&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg max-w-lg w-full max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"w-5 h-5 text-brand-navy"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Bulk Publish to Public Site"})]}),e.jsx("button",{onClick:()=>{qe(!1),ye(null)},className:"text-gray-400 hover:text-gray-600","aria-label":"Close",children:e.jsx(Fe,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"px-6 py-4 overflow-y-auto flex-1 space-y-4",children:[e.jsxs("p",{className:"text-sm text-gray-600",children:["Publishing ",e.jsx("strong",{children:D.size})," unit",D.size!==1?"s":""," to the public Storage page. Each unit gets its own listing with auto-generated title, dimensions, and price from its record. Use the fields below to set shared rental terms once for all selected units."]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Rental Type"}
1),e.jsxs("select",{value:re.rental_type,onChange:t=>Me(s=>({...s,rental_type:t.target.value})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent",children:[e.jsx("option",{value:"long-term",children:"Long-Term"}),e.jsx("option",{value:"short-term",children:"Short-Term"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Lease Type"}),e.jsx("input",{type:"text",value:re.lease_type,onChange:t=>Me(s=>({...s,lease_type:t.target.value})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Available From"}),e.jsx("input",{type:"date",value:re.availability_date,onChange:t=>Me(s=>({...s,availability_date:t.target.value})),className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Shared Amenities (comma-separated, optional)"}),e.jsx("input",{type:"text",value:re.amenities_csv,onChange:t=>Me(s=>({...s,amenities_csv:t.target.value})),placeholder:"On-Site Manager, Security Cameras, Pest Control",className:"w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-brand-navy focus:border-transparent"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Climate Controlled, Drive-Up/Indoor Access, and 24/7 Access are added automatically per unit."})]}),te&&e.jsxs("div",{className:`p-3 rounded-lg border ${te.errors&&te.errors.length>0?"bg-red-50 border-red-200":"bg-green-50 border-green-200"}`,children:[te.published!=null&&e.jsxs("p",{className:"text-sm font-medium text-green-800",children:["Published ",te.published," listing",te.published!==1?"s":""," to the public site."]}),te.errors&&te.errors.length>0&&e.jsx("div",{className:"mt-2 text-xs text-red-700",children:te.errors.slice(0,5).map((t,s)=>e.jsxs("p",{children:[t.unit_number,": ",t.error]},s))})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-200 flex justify-end gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{qe(!1),ye(null)},disabled:Ve,children:"Cancel"}),e.jsxs(f,{variant:"primary",size:"sm",icon:e.jsx(Je,{className:"w-4 h-4"}),loading:Ve,onClick:yt,disabled:Ve||D.size===0,children:["Publish ",D.size," Listing",D.size!==1?"s":""]})]})]})}),o&&e.jsxs("div",{className:"fixed inset-0 z-40 flex",children:[e.jsx("div",{className:"flex-1",onClick:()=>Pe(null)}),e.jsxs("div",{className:"w-full max-w-md bg-white shadow-2xl border-l border-gray-200 flex flex-col overflow-hidden animate-slide-in-right",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between bg-gray-50",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900",children:["Unit ",o.unit_number]}),e.jsxs("p",{className:"text-sm text-gray-500",children:[Re(o.unit_type)," · ",o.length_ft&&o.width_ft?`${o.length_ft}x${o.width_ft}`:"—"," · ",We(o).label]})]}),e.jsx("button",{onClick:()=>Pe(null),className:"text-gray-400 hover:text-gray-600",children:e.jsx(Fe,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-5",children:[e.jsxs("section",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase text-gray-500 tracking-wide mb-2",children:"Unit Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Type"}),e.jsx("p",{className:"font-medium",children:Re(o.unit_type)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Dimensions"}),e.jsxs("p",{className:"font-medium font-mono",children:[o.length_ft,"x",o.width_ft,o.height_ft?`x${o.height_ft}`:""]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Square Feet"}),e.jsx("p",{className:"font-medium",children:o.length_ft&&o.width_ft?(o.length_ft*o.width_ft).toLocaleStr
1ing():"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Floor / Section"}),e.jsxs("p",{className:"font-medium",children:[o.floor_level||"—"," / ",o.building_section||"—"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Monthly Rent"}),e.jsxs("p",{className:"font-medium text-gray-900",children:["$",Number(o.monthly_rent||0).toLocaleString(),"/mo"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Access Code"}),e.jsx("p",{className:"font-medium font-mono tracking-widest",children:o.access_code||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Climate"}),e.jsx("p",{className:"font-medium",children:o.is_climate_controlled===1||o.climate_controlled?"Yes":"No"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Status"}),e.jsx("p",{children:(()=>{const t=We(o);return e.jsx(Le,{variant:t.variant,size:"sm",children:t.label})})()})]})]})]}),e.jsxs("section",{className:"border-t border-gray-100 pt-4",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase text-gray-500 tracking-wide mb-2",children:"Tenant & Lease"}),o.tenant_name?e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-brand-navy rounded-full flex items-center justify-center",children:e.jsx("span",{className:"text-white font-semibold text-sm",children:o.tenant_name.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900",children:o.tenant_name}),o.tenant_email&&e.jsx("p",{className:"text-gray-500 text-xs",children:o.tenant_email})]})]}),o.billing_status==="past_due"&&o.days_past_due&&e.jsxs("div",{className:"p-2 bg-red-50 border border-red-200 rounded text-xs text-red-700",children:["Payment overdue by ",o.days_past_due," day",o.days_past_due!==1?"s":"",". Follow up with tenant."]}),be==="has-access"&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-700",children:[e.jsx(Se,{className:"w-3.5 h-3.5"})," Has portal access"]}),be==="sent"&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-700",children:[e.jsx(Se,{className:"w-3.5 h-3.5"})," Portal invite sent"]}),be==="no-access"&&o.tenant_email&&e.jsx(f,{variant:"outline",size:"sm",icon:e.jsx(Ge,{className:"w-3.5 h-3.5"}),onClick:ht,className:"w-full",children:"Invite to Portal"}),be==="no-access"&&!o.tenant_email&&e.jsx("div",{className:"text-xs text-gray-400 italic",children:"No email on file — can't invite to portal."}),be==="inviting"&&e.jsx("div",{className:"text-xs text-gray-500",children:"Sending invite..."}),be==="error"&&e.jsx("div",{className:"text-xs text-red-600",children:ut||"Invite failed"})]}):e.jsxs("div",{className:"text-sm text-gray-400 italic",children:["No tenant — unit is vacant.",e.jsx("button",{type:"button",onClick:()=>{Pe(null),$e(o)},className:"ml-2 text-brand-navy font-medium hover:underline not-italic",children:"+ Lease this unit"})]})]}),e.jsxs("section",{className:"border-t border-gray-100 pt-4",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase text-gray-500 tracking-wide mb-2",children:"Quick Actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[!o.lease_id&&o.status==="vacant"&&e.jsx(f,{variant:"primary",size:"sm",icon:e.jsx(we,{className:"w-4 h-4"}),onClick:()=>{Pe(null),$e(o)},children:"Lease Unit"}),o.lease_id&&e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{},children:"View Lease"}),e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{},children:"Edit Unit"})]})]})]}),e.jsx("div",{className:"px-6 py-3 border-t border-gray-200 bg-gray-50",children:e.jsxs("p",{className:"text-xs text-gray-400 text-center",children:["Unit ",o.unit_id.slice(0,8),"..."]})})]})]}),gt&&e.jsx(zt,{propertyId:m,propertyName:_||(w==="warehouse"?"Warehouse":"Storage Facility"),onClose:()=>De(!1),onSuccess:()=>{De(!1),oe()}}),z&&e.jsx(Ft,{propertyId:m,propertyName:_||(w==="warehouse"?"Warehouse":"Storage Facility"),unitNumber:z.unit_number,unitId:z.unit_id,unitType:z.unit_type,monthlyRent:Number(z.monthly_rent||0),sqFt:z.length_ft&&z.width_ft?z.length_ft*z.width_ft:0,isClimateControlled:z.climate_controlled===!0||z.is_climate_controlled===1,onClose:()=>$e(null),onSuccess:()=>{$e(null),oe()}})]})}function dt({field:m,label:w,current:_,dir:b,onSort:Q,align:S="left"}){const E=_===m;return e.jsx("th",{className:`px-4 py-3 text-xs font-medium text-gray-500 uppercase cursor-pointer select-none hover:text-gray-700 ${S==="right"?"text-right":"text-left"}`,onClick:()=>Q(m),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[w,e.jsx(Ot,{className:`w-3 h-3 ${E?"text-brand-navy":"text-gray-300"}`}),E&&e.jsx("span",{className:"text-[10px] text-brand-navy font-normal",children:b==="asc"?"â
1†‘":"↓"})]})})}export{as 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.