1import{a as C,Y as w,b as S,z as I,r as d,j as e,d as k,C as T,t as f}from"./index-CfcSdzPN.js";import{u as M}from"./useQuery-DDNSg42L.js";import{u as P}from"./useMutation-e7_SgXT4.js";import{u as v}from"./useServerFn-DgcYVCxo.js";import{u as G}from"./org-switcher-provider-DoMbZ9EO.js";import{c as E,a as O,M as _,d as q}from"./mobile-ui-DuR_KxHn.js";import{d as L,b as U}from"./fleet-app.functions-BXbQC9bu.js";import{S as $}from"./shield-check-B6XlA_cA.js";import{T as K}from"./trash-2-qgcxLbn5.js";const A=[{id:"samsara",name:"Samsara",help:"Samsara dashboard â Settings â API tokens. Read-only token is enough.",fields:[{key:"api_token",label:"API token",secret:!0}]},{id:"geotab",name:"Geotab",help:"MyGeotab â Administration â Users. Use the service user credentials plus database name.",fields:[{key:"database",label:"Database name",secret:!1},{key:"username",label:"Username",secret:!1},{key:"password",label:"Password",secret:!0}]},{id:"motive",name:"Motive (KeepTruckin)",help:"Motive â Admin â API keys. Create a read-only key.",fields:[{key:"api_key",label:"API key",secret:!0}]},{id:"generic",name:"Other provider",help:"Any provider with an HTTP API. We store the base URL and key securely.",fields:[{key:"base_url",label:"API base URL",secret:!1},{key:"api_key",label:"API key",secret:!0}]}],Q=C({method:"POST"}).middleware([w]).handler(S("d3b54f763c34db3333304ef0b5c8996877a6a9078896aa0424bf29512b00bb8b")),V=C({method:"POST"}).middleware([w]).handler(S("a656520df5349494c2b6dd3c37347738dade8965f5ebaaf4c3c1447aa03723ba")),Y=C({method:"POST"}).middleware([w]).handler(S("f4ae68e4fb477cba645797116bda0bb8354f0dfbf17689835a917a4a426241a6")),R=["Choose provider","Sign in to Geotab","Test connection","Discover vehicles","First sync"];function z(){const i=I(),m=v(L),[n,p]=d.useState(0),[o,u]=d.useState(!1),[t,l]=d.useState({server:"my.geotab.com",database:"relyup_demo",username:"[email protected]",password:"demo-password"}),[h,g]=d.useState(""),[y,b]=d.useState([]),[r,j]=d.useState(null);async function c(a,N,F){u(!0);try{F(await a()),p(N)}catch(D){f.error(D.message)}finally{u(!1)}}const x="w-full rounded-xl border border-border bg-background px-3 py-2 text-sm",s="w-full rounded-xl bg-brand px-3 py-2.5 text-sm font-semibold text-brand-foreground disabled:opacity-60 inline-flex items-center justify-center gap-2";return e.jsxs(E,{className:"space-y-3 border-brand/40",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Connect Geotab â guided demo"}),e.jsx("span",{className:"rounded-full bg-alert px-2 py-0.5 text-[10px] font-bold text-alert-foreground",children:"SIMULATED"})]}),e.jsx("ol",{className:"flex gap-1",children:R.map((a,N)=>e.jsx("li",{className:`h-1.5 flex-1 rounded-full ${N<=n?"bg-brand":"bg-muted"}`,title:a},a))}),e.jsxs("p",{className:"text-xs font-semibold text-muted-foreground",children:["Step ",Math.min(n+1,5)," of 5 · ",R[Math.min(n,4)]]}),n===0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"The customer picks the telematics provider they already use. One connection brings in every vehicle on that account â no per-truck setup."}),e.jsx("button",{className:s,onClick:()=>p(1),children:"Use Geotab (MyGeotab)"})]}),n===1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"In MyGeotab, create a read-only service user, then enter it here. Credentials are encrypted and only used to read data."}),e.jsx("input",{className:x,value:t.server,onChange:a=>l({...t,server:a.target.value}),placeholder:"Server"}),e.jsx("input",{className:x,value:t.database,onChange:a=>l({...t,database:a.target.value}),placeholder:"Database"}),e.jsx("input",{className:x,value:t.username,onChange:a=>l({...t,username:a.target.value}),placeholder:"Service user"}),e.jsx("input",{className:x,type:"password",value:t.password,onChange:a=>l({...t,password:a.target.value}),placeholder:"Password"}),e.jsx("button",{className:s,onClick:()=>p(2),children:"Continue"})]}),n===2&&e.jsxs("button",{className:s,disabled:o,onClick:()=>c(()=>m({data:{step:"test",...t}}),3,a=>g(a.account??"")),children:[o&&e.jsx(k,{className:"h-4 w-4 animate-spin"})," Test connection"]}),n===3&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx(T,{className:"h-4 w-4 text-l0"})," Connected to ",h]}),e.jsxs("button",{className:s,disabled:o,onClick:()=>c(()=>m({data:{step:"discover"}}),4,a=>b(("vehicles"in a?a.vehicles:void 0)??[])),children:[o&&e.jsx(k,{className:"h-4 w-4 animate-spin"})," Discover vehicles"]})]}),n===4&&!r&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:["Found ",e.jsx("b",{children:y.filter(a=>a.found).length})," of ",y.length," fleet vehicles in this Geotab account, matched by VIN."]}),e.jsx("div",{className:"max-h-48 overflow-auto rounded-xl border border-border text-xs",children:y.map(a=>e.jsxs("div",{className:"flex justify-between border-b border-border px-3 py-1.5 last:border-b-0",children:[e.jsx("span",{className:"font-mono",children:a.plate}),e.jsx("span",{className:a.found?"text-l0":"text-l4",children:a.found?`Matched · device ${a.unitId}`:"Not in this account"})]},a.plate))}),e.jsxs("button",{className:s,disabled:o,onClick:()=>c(()=>m({data:{step:"sync"}}),4,a=>{"linked"in a&&j(a),i.invalidateQueries()}),children:[o&&e.jsx(k,{className:"h-4 w-4 animate-spin"})," Run first sync"]})]}),r&&e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("p",{className:"flex items-center gap-2 font-semibold",children:[e.jsx(T,{className:"h-4 w-4 text-l0"})," Sync complete"]}),e.jsxs("p",{children:[r.live," vehicles sending live data"]}),e.jsxs("p",{children:[r.stale,' linked but silent (tagged "No data received")']}),e.jsxs("p",{children:[r.missing,' not in this account (tagged "Not in your telemetry account")']}),e.jsx("p",{className:"pt-1 text-xs text-muted-foreground",children:"Open Vehicles to see the tags. Reset the demo from the admin sandbox to run this again."})]})]})}function te(){const{activeOrg:i}=G(),m=I(),n=v(Q),p=v(V),o=v(Y),[u,t]=d.useState("samsara"),[l,h]=d.useState({}),g=v(U),y=M({queryKey:["m-ctx",i?.id],queryFn:()=>g(),enabled:!!i?.id}),b=A.find(s=>
1s.id===u),{data:r,isLoading:j}=M({queryKey:["m-telemetry",i?.id],queryFn:()=>n(),enabled:!!i?.id}),c=P({mutationFn:async()=>p({data:{provider:u,credentials:l,label:b.name}}),onSuccess:async()=>{f.success(`${b.name} connected`),h({}),await m.invalidateQueries({queryKey:["m-telemetry"]})},onError:s=>f.error(s.message)}),x=P({mutationFn:async s=>o({data:{id:s}}),onSuccess:async()=>{f.success("Connection removed"),await m.invalidateQueries({queryKey:["m-telemetry"]})},onError:s=>f.error(s.message)});return e.jsxs(O,{title:"Telemetry access",subtitle:"Your keys are encrypted and only used to read fleet data",children:[y.data?.isDemo&&e.jsx(z,{}),j?e.jsx(_,{}):!r||r.length===0?e.jsx(q,{title:"No provider connected",hint:"Add one below to start syncing."}):e.jsx("div",{className:"overflow-hidden rounded-2xl border border-border bg-card",children:r.map(s=>e.jsxs("div",{className:"flex items-center gap-3 border-b border-border px-4 py-3 last:border-b-0",children:[e.jsx($,{className:"h-4 w-4 text-l0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-semibold",children:s.label}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.status,s.last_checked_at?` · checked ${new Date(s.last_checked_at).toLocaleDateString()}`:""]})]}),e.jsx("button",{onClick:()=>{confirm(`Remove ${s.label}?`)&&x.mutate(s.id)},className:"rounded-xl p-2 text-muted-foreground active:bg-muted","aria-label":`Remove ${s.label}`,children:e.jsx(K,{className:"h-4 w-4"})})]},s.id))}),e.jsxs(E,{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Add a provider"}),e.jsx("select",{value:u,onChange:s=>{t(s.target.value),h({})},className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-sm",children:A.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b.help}),b.fields.map(s=>e.jsx("input",{type:s.secret?"password":"text",value:l[s.key]??"",onChange:a=>h({...l,[s.key]:a.target.value}),placeholder:s.label,autoComplete:"off",className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-sm"},s.key)),e.jsx("button",{onClick:()=>c.mutate(),disabled:c.isPending,className:"w-full rounded-xl bg-brand px-3 py-2.5 text-sm font-semibold text-brand-foreground disabled:opacity-60",children:c.isPending?"Savingâ¦":"Connect"})]})]})}export{te as component};
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.