1import{co as e,q as ke,M as De,cq as $e,cs as Q,cu as Te,cH as Ae,cF as Fe,cS as Le,a_ as Re,b3 as Ie,aY as Ee,bO as Me}from"./index-B70u2C2F.js";import{r as t,u as J,R as ze}from"./vendor-react-DDKacIYH.js";import{j as Z,p as Y,z as Oe}from"./appointments-C5oO4ZOa.js";import{s as We}from"./jobs-B_YHjmOT.js";import{u as Be}from"./useRealtimeCalls-BmXYWwmM.js";import{f as fe,a as Pe}from"./utils-CD0JJNA-.js";import{F as B}from"./CheckCircleIcon-DKqegKtq.js";import{F as he}from"./ClockIcon-DoOCG-hY.js";import{F}from"./PhoneIcon-BHTrtL7o.js";import{F as W,a as Ue}from"./CalendarIcon-JzMXtzKS.js";import{d as He,c as qe}from"./businessTypeRegistry-CBq9p7PI.js";import{S as Ge}from"./settingsTabRegistry-DOmToyDG.js";import{F as de}from"./XMarkIcon-4LAID-B-.js";import{F as Ve}from"./RocketLaunchIcon-BRxlZ1QY.js";import{F as Ze}from"./ChevronRightIcon-CxUTcfv1.js";import{b as Ye}from"./ai-CE1FefG5.js";import"./vendor-firebase-BlSo17-V.js";import"./calls-CQTc5ouF.js";function Qe({title:s,titleId:a,...n},i){return t.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:i,"aria-labelledby":a},n),s?t.createElement("title",{id:a},s):null,t.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.857 17.082a23.848 23.848 0 0 0 5.454-1.31A8.967 8.967 0 0 1 18 9.75V9A6 6 0 0 0 6 9v.75a8.967 8.967 0 0 1-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 0 1-5.714 0m5.714 0a3 3 0 1 1-5.714 0M3.124 7.5A8.969 8.969 0 0 1 5.292 3m13.416 0a8.969 8.969 0 0 1 2.168 4.5"}))}const Je=t.forwardRef(Qe);function Ke({title:s,titleId:a,...n},i){return t.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:i,"aria-labelledby":a},n),s?t.createElement("title",{id:a},s):null,t.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.087.16 2.185.283 3.293.369V21l4.076-4.076a1.526 1.526 0 0 1 1.037-.443 48.282 48.282 0 0 0 5.68-.494c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.
1123-2.995-2.707-3.228A48.394 48.394 0 0 0 12 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018Z"}))}const Xe=t.forwardRef(Ke);function es(s){return s?s.replace(/job[\s_]id:[^\n]*/gi,"").replace(/\n{3,}/g,` 2 3`).trim():""}function ss({jobStatus:s}){return!s||s==="agent_quote"||s==="quote"?e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-700",children:"ð¤ Agent Quote"}):s==="accepted"?e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-700",children:"ð¼ Quoted"}):s==="in_progress"?e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-orange-100 text-orange-700",children:"ð§ In Progress"}):s==="completed"?e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-700",children:"â Completed"}):e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-700",children:"ð¤ Agent Quote"})}function ts({item:s,onDone:a}){const n=J(),i=s.urgency==="urgent",c=new URLSearchParams({new:"1"});return s.caller_name&&c.set("caller_name",s.caller_name),s.caller_phone&&c.set("caller_phone",s.caller_phone),s.message&&c.set("notes",s.message),e.jsx("div",{className:` 4 w-full text-left p-4 rounded-xl border-2 5 ${i?"bg-red-50 border-red-300":"bg-blue-50 border-blue-300"} 6 `,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:` 7 w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 8 ${i?"bg-red-200 text-red-700":"bg-blue-200 text-blue-700"} 9 `,children:e.jsx(Xe,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:e.jsx("span",{className:` 10 text-xs font-bold uppercase tracking-wide px-2 py-0.5 rounded 11 ${i?"bg-red-200 text-red-800":"bg-blue-200 text-blue-800"} 12 `,children:i?"ð¨ URGENT CALLBACK":"ð CALLBACK REQUEST"})}),e.jsx("h3",{className:"font-semibold text-gray-900 mt-1.5 truncate",children:s.caller_name||"Unknown Caller"}),s.caller_phone&&e.jsxs("div",{className:"flex items-center gap-1 mt-1 text-sm text-gray-600",children:[e.jsx(F,{className:"w-4 h-4"}),fe(s.caller_phone)]}),s.message&&e.jsxs("p",{className:"mt-2 text-sm text-gray-700 line-clamp-3 italic",children:['"',s.message,'"']})]}),e.jsxs("div",{className:"flex flex-col gap-2 flex-shrink-0 items-end",children:[s.source_call_id&&e.jsxs("button",{onClick:()=>n(`/calls?call=${s.source_call_id}`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:border-gray-400 transition-colors whitespace-nowrap",children:[e.jsx(F,{className:"w-3.5 h-3.5"}),"View Call"]}),e.jsxs("button",{onClick:()=>n(`/calendar?${c.toString()}`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-blue-700 bg-blue-50 hover:bg-blue-100 border border-blue-200 rounded-lg transition-colors whitespace-nowrap",children:[e.jsx(W,{className:"w-3.5 h-3.5"}),"Book Appt"]}),e.jsxs("button",{onClick:()=>a&&a(s.id),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-green-700 bg-green-50 hover:bg-green-100 border border-green-200 rounded-lg transition-colors whitespace-nowrap",children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"Mark Done"]})]})]})})}function as({item:s,onMessageDone:a,dashActions:n}){const i=J();if(s._type==="message")return e.jsx(ts,{item:s,onDone:a});const c=s.status==="new",r=s._isConflict,g=es(s.notes),l=n!=null&&n.itemTitle?n.itemTitle(s):s.customer_name||s.caller_name||"Unknown Customer",m=n!=null&&n.itemSubtitle?n.itemSubtitle(s):s.service||s.service_type;return e.jsx("div",{className:` 13 w-full text-left p-4 rounded-xl border-2 14 ${r?"bg-red-50 border-red-400 ring-2 ring-red-200":c?"bg-amber-50 border-amber-300":"bg-white border-gray-200"} 15 `,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:` 16 w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 17 ${r?"bg-red-200 text-red-700":c?"bg-amber-200 text-amber-700":"bg-gray-100 text-gray-600"} 18 `,children:r?e.jsx("span",{className:"text-lg",children:"â ï¸"}):c?e.jsx(Je,{className:"w-5 h-5"}):e.jsx(he,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:` 19 text-xs font-bold uppercase tracking-wide px-2 py-0.5 rounded 20 ${r?"bg-red-200 text-red-800":c?"bg-amber-200 text-amber-800":"bg-gray-200 text-gray-700"} 21 `,children:r?"â ï¸ CONFLICT":c?"ð NEEDS REVIEW":"â³ AWAITING CONFIRM"}),s.job_id&&e.jsx(ss,{jobStatus:s._jobStatus})]}),e.jsxs("h3",{className:"font-semibold text-gray-900 mt-1.5 truncate",children:[l,m&&e.jsxs("span",{className:"text-gray-500 font-normal",children:[" â ",m]})]}),r&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:s._conflictReason||"Scheduled on a blocked day â needs rescheduling"}),e.jsxs("div",{className:"flex items-center gap-4 mt-1.5 text-sm text-gray-600 flex-wrap",children:[(s.customer_phone||s.caller_phone)&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(F,{className:"w-4 h-4"}),fe(s.customer_phone||s.caller_phone)]}),s.date&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(W,{className:"w-4 h-4"}),r?"Conflict:":"Requested:"," ",Pe(s.date),s.time_slot&&`, ${s.time_slot}`]})]}),g&&e.jsxs("p",{className:"mt-2 text-sm text-gray-500 line-clamp-2",children:['"',g,'"']})]}),e.jsxs("div",{className:"flex flex-col gap-2 flex-shrink-0 items-end",children:[s.source_call_id&&e.jsxs("button",{onClick:()=>i(`/calls?call=${s.source_call_id}`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:border-gray-400 transition-colors whitespace-nowrap",children:[e.jsx(F,{className:"w-3.5 h-3.5"}),"View Call"]}),e.jsxs("button",{onClick:()=>i(`/calendar?appointment=${s.id}`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors whitespace-nowrap ${r?"text-red-700 bg-red-100 hover:bg-red-200 border border-red-300":c?"text-amber-700 bg-amber-100 hover:bg-amber-200 border border-amber-300":"text-blue-700 bg-blue-50 hover:bg-blue-100 border border-blue-200"}`,children:[e.jsx(W,{className:"w-3.5 h-3.5"}),"Calendar"]})]})]})})}function me({items:s,onMessageDone:a,tenantId:n,dashActions:i}){if(s.length===0)return e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-16 h-16 mx-auto bg-green-100 rounded-full flex items-center justify-center mb-4",children:e.jsx(B,{className:"w-8 h-8 text-green-600"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"All caught up!"}),e.jsx("p",{className:"text-gray-500 mt-1",children:(i==null?void 0:i.emptyMessage)||"No items need your attention."})]});const c=[...s].sort((m,o)=>m._isConflict&&!o._isConflict?-1:!m._isConflict&&o._isConflict?1:m._type==="message"&&m.urgency==="urgent"&&!(o._type==="message"&&o.urgency==="urgent")?-1:o._type==="message"&&o.urgency==="urgent"&&!(m._type==="message"&&m.urgency==="urgent")?1:m.status==="new"&&o.status!=="new"?-1:m.status!=="new"&&o.status==="new"?1:new Date(m.created_at)-new Date(o.created_at)),r=s.filter(m=>m.status==="new"&&m._type!=="message").length,g=s.filter(m=>m.status==="pending").length,l=s.filter(m=>m._type==="message").length;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4 flex-wrap",children:[l>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-sm text-blue-700 bg-blue-50 px-3 py-1 rounded-full",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),l," callback",l!==1?"s":""]}),r>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-sm text-amber-700 bg-amber-50 px-3 py-1 rounded-full",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-500"})]}),r," need review"]}),g>0&&e.jsxs("span",{className:"text-sm text-gray-600 bg-gray-100 px-3 py-1 rounded-full",children:[g," awaiting"]})]}),e.jsx("div",{className:"space-y-3",children:c.map(m=>e.jsx(as,{item:m,onMessageDone:a,dashActions:i},m.id))})]})}function xe({icon:s,label:a,title:n,value:i,subtitle:c,trend:r,trendUp:g,className:l=""}){const m=a||n,o=typeof r=="number"&&!isNaN(r);return e.jsxs("div",{className:`bg-white rounded-xl border border-gray-200 p-4 ${l}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm text-gray-500",children:m}),s&&e.jsx("span",{className:"w-4 h-4 text-gray-400",children:s})]}),e.jsx("div",{className:"text-2xl font-bold text-gray-900",children:i}),c&&e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:c}),o&&e.jsxs("div",{className:`mt-1 text-xs font-medium ${r>=0?"text-green-600":"text-red-600"}`,children:[r>=0?"â":"â"," ",Math.abs(r),"% from last week"]}),!o&&r&&e.jsx("div",{className:`mt-1 text-xs font-medium ${g?"text-green-600":"text-gray-500"}`,children:r})]})}function ls({title:s,titleId:a,...n},i){return t.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"
21currentColor","aria-hidden":"true","data-slot":"icon",ref:i,"aria-labelledby":a},n),s?t.createElement("title",{id:a},s):null,t.createElement("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"}))}const ue=t.forwardRef(ls);function rs({tenant:s,progress:a,onDismiss:n,onComplete:i}){const c=J(),[r,g]=t.useState(!1),[l,m]=t.useState(a),[o,S]=t.useState(!1),[f,u]=t.useState(!1);t.useEffect(()=>{a&&m(a)},[a]),t.useEffect(()=>{if(!(s!=null&&s.id)||f||l!=null&&l.wizard_completed_at||l!=null&&l.wizard_dismissed_at)return;let d=!1;return ke(s.id).then(N=>{!d&&N&&m(N)}).catch(()=>{}).finally(()=>{d||u(!0)}),()=>{d=!0}},[s==null?void 0:s.id,f,l==null?void 0:l.wizard_completed_at,l==null?void 0:l.wizard_dismissed_at]);const C=t.useMemo(()=>He(s==null?void 0:s.business_type,s==null?void 0:s.business_subtype),[s==null?void 0:s.business_type,s==null?void 0:s.business_subtype]),w=t.useMemo(()=>{if(!C||!l)return[];const d=l.wizard_steps||{};return C.map(N=>{var I;const U=((I=d[N.id])==null?void 0:I.completed)===!0||l[N.id]===!0||N.id==="test_call"&&l.test_call_completed===!0;return{...N,completed:U}})},[C,l]),h=w.filter(d=>d.completed).length,k=w.length,M=w.filter(d=>d.required!==!1),L=M.length>0&&M.every(d=>d.completed),R=k>0?Math.round(h/k*100):0;t.useEffect(()=>{L&&!o&&!(l!=null&&l.wizard_completed_at)&&(S(!0),i&&i())},[L,o,l==null?void 0:l.wizard_completed_at,i]),t.useEffect(()=>{if(!o)return;const d=setTimeout(()=>g(!0),1e4);return()=>clearTimeout(d)},[o]);const z=t.useCallback(()=>{g(!0),n&&n()},[n]),T=t.useCallback(async()=>{if(g(!0),s!=null&&s.id)try{await De(s.id)}catch{}n&&n()},[s==null?void 0:s.id,n]),O=t.useCallback(d=>{d.route?c(d.route):d.settingsTab&&c(`/settings?tab=${d.settingsTab}`)},[c]),P=t.useCallback(d=>{if(d.route)return"Go to Calls";const N=d.settingsTab&&Ge[d.settingsTab];return N?`Go to ${N.label}`:"Configure"},[]);return!l||!s||l.guided_setup_completed&&!o||l.wizard_completed_at&&!o||l.wizard_dismissed_at||r?null:o?e.jsx("div",{className:"bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200 rounded-xl p-6 mb-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-full bg-green-100 shrink-0",children:e.jsx(ue,{className:"w-6 h-6 text-green-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold text-green-800 text-lg mb-1",children:"You're all set!"}),e.jsx("p",{className:"text-sm text-green-700 mb-4",children:"Your AI agent has everything it needs. Callers will get great answers about your business. You can always update your data in Settings."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>c("/settings"),className:"px-4 py-2 bg-green-600 hover:bg-green-700 text-white text-sm font-medium rounded-lg transition-colors",children:"Go to Settings"}),e.jsx("button",{onClick:()=>g(!0),className:"text-sm text-green-600 hover:text-green-800",children:"Dismiss"})]})]})]}),e.jsx("button",{onClick:()=>g(!0),className:"p-1 text-green-400 hover:text-green-600 rounded-lg hover:bg-green-100",children:e.jsx(de,{className:"w-5 h-5"})})]})}):e.jsx("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200 rounded-xl p-4 sm:p-6 mb-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-full bg-blue-100 shrink-0",children:e.jsx(Ve,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-1",children:"Welcome! Let's get your agent ready."}),e.jsx("p",{className:"text-sm text-slate-600 mb-4",children:"Your AI phone agent is live, but it needs your business data to give callers great answers. Complete these steps to get the best experience."}),e.jsxs("div",{className:"mb-5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-500 mb-1",children:[e.jsxs("span",{children:[h," of ",k," steps complete"]}),e.jsxs("span",{children:[R,"%"]})]}),e.jsx("div",{className:"w-full h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-blue-500 rounded-full transition-all duration-500",style:{width:`${R}%`}})})]}),e.jsx("div",{className:"space-y-3 mb-5",children:w.map(d=>e.jsxs("div",{className:`flex items-start gap-3 ${d.completed?"opacity-70":""}`,children:[e.jsx("div",{className:"mt-0.5 shrink-0",children:d.completed?e.jsx(ue,{className:"w-5 h-5 text-green-500"}):e.jsx(B,{className:"w-5 h-5 text-slate-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:`text-sm font-medium ${d.completed?"text-slate-500 line-through":"text-slate-800"}`,children:[d.label,d.required===!1&&e.jsx("span",{className:"ml-1.5 text-xs font-normal text-slate-400",children:"(optional)"})]}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:d.description})]}),e.jsx("div",{className:"shrink-0 mt-0.5",children:d.completed?e.jsx("span",{className:"text-xs text-green-600 font-medium",children:"Completed"}):e.jsxs("button",{onClick:()=>O(d),className:"inline-flex items-center gap-1 text-xs font-medium text-blue-600 hover:text-blue-800 whitespace-nowrap",children:[P(d),e.jsx(Ze,{className:"w-3 h-3"})]})})]},d.id))}),e.jsxs("div",{className:"flex items-center gap-3 pt-2 border-t border-blue-100",children:[e.jsx("button",{onClick:T,className:"text-xs text-slate-400 hover:text-slate-600",children:"Dismiss forever"}),e.jsx("button",{onClick:z,className:"text-xs text-slate-500 hover:text-slate-700",children:"Remind me later"})]})]})]}),e.jsx("button",{onClick:z,className:"p-1 text-slate-400 hover:text-slate-600 rounded-lg hover:bg-slate-100 shrink-0",children:e.jsx(de,{className:"w-5 h-5"})})]})})}function ns(){var f;const{user:s,loading:a}=$e(),{tenantId:n,loading:i}=Q(),[c,r]=t.useState(null),[g,l]=t.useState(!0),[m,o]=t.useState(null);if(t.useEffect(()=>{if(a||i||!n||!s)return;let u=!1;return(async()=>{try{l(!0),o(null);const w=await Ye(n);u||r(w)}catch(w){console.error("Weather fetch error:",w),u||o(w.message||"Weather unavailable")}finally{u||l(!1)}})(),()=>{u=!0}},[n,i,a,s]),g)return e.jsx("div",{className:"bg-white border border-gray-200 rounded-xl p-3 h-full animate-pulse",children:e.jsx("div",{className:"h-6 bg-gray-100 rounded w-full"})});if(m||!((f=c==null?void 0:c.days)!=null&&f.length))return null;const S=(u,C)=>C===0?"Today":new Date(u+"T12:00:00").toLocaleDateString("en-US",{weekday:"short"});return e.jsx("div",{className:"bg-white border border-gray-200 rounded-xl p-3 h-full",children:e.jsx("div",{className:"flex items-center justify-between gap-1 overflow-x-auto",children:c.days.map((u,C)=>e.jsxs(ze.Fragment,{children:[e.jsxs("div",{className:"flex flex-col items-center px-2 py-1 rounded-lg min-w-[52px] hover:bg-gray-50",title:`${u.condition} - High: ${u.high}° Low: ${u.low}°`,children:[e.jsx("span",{className:"text-xs font-medium text-gray-500",children:S(u.date,C)}),e.jsx("span",{className:"text-xl my-0.5",children:u.icon}),e.jsxs("div",{className:"flex items-baseline gap-0.5",children:[e.jsxs("span",{className:"text-sm font-semibold text-gray-700",children:[u.high,"°"]}),e.jsxs("span",{className:"text-xs text-gray-400",children:["/",u.low,"°"]})]}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-gray-400",children:[u.precip_chance>0&&e.jsxs("span",{className:u.precip_chance>=50?"text-blue-600":"",children:["ð§",u.precip_chance,"%"]}),u.wind_mph&&e.jsxs("span",{className:u.wind_mph>=15?"text-amber-600":"",children:["ð¨",u.wind_mph]})]})]}),C===0&&e.jsx("div",{className:"h-12 w-px bg-gray-300 mx-1 flex-shrink-0"})]},u.date))})})}function is(){const{tenant:s}=Q(),[a,n]=t.useState(new Date),i=(s==null?void 0:s.timezone)||"America/Los_Angeles";t.useEffect(()=>{const l=setInterval(()=>{n(new Date)},1e3);return()=>clearInterval(l)},[]);const c=()=>a.toLocaleTimeString("en-US",{timeZone:i,hour:"numeric",minute:"2-digit",hour12:!0}),r=()=>a.toLocaleDateString("en-US",{timeZone:i,weekday:"long",month:"long",day:"numeric"}),g=()=>a.toLocaleTimeString("en-US",{timeZone:i,timeZoneName:"short"}).split(" ").pop();return e.jsxs("div",{className:"bg-white border border-gray-200 rounded-xl p-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-3xl font-bold text-gray-900 tabular-nums",children:c()}),e.jsx("div",{className:"text-sm text-gray-500 mt-1",children:r()})]}),e.jsx("div",{className:"text-xs text-gray-400 self-start",children:g()})]})}const ge=[{value:"happy",emoji:"ð",label:"Great"},{value:"neutral",emoji:"ð",label:"Okay"},{value:"sad",emoji:"ð",label:"Poor"}];function cs({tenantId:s,onSubmit:a}){var w;const[n,i]=t.useState(!1),[c,r]=t.useState("rating"),[g,l]=t.useState(null),[m,o]=t.useState(""),[S,f]=t.useState(!1);if(n)return null;const u=h=>{l(h),r("comment")},C=async()=>
21{if(g){f(!0);try{await Me(s,g,m.trim()||null,"dashboard"),r("done"),setTimeout(()=>{a&&a(),i(!0)},2500)}catch{f(!1)}}};return e.jsxs("div",{className:"relative mb-4 bg-blue-50 border border-blue-200 rounded-xl px-5 py-4",children:[e.jsx("button",{onClick:()=>i(!0),className:"absolute top-3 right-3 text-blue-300 hover:text-blue-500 text-lg leading-none","aria-label":"Dismiss",children:"Ã"}),c==="rating"&&e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-blue-800",children:"How is Smart Voice Agent working for you?"}),e.jsx("div",{className:"flex items-center gap-2",children:ge.map(h=>e.jsxs("button",{onClick:()=>u(h.value),className:"flex flex-col items-center gap-0.5 group",children:[e.jsx("span",{className:"text-2xl group-hover:scale-110 transition-transform",children:h.emoji}),e.jsx("span",{className:"text-xs text-blue-600",children:h.label})]},h.value))})]}),c==="comment"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:(w=ge.find(h=>h.value===g))==null?void 0:w.emoji}),e.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Thanks! Any additional comments? (optional)"})]}),e.jsx("textarea",{value:m,onChange:h=>o(h.target.value),rows:2,placeholder:"Tell us more...",className:"w-full text-sm border border-blue-200 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400 resize-none bg-white"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:C,disabled:S,className:"px-4 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg disabled:opacity-50 transition-colors",children:S?"Sending...":"Submit"}),e.jsx("button",{onClick:()=>i(!0),className:"text-sm text-blue-500 hover:text-blue-700",children:"Skip"})]})]}),c==="done"&&e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-blue-800",children:[e.jsx("span",{children:"â"}),e.jsx("span",{children:"Thank you for your feedback!"})]})]})}function ks(){const s=Te(),{tenantId:a,loading:n}=Q(),[i,c]=t.useState(!0),[r,g]=t.useState([]),[l,m]=t.useState([]),[o,S]=t.useState(null),[f,u]=t.useState(null),[C,w]=t.useState(null),[h,k]=t.useState("all"),[M,L]=t.useState(!1),[R,z]=t.useState([]),[T,O]=t.useState(!1),[P,d]=t.useState(!1),N=t.useMemo(()=>qe(f==null?void 0:f.business_type,f==null?void 0:f.business_subtype),[f==null?void 0:f.business_type,f==null?void 0:f.business_subtype]),{isActive:U}=Ae(),I=U("fleet_management");t.useEffect(()=>{Fe("feature_viewed",{feature:"dashboard"})},[]);const{calls:K}=Be(a,50),pe=t.useMemo(()=>{const x=new Date().toDateString();return K.filter(y=>{var D,$;return new Date((($=(D=y.created_at)==null?void 0:D.toDate)==null?void 0:$.call(D))||y.created_at||y.timestamp).toDateString()===x}).length},[K]),be=t.useMemo(()=>{const x=new Date().toISOString().split("T")[0];return r.filter(y=>{var _;return y.status==="confirmed"&&((_=y.confirmed_at)==null?void 0:_.startsWith(x))}).length},[r]);t.useEffect(()=>{async function x(){var y;if(a){c(!0);try{const _=new Date;_.setDate(_.getDate()-7);const D=_.toISOString().split("T")[0],$=new Date;$.setDate($.getDate()+14);const Ne=$.toISOString().split("T")[0],[se,H,q,te,ae,G]=await Promise.allSettled([Re(a),Z(a,{status:"new,pending"}),Z(a,{date_from:D,date_to:Ne}),Ie(a),Ee(a),Y(a,{status:"new"})]);if(se.status==="fulfilled"){const p=se.value;if(u(p),!(p!=null&&p.feedback_opt_out)){const v=p==null?void 0:p.next_feedback_due,b=!v||new Date(((y=v==null?void 0:v.toDate)==null?void 0:y.call(v))||v)<=new Date;L(b)}}ae.status==="fulfilled"&&w(ae.value);const V=q.status==="fulfilled"?Array.isArray(q.value)?q.value:[]:[];m(V);const le=[],re=new Set;if(I){const p=V.filter(b=>b.end_date&&b.status!=="cancelled");V.filter(b=>b.end_date||b.exception?!1:p.some(j=>b.date>=j.date&&b.date<=j.end_date)).forEach(b=>{const j=p.find(oe=>b.date>=oe.date&&b.date<=oe.end_date),Se=(j==null?void 0:j.caller_name)||(j==null?void 0:j.customer_name)||"another job",ce=j?j.date===j.end_date?j.date:`${j.date} â ${j.end_date}`:null;re.add(b.id),le.push({...b,_isConflict:!0,_conflictReason:ce?`Overlaps ${Se} (${ce})`:"Scheduled on a blocked day"})})}const ve=H.status==="fulfilled"?Array.isArray(H.value)?H.value:[]:[],ne=[...le,...ve.filter(p=>!re.has(p.id))],_e=G.status==="fulfilled"?Array.isArray(G.value)?G.value:[]:[],Ce=[...ne,..._e.map(p=>({...p,_type:"message"}))];g(Ce);const ie=ne.filter(p=>p.job_id);ie.length>0&&Promise.all(ie.map(p=>We(a,p.job_id).then(v=>{var b;return{id:p.id,jobStatus:(b=(v==null?void 0:v.job)||v)==null?void 0:b.status}}).catch(()=>({id:p.id,jobStatus:null})))).then(p=>{const v=Object.fromEntries(p.map(b=>[b.id,b.jobStatus]));g(b=>b.map(j=>j.job_id?{...j,_jobStatus:v[j.id]}:j))}),te.status==="fulfilled"&&S(te.value)}catch(_){console.error("Dashboard load error:",_),s.error("Failed to load dashboard")}finally{c(!1)}}}!n&&a&&x()},[a,n,s,I]);const X=t.useMemo(()=>h==="all"?r:h==="conflict"?r.filter(x=>x._isConflict):r.filter(x=>x.status===h),[r,h]),je=async()=>{c(!0);try{const[x,y]=await Promise.all([Z(a,{status:"new,pending"}),Y(a,{status:"new"})]),_=Array.isArray(x)?x:[],D=Array.isArray(y)?y.map($=>({...$,_type:"message"})):[];g([..._,...D]),s.success("Refreshed")}catch{s.error("Failed to refresh")}finally{c(!1)}},we=async x=>{try{await Oe(a,x,{status:"done"}),g(y=>y.filter(_=>!(_._type==="message"&&_.id===x))),s.success("Marked as done")}catch{s.error("Failed to update message")}},ye=async()=>
21{if(T){O(!1);return}d(!0),O(!0);try{const x=await Y(a,{status:"done"});z(Array.isArray(x)?x.map(y=>({...y,_type:"message"})):[])}catch{s.error("Failed to load handled callbacks")}finally{d(!1)}};if(n)return e.jsx("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-8",children:e.jsx(Le,{})});const E=r.filter(x=>x.status==="new").length,ee=r.filter(x=>x.status==="pending").length,A=r.filter(x=>x._isConflict).length;return e.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-6 py-4 sm:py-8",children:[e.jsxs("div",{className:"mb-4 sm:mb-8",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold text-gray-900",children:f!=null&&f.business_name?`${f.business_name} Dashboard`:"Dashboard"}),e.jsxs("p",{className:"text-sm sm:text-base text-gray-500 mt-1",children:["Manage your ",N.actionLabel.toLowerCase()," and calls"]})]}),e.jsx(rs,{tenant:f,progress:C,onDismiss:()=>w(x=>x&&{...x,wizard_dismissed_at:new Date().toISOString()}),onComplete:()=>w(x=>x&&{...x,wizard_completed_at:new Date().toISOString()})}),M&&a&&e.jsx(cs,{tenantId:a,onSubmit:()=>L(!1)}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 mb-4",children:[e.jsx(is,{}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(ns,{})})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-4 mb-8",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm text-gray-500",children:N.actionLabel}),e.jsx(W,{className:"w-4 h-4 text-gray-400"})]}),e.jsx("div",{className:"text-2xl font-bold text-gray-900",children:r.length}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs",children:[E>0&&e.jsxs("span",{className:"text-amber-600",children:[E," review"]}),A>0&&e.jsxs("span",{className:"text-red-600",children:["â ï¸ ",A," conflict",A>1?"s":""]}),E===0&&A===0&&ee>0&&e.jsxs("span",{className:"text-gray-500",children:[ee," awaiting"]})]})]}),e.jsx(xe,{title:"Calls Today",value:pe,icon:e.jsx(F,{className:"w-5 h-5"})}),e.jsx(xe,{title:"Confirmed Today",value:be,icon:e.jsx(B,{className:"w-5 h-5"})}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Calls This Billing Cycle"}),e.jsx(F,{className:"w-4 h-4 text-gray-400"})]}),e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-xl font-bold text-gray-900",children:o.calls}),e.jsx("span",{className:"text-sm text-gray-400",children:"calls"})]})]}),e.jsxs("div",{className:`bg-white rounded-xl border p-4 ${o.over_minutes?"border-red-300 bg-red-50":"border-gray-200"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Plan Minutes"}),o.over_minutes?e.jsx("span",{className:"text-xs text-red-600 font-medium",children:"â ï¸"}):e.jsx(he,{className:"w-4 h-4 text-gray-400"})]}),e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:`text-xl font-bold ${o.over_minutes?"text-red-600":"text-gray-900"}`,children:Math.round(o.minutes)}),e.jsxs("span",{className:"text-sm text-gray-400",children:["/ ",o.minute_limit]})]}),e.jsx("div",{className:"w-full h-1.5 bg-gray-200 rounded-full overflow-hidden mt-2",children:e.jsx("div",{className:`h-full rounded-full ${o.minute_pct>100?"bg-red-500 animate-pulse":o.minute_pct>90?"bg-red-500":o.minute_pct>70?"bg-amber-500":"bg-blue-500"}`,style:{width:`${Math.min(o.minute_pct,100)}%`}})})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-gray-200 bg-gray-50 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-base sm:text-lg font-semibold text-gray-900",children:N.actionLabel}),r.length>0&&e.jsxs("span",{className:"text-sm text-gray-500",children:["(",X.length," shown)"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-gray-100 rounded-lg p-1 overflow-x-auto",children:[e.jsx("button",{onClick:()=>k("all"),className:`px-2.5 sm:px-3 py-1 text-xs sm:text-sm rounded-md transition-colors whitespace-nowrap min-h-[36px] ${h==="all"?"bg-white shadow text-gray-900":"text-gray-600 hover:text-gray-900"}`,children:"All"}),e.jsxs("button",{onClick:()=>k("new"),className:`px-2.5 sm:px-3 py-1 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1 whitespace-nowrap min-h-[36px] ${h==="new"?"bg-white shadow text-amber-700":"text-gray-600 hover:text-gray-900"}`,children:["Review",E>0&&e.jsx("span",{className:"bg-amber-200 text-amber-800 text-xs px-1.5 rounded-full",children:E})]}),e.jsx("button",{onClick:()=>k("pending"),className:`px-2.5 sm:px-3 py-1 text-xs sm:text-sm rounded-md transition-colors whitespace-nowrap min-h-[36px] ${h==="pending"?"bg-white shadow text-gray-900":"text-gray-600 hover:text-gray-900"}`,children:"Awaiting"}),A>0&&e.jsxs("button",{onClick:()=>k("conflict"),className:`px-2.5 sm:px-3 py-1 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1 whitespace-nowrap min-h-[36px] ${h==="conflict"?"bg-white shadow text-red-700":"text-gray-600 hover:text-gray-900"}`,children:["Conflicts",e.jsx("span",{className:"bg-red-200 text-red-800 text-xs px-1.5 rounded-full",children:A})]})]}),e.jsx("button",{onClick:je,disabled:i,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-lg transition-colors disabled:opacity-50 min-h-[44px] min-w-[44px] flex items-center justify-center",children:e.jsx(Ue,{className:`w-5 h-5 ${i?"animate-spin":""}`})})]})]}),e.jsx("div",{className:"p-3 sm:p-6",children:i?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-gray-300 border-t-blue-600 mx-auto"}),e.jsx("p",{className:"text-gray-500 mt-3",children:"Loading..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{items:X,onMessageDone:we,tenantId:a,dashActions:N}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-100",children:[e.jsxs("button",{onClick:ye,className:"text-sm text-gray-500 hover:text-gray-700 flex items-center gap-1",children:[e.jsx("span",{children:T?"â¾":"â¸"}),T?"Hide handled callbacks":"View handled callbacks"]}),T&&e.jsx("div",{className:"mt-3",children:P?e.jsx("p",{className:"text-sm text-gray-400",children:"Loading..."}):R.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No handled callbacks yet."}):e.jsx("div",{className:"space-y-2 opacity-70",children:e.jsx(me,{items:R})})})]})]})})]})]})}export{ks 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.