import{j as e}from"./ui-vendor-Cn57k9R1.js";import{r as d,L as b}from"./react-vendor-B9tfxWGs.js";import{u as M}from"./useDashboardQuery-DHFenreI.js";import{d as f,e as _,g as i,M as j,h as c,i as v,F as u}from"./index-DT-X9ySe.js";import{f as k}from"./crmLabels-C2P3kT73.js";import{R as g,B as A,C as D,X as F,Y as P,T as p,a as I,P as q,b as L,d as B,L as R}from"./charts-vendor-DecUTkfU.js";import{D as z}from"./download-CxKVf-xn.js";import"./query-vendor-BGnEs3s8.js";import"./editor-vendor-BA3QzDsK.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const y=f("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const N=f("Star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);function a({className:s,...o}){return e.jsx("div",{className:_("animate-pulse rounded-md bg-muted",s),...o})}const T=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],E={available:{label:"Available",color:"hsl(150, 45%, 33%)"},selling_fast:{label:"Selling Fast",color:"hsl(35, 82%, 50%)"},sold_out:{label:"Sold Out",color:"hsl(4, 72%, 46%)"}},U=[{label:"Total Properties",value:0,change:"—",changeColor:"text-muted-foreground",icon:i},{label:"Featured",value:0,change:"—",changeColor:"text-muted-foreground",icon:N},{label:"New Inquiries",value:0,change:"—",changeColor:"text-muted-foreground",icon:j},{label:"Unread Inquiries",value:0,change:"—",changeColor:"text-muted-foreground",icon:y},{label:"Announcements",value:0,change:"—",changeColor:"text-muted-foreground",icon:c},{label:"Unread Messages",value:0,change:"—",changeColor:"text-muted-foreground",icon:v},{label:"Blog Posts",value:0,change:"—",changeColor:"text-muted-foreground",icon:u}],J=[{month:"Jan",count:0}],K=[{name:"Available",value:1,color:"hsl(150, 45%, 33%)"}],O=[],$={New:"bg-destructive/10 text-destructive",Contacted:"bg-primary/10 text-primary","Follow up":"bg-amber-500/15 text-amber-800 dark:text-amber-200",Qualified:"bg-blue-500/10 text-blue-700 dark:text-blue-300",Converted:"bg-success/10 text-success",Closed:"bg-muted text-muted-foreground",Spam:"bg-destructive/15 text-destructive"},Q=[{icon:i,label:"Add Property",to:"/admin/properties/new"},{icon:u,label:"New Blog Post",to:"/admin/blog/new"},{icon:c,label:"New Announcement",to:"/admin/announcements/new"},{icon:z,label:"Export Inquiries CSV",to:"#"}],V=s=>{const o=Number(s)-1;return T[o]??String(s)},re=()=>{const{data:s,isError:o,isPending:n}=M(),w=d.useMemo(()=>{if(!(s!=null&&s.metrics))return U;const t=s.metrics;return[{label:"Total Properties",value:t.total_properties,change:"Live",changeColor:"text-success",icon:i},{label:"Featured",value:t.featured_properties,change:"Featured listings",changeColor:"text-muted-foreground",icon:N},{label:"New Inquiries",value:t.new_inquiries,change:"Status: new",changeColor:"text-muted-foreground",icon:j},{label:"Unread Inquiries",value:t.unread_inquiries??0,change:"Needs attention",changeColor:"text-muted-foreground",icon:y},{label:"Announcements",value:t.announcements,change:"All announcements",changeColor:"text-muted-foreground",icon:c},{label:"Unread Messages",value:t.unread_messages,change:"Contact messages",changeColor:"text-muted-foreground",icon:v},{label:"Blog Posts",value:t.blog_posts,change:"Published posts",changeColor:"text-success",icon:u}]},[s]),S=d.useMemo(()=>{var t;return(t=s==null?void 0:s.inquiries_per_month)!=null&&t.length?s.inquiries_per_month.map(r=>({month:V(r.month),count:Number(r.count)||0})):J},[s]),C=d.useMemo(()=>!(s!=null&&s.properties_by_status)||Object.keys(s.properties_by_status).length===0?K:Object.entries(s.properties_by_status).map(([t,r],l)=>{const h=E[t]??{label:t.replace(/_/g," "),color:["hsl(220, 14%, 72%)","hsl(48, 96%, 70%)","hsl(325, 66%, 60%)"][l%3]};return{name:h.label,value:Number(r)||0,color:h.color}}),[s]),m=d.useMemo(()=>{var t;return(t=s==null?void 0:s.recent_inquiries)!=null&&t.length?s.recent_inquiries.map(r=>{var l;return{id:r.id,name:r.name,property:((l=r.property)==null?void 0:l.name)??`#${r.id}`,time:new Date(r.created_at).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"numeric"}),status:k(r.status)}}):O},[s]),x=C.filter(t=>t.value>0);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-[22px] font-bold text-foreground font-body",children:"Dashboard"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body",children:"Welcome back, Admin"})]}),o?e.jsx("div",{className:"rounded-xl border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive font-body",children:"Unable to load live dashboard data."}):null]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:n&&!s?Array.from({length:7}).map((t,r)=>e.jsxs("div",{className:"bg-card rounded-xl border border-border p-6 relative overflow-hidden",children:[e.jsx(a,{className:"h-4 w-24 mb-3"}),e.jsx(a,{className:"h-9 w-16 mb-2"}),e.jsx(a,{className:"h-3 w-20"})]},r)):w.map(t=>e.jsxs("div",{className:"bg-card rounded-xl border border-border p-6 relative overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 bg-primary rounded-r"}),e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground font-body",children:t.label}),e.jsx("p",{className:"text-3xl font-bold text-foreground font-body mt-1",children:t.value}),e.jsx("p",{className:`text-xs mt-1 font-body ${t.changeColor}`,children:t.change})]}),e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(t.icon,{className:"w-5 h-5 text-primary"})})]})]},t.label))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card rounded-xl border border-border p-6",children:[e.jsx("h2",{className:"text-base font-semibold text-foreground font-body mb-4",children:"Inquiries Per Month"}),e.jsx("div",{className:"h-[260px]",children:n&&!s?e.jsx(a,{className:"h-full w-full rounded-lg"}):e.jsx(g,{width:"100%",height:"100%",children:e.jsxs(A,{data:S,children:[e.jsx(D,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(37, 18%, 88%)"}),e.jsx(F,{dataKey:"month",tick:{fontSize:12,fontFamily:"DM Sans"},stroke:"hsl(233, 18%, 35%)"}),e.jsx(P,{tick:{fontSize:12,fontFamily:"DM Sans"},stroke:"hsl(233, 18%, 35%)"}),e.jsx(p,{contentStyle:{borderRadius:12,border:"1px solid hsl(37, 18%, 88%)",fontFamily:"DM Sans",fontSize:13}}),e.jsx(I,{dataKey:"count",fill:"hsl(35, 82%, 50%)",radius:[6,6,0,0]})]})})})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border p-6",children:[e.jsx("h2",{className:"text-base font-semibold text-foreground font-body mb-4",children:"Properties by Status"}),e.jsx("div",{className:"h-[260px]",children:n&&!s?e.jsx(a,{className:"h-full w-full rounded-lg"}):e.jsx(g,{width:"100%",height:"100%",children:e.jsxs(q,{children:[e.jsx(L,{data:x,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",innerRadius:60,outerRadius:90,paddingAngle:4,children:x.map((t,r)=>e.jsx(B,{fill:t.color},r))}),e.jsx(R,{formatter:t=>e.jsx("span",{style:{fontFamily:"DM Sans",fontSize:13},children:t})}),e.jsx(p,{contentStyle:{borderRadius:12,fontFamily:"DM Sans",fontSize:13}})]})})})]})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 pb-4",children:[e.jsx("h2",{className:"text-base font-semibold text-foreground font-body",children:"Recent Inquiries"}),e.jsx(b,{to:"/admin/inquiries",className:"text-sm text-primary hover:underline font-body",children:"View All →"})]}),e.jsx("div",{className:"overflow-x-auto",children:n&&!s?e.jsxs("div",{className:"p-6 space-y-2",children:[e.jsx(a,{className:"h-10 w-full"}),e.jsx(a,{className:"h-10 w-full"}),e.jsx(a,{className:"h-10 w-full"})]}):e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b",style:{background:"#F4F1EB"},children:["Client Name","Property","Time","Status"].map(t=>e.jsx("th",{className:"text-left px-6 py-3 text-xs font-semibold text-muted-foreground uppercase tracking-wider font-body",children:t},t))})}),e.jsx("tbody",{children:m.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-6 py-8 text-sm text-muted-foreground font-body text-center",children:"No inquiries yet."})}):m.map(t=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/30 transition-colors duration-150",children:[e.jsx("td",{className:"px-6 py-3 text-sm font-medium text-foreground font-body",children:t.name}),e.jsx("td",{className:"px-6 py-3 text-sm text-muted-foreground font-body",children:t.property}),e.jsx("td",{className:"px-6 py-3 text-sm text-muted-foreground font-body",children:t.time}),e.jsx("td",{className:"px-6 py-3",children:e.jsx("span",{className:`text-xs px-2 py-1 rounded-full font-medium font-body ${$[t.status]??"bg-muted text-muted-foreground"}`,children:t.status})})]},t.id))})]})})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:Q.map(t=>e.jsxs(b,{to:t.to,className:"bg-card rounded-xl border border-border p-6 flex flex-col items-center gap-3 hover:shadow-md hover:-translate-y-0.5 transition-all duration-200 group",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center group-hover:bg-primary/20 transition-colors",children:e.jsx(t.icon,{className:"w-6 h-6 text-primary"})}),e.jsx("span",{className:"text-sm font-medium text-foreground font-body text-center",children:t.label})]},t.label))})]})};export{re as default};
