1import{r as o,s as k,m as s,B as b,L as I,D as S,w as $,o as z,x as M}from"./index-CpSGH3si.js";import{M as B,T as U,a as D,P as E,u as F,L as f}from"./leaflet-DGXHz3bg.js";import{L as G}from"./layers-BrLtODAJ.js";import{R as T}from"./refresh-cw-Wgel5wP6.js";import{N as j,P as Q}from"./Polyline-Bicuu4ZU.js";import{C as K}from"./circle-alert-CRwkKVNs.js";import{P as W}from"./phone-B5j7AMqT.js";import{a as Z}from"./format-DRR4LvZs.js";import"./differenceInCalendarDays-CFJcUmo7.js";delete f.Icon.Default.prototype._getIconUrl;f.Icon.Default.mergeOptions({iconRetinaUrl:"https://unpkg.com/[email protected]/dist/images/marker-icon-2x.png",iconUrl:"https://unpkg.com/[email protected]/dist/images/marker-icon.png",shadowUrl:"https://unpkg.com/[email protected]/dist/images/marker-shadow.png"});const C={scheduled:"#3b82f6",in_progress:"#f59e0b",quoted:"#a78bfa"},R="#10b981";function H(a,l){return f.divIcon({className:"",html:`<div style="background:${a};color:#fff;border-radius:50% 50% 50% 0;transform:rotate(-45deg);width:30px;height:30px;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:11px;box-shadow:0 2px 6px rgba(0,0,0,0.3);border:2px solid #fff;"> 2 <span style="transform:rotate(45deg)">${l}</span></div>`,iconSize:[30,30],iconAnchor:[15,30],popupAnchor:[0,-34]})}async function V(a){const l=`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(a)}&format=json&limit=1`,d=await(await fetch(l,{headers:{"Accept-Language":"en"}})).json();return d!=null&&d[0]?[parseFloat(d[0].lat),parseFloat(d[0].lon)]:null}function X({positions:a}){const l=F();return o.useEffect(()=>{a.length&&(a.length===1?l.setView(a[0],12):l.fitBounds(f.latLngBounds(a),{padding:[40,40]}))},[a,l]),null}function de({contractorId:a,contractorEmail:l}){const[x,d]=o.useState({}),[O,N]=o.useState(!1),[w,P]=o.useState(!1),[m,A]=o.useState("all");Z(new Date,"yyyy-MM-dd");const{data:y=[]}=k({queryKey:["dashboard-map-jobs",l],queryFn:()=>M.entities.Job.filter({contractor_id:l},"-scheduled_date",100),enabled:!!l}),{data:v=[]}=k({queryKey:["dashboard-map-leads",a],queryFn:()=>M.entities.Lead.filter({contractor_id:a},"-created_date",100),enabled:!!a}),h=o.useMemo(()=>y.filter(e=>e.service_address&&["scheduled","in_progress","quoted"].includes(e.status)),[y]),u=o.useMemo(()=>v.filter(e=>e.address&&!["won","lost"].includes(e.status)),[v]),i=o.useMemo(()=>{const e=[];return m!=="leads"&&h.forEach(t=>e.push({type:"job",id:t.id,address:t.service_address,data:t})),m!=="jobs"&&u.forEach(t=>{const n=[t.address,t.city,t.state,t.zip].filter(Boolean).join(", ");n&&e.push({type:"lead",id:t.id,address:n,data:t})}),e},[h,u,m]);o.useEffect(()=>{const e=i.map(t=>t.address).filter(t=>t&&!(t in x));e.length&&(N(!0),Promise.all(e.map(t=>V(t).then(n=>({addr:t,coords:n})).catch(()=>({addr:t,coords:null})))).then(t=>{d(n=>{const r={...n};return t.forEach(({addr:p,coords:q})=>{r[p]=q}),r}),N(!1)}))},[i]);const c=i.map((e,t)=>({...e,coords:x[e.address],idx:t+1})).filter(e=>e.coords),g=c.map(e=>e.coords),J=()=>{if(!c.length)return;const e=c.map(t=>t.coords.join(",")).join("/");window.open(`https://www.google.com/maps/dir/${e}`,"_blank")},_=e=>({scheduled:"Scheduled",in_progress:"In Progress",quoted:"Quoted"})[e]||e,L=e=>({new:"New",contacted:"Contacted",qualified:"Qualified",proposal_sent:"Proposal Sent",negotiating:"Negotiating",appointment_scheduled:"Appt. Scheduled"})[e]||e;return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(G,{className:"w-4 h-4 text-slate-500"}),s.jsx("div",{className:"flex rounded-lg border border-slate-200 overflow-hidden text-sm",children:[["all","All"],["jobs","Jobs"],["leads","Leads"]].map(([e,t])=>s.jsx("button",{onClick:()=>A(e),className:`px-3 py-1.5 transition-colors ${m===e?"bg-slate-900 text-white":"bg-white text-slate-600 hover:bg-slate-50"}`,children:t},e))}),O&&s.jsxs("span",{className:"flex items-center gap-1 text-xs text-slate-400",children:[s.jsx(T,{className:"w-3 h-3 animate-spin"})," Locatingâ¦"]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(b,{variant:"outline",size:"sm",onClick:()=>P(e=>!e),disabled:c.length<2,className:"gap-1.5",children:[s.jsx(j,{className:"w-3.5 h-3.5"}),w?"Hide Route":"Route Line"]}),s.jsxs(b,{size:"sm",className:"bg-blue-600 hover:bg-blue-700 gap-1.5",onClick:J,disabled:!c.length,children:[s.jsx(j,{className:"w-3.5 h-3.5"})," Open in Maps"]}),s.jsx(I,{to:"/JobMap",children:s.jsx(b,{variant:"outline",size:"sm",children:"Full Map"})})]})]}),s.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[s.jsxs("span",{className:"flex items-center gap-1.5 text-sm text-slate-600",children:[s.jsx("span",{className:"w-3 h-3 rounded-full bg-blue-500 inline-block"}),h.length," active job",h.length!==1?"s":""]}),s.jsxs("span",{className:"flex items-center gap-1.5 text-sm text-slate-600",children:[s.jsx("span",{className:"w-3 h-3 rounded-full bg-emerald-500 inline-block"}),u.length," open lead",u.length!==1?"s":""]}),s.jsxs("span",{className:"flex items-center gap-1.5 text-sm text-slate-400",children:[s.jsx(S,{className:"w-3.5 h-3.5"}),c.length," pinned on map"]})]}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[s.jsxs("div",{className:"lg:col-span-1 space-y-2 max-h-[420px] overflow-y-auto pr-1",children:[i.length===0&&s.jsx("p",{className:"text-sm text-slate-400 text-center py-8",children:"No items to display."}),i.map((e,t)=>{const n=x[e.address],r=e.type==="job",p=r?C[e.data.status]||"#3b82f6":R;return s.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl border border-slate-200 bg-white hover:shadow-sm transition-shadow",children:[s.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-white text-xs font-bold shrink-0 mt-0.5",style:{background:p},children:r?"J":"L"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"font-semibold text-slate-900 text-sm truncate",children:r?e.data.customer_name:e.data.name}),s.jsxs("p",{className:"text-xs text-slate-500 truncate flex items-center gap-1",children:[s.jsx(S,{className:"w-3 h-3 shrink-0"})," ",e.address]}),s.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[s.jsx($,{className:"text-xs px-1.5 py-0",style:{background:p+"22",color:p,border:"none"},children:r?_(e.data.status):L(e.data.status)}),r&&e.data.scheduled_time&&s.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-0.5",children:[s.jsx(z,{className:"w-3 h-3"})," ",e.data.scheduled_time]}),r&&e.data.estimated_revenue&&s.jsxs("span",{className:"text-xs text-slate-400",children:["$",e.data.estimated_revenue.toLocaleStr
2ing()]}),!r&&e.data.estimated_value&&s.jsxs("span",{className:"text-xs text-slate-400",children:["$",e.data.estimated_value.toLocaleString()]})]}),n===null&&s.jsxs("p",{className:"text-xs text-amber-500 flex items-center gap-1 mt-0.5",children:[s.jsx(K,{className:"w-3 h-3"})," Can't locate address"]})]})]},e.id)})]}),s.jsxs("div",{className:"lg:col-span-2",children:[s.jsx("div",{className:"rounded-2xl overflow-hidden border border-slate-200 shadow-sm",style:{height:420},children:s.jsxs(B,{center:[39.5,-98.35],zoom:4,style:{height:"100%",width:"100%"},scrollWheelZoom:!0,children:[s.jsx(U,{attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',url:"https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png",subdomains:"abcd",maxZoom:19}),s.jsx(X,{positions:g}),w&&g.length>=2&&s.jsx(Q,{positions:g,pathOptions:{color:"#3b82f6",weight:3,dashArray:"6 8",opacity:.8}}),c.map(e=>{const t=e.type==="job",n=t?C[e.data.status]||"#3b82f6":R;return s.jsx(D,{position:e.coords,icon:H(n,t?"J":"L"),children:s.jsx(E,{children:s.jsxs("div",{className:"text-sm min-w-[180px]",children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1",children:s.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-semibold text-white",style:{background:n},children:t?"Job":"Lead"})}),s.jsx("p",{className:"font-semibold text-slate-900",children:t?e.data.customer_name:e.data.name}),s.jsx("p",{className:"text-slate-500 text-xs mt-0.5",children:e.address}),t&&e.data.service_type&&s.jsx("p",{className:"text-xs text-slate-600 mt-1",children:e.data.service_type}),!t&&e.data.project_type&&s.jsx("p",{className:"text-xs text-slate-600 mt-1",children:e.data.project_type}),s.jsx("div",{className:"flex items-center gap-2 mt-1.5",children:s.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium",style:{background:n+"22",color:n},children:t?_(e.data.status):L(e.data.status)})}),(t?e.data.customer_phone:e.data.phone)&&s.jsxs("a",{href:`tel:${t?e.data.customer_phone:e.data.phone}`,className:"text-xs text-blue-600 flex items-center gap-1 mt-1",children:[s.jsx(W,{className:"w-3 h-3"}),t?e.data.customer_phone:e.data.phone]}),s.jsxs("a",{href:`https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(e.address)}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-600 flex items-center gap-1 mt-1",children:[s.jsx(j,{className:"w-3 h-3"})," Get directions"]})]})})},e.id)})]})}),s.jsxs("div",{className:"flex items-center gap-4 mt-2 flex-wrap text-xs text-slate-500",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"w-3 h-3 rounded-full bg-blue-500"})," Scheduled"]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"w-3 h-3 rounded-full bg-amber-400"})," In Progress"]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"w-3 h-3 rounded-full bg-violet-400"})," Quoted"]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"w-3 h-3 rounded-full bg-emerald-500"})," Open Lead"]})]})]})]})]})}export{de 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.