1import{a as o,j as e}from"./vendor-query-B-_nDQQY.js";import{b as f,L as M}from"./index-D8ww6b7J.js";/* empty css */import{M as L,T as I,a as j,P as _,b as S,L as d}from"./vendor-leaflet-CQpbWEOL.js";import{u as D}from"./vendor-react-BUIlT3ms.js";import"./vendor-three-1K-S22da.js";import"./vendor-charts-i-522T5A.js";import"./vendor-pdf-Bwkk3Ew0.js";import"./vendor-radix-X0WMATEu.js";delete d.Icon.Default.prototype._getIconUrl;d.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"});function P(){return d.divIcon({html:`<div style=" 2 background: #f59e0b; 3 border: 3px solid white; 4 border-radius: 50%; 5 width: 28px; 6 height: 28px; 7 box-shadow: 0 4px 12px rgba(0,0,0,0.4); 8 display: flex; 9 align-items: center; 10 justify-content: center; 11 "> 12 <svg width="16" height="16" viewBox="0 0 24 24" fill="white"> 13 <path d="M12 2L2 22h20L12 2zm0 3.5L18.5 20H5.5L12 5.5z"/> 14 </svg> 15 </div>`,className:"driver-marker",iconSize:[28,28],iconAnchor:[14,14]})}function z(){return d.divIcon({html:`<div style=" 16 background: #84cc16; 17 border: 3px solid white; 18 border-radius: 50%; 19 width: 24px; 20 height: 24px; 21 box-shadow: 0 4px 12px rgba(0,0,0,0.3); 22 "></div>`,className:"location-marker",iconSize:[24,24],iconAnchor:[12,12]})}function E(n,t,l,r){const m=(l-n)*Math.PI/180,h=(r-t)*Math.PI/180,i=Math.sin(m/2)**2+Math.cos(n*Math.PI/180)*Math.cos(l*Math.PI/180)*Math.sin(h/2)**2;return 3959*2*Math.atan2(Math.sqrt(i),Math.sqrt(1-i))}function T(n,t=35){return Math.round(n/t*60)}function F(){const{jobId:n}=D(),[t,l]=o.useState(null),[r,u]=o.useState(null),[m,h]=o.useState(!0),[i,v]=o.useState(null),[x,y]=o.useState(null),[p,k]=o.useState(null);o.useEffect(()=>{w();const a=setInterval(()=>{g()},1e4);return()=>clearInterval(a)},[n]);const w=async()=>{try{const s=(await f.entities.Job.list()).find(c=>c.id===n);s&&(l(s),s.job_address_lat&&s.job_address_lng&&p&&p.setView([s.job_address_lat,s.job_address_lng],13),await g())}catch(a){console.error("Error loading job:",a)}finally{h(!1)}},g=async()=>{try{const a=await f.entities.TimeEntry.filter({job_id:n,clock_out_time:null});if(a.length>0){const s=a[0];if(s.clock_in_lat&&s.clock_in_lng){const c={lat:s.clock_in_lat,lng:s.clock_in_lng,clockInTime:new Date(s.clock_in_time)};if(u(c),t!=null&&t.job_address_lat&&(t!=null&&t.job_address_lng)){const b=E(c.lat,c.lng,t.job_address_lat,t.job_address_lng);y(b.toFixed(1));const N=T(b);v(N)}}}}catch(a){console.error("Error fetching location:",a)}};return m?e.jsx("div",{className:"fixed inset-0 bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(M,{className:"w-12 h-12 animate-spin mx-auto text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading map..."})]})}):t?e.jsxs("div",{className:"fixed inset-0 bg-background",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 z-[1000] bg-gradient-to-b from-black/80 to-transparent p-4 pointer-events-none",children:e.jsx("div",{className:"max-w-md mx-auto",children:e.jsx("div",{className:"bg-white/95 backdrop-blur rounded-lg p-4 shadow-lg pointer-events-auto",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm",children:t.customer_name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i!==null?`${i} min away`:"Preparing"})]}),x&&e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Distance"}),e.jsxs("p",{className:"font-bold text-sm",children:[x," mi"]})]})]})})})}),e.jsxs(L,{ref:k,center:t.job_address_lat?[t.job_address_lat,t.job_address_lng]:[28.5,-81.5],zoom:13,style:{height:"100%",width:"100%"},scrollWheelZoom:!0,zoomControl:!1,attributionControl:!1,children:[e.jsx(I,{url:"https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}",attribution:"© OpenStreetMap © CARTO"}),r&&t.job_address_lat&&t.job_address_lng&&e.jsxs(e.Fragment,{children:[e.jsx(j,{position:[r.lat,r.lng],icon:P(),children:e.jsx(_,{children:e.jsx("div",{className:"text-sm font-semibold",children:"ð Your Technician"})})}),e.jsx(j,{position:[t.job_address_lat,t.job_address_lng],icon:z(),children:e.jsx(_,{children:e.jsx("div",{className:"text-sm font-semibold",children:"ð Your Location"})})}),e.jsx(S,{positions:[[r.lat,r.lng],[t.job_address_lat,t.job_address_lng]],pathOptions:{color:"#84cc16",weight:5,opacity:.9,dashArray:"12, 8"}})]})]}),r&&e.jsx("div",{className:"absolute bottom-4 right-4 z-[1000] bg-white/95 backdrop-blur rounded-full px-4 py-2 shadow-lg text-xs text-muted-foreground",children:"Live GPS ⢠Updates every 10s"})]}):e.jsx("div",{className:"fixed inset-0 bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-4 p-6",children:[e.jsx("p",{className:"text-lg font-semibold",children:"Tracking link not found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This link may have expired"})]})})}export{F 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.