import{e as V,t as Xe,u as Ye,c as et,v as tt,a as Ke,i as Pe,r as n,d as k,aj as A,j as e,ac as st,F as at,a1 as lt}from"./index-D4ZMoJFe.js";import{Q as nt}from"./index-iEHcFRfU.js";import{b as F}from"./formatters-jmx2pV9o.js";import{g as rt,a as it,f as ot,b as Re}from"./trackingUtils-D2VhIKbr.js";import{R as Te}from"./refresh-cw-Dz03z_Yo.js";import{M as ct}from"./monitor-smartphone-CZzPmFw8.js";import{K as dt}from"./key-round-BhKTq8yO.js";import{T as mt}from"./trash-2-CGotPSCR.js";import{M as te,T as se}from"./TileLayer-BRQ5IQYZ.js";import{C as I,T as z,P as Le}from"./Tooltip-UyA4P4hO.js";import{P as pt}from"./play-DIZ8lNZS.js";import{S as xt,P as ut}from"./skip-back-ssG3Tjgw.js";import{R as Fe,T as Oe,B as ht,C as ft}from"./generateCategoricalChart-3rcGS8p6.js";import{B as gt}from"./BarChart-78W7x31T.js";import{X as bt,Y as jt}from"./YAxis-DOtzoTA4.js";import{P as vt,a as kt}from"./PieChart-C9p1G6Gr.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _t=V("Camera",[["path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z",key:"1tc9qg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Nt=V("LocateFixed",[["line",{x1:"2",x2:"5",y1:"12",y2:"12",key:"bvdh0s"}],["line",{x1:"19",x2:"22",y1:"12",y2:"12",key:"1tbv5k"}],["line",{x1:"12",x2:"12",y1:"2",y2:"5",key:"11lu5j"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}],["circle",{cx:"12",cy:"12",r:"7",key:"fim9np"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const yt=V("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const wt=V("SkipForward",[["polygon",{points:"5 4 15 12 5 20 5 4",key:"16p6eg"}],["line",{x1:"19",x2:"19",y1:"5",y2:"19",key:"futhcm"}]]),ae="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",$e=Array.from({length:24},(r,x)=>x);function St({deviceId:r,deviceName:x,onClose:h,onSaved:N}){const{selectedCompanyId:y,selectedCompany:O}=Ke(),{pushToast:R}=Pe(),[f,a]=n.useState(()=>Re()),[$,m]=n.useState(!1),q=y||(O==null?void 0:O.id)||"",T=async K=>{var c,E;K.preventDefault(),m(!0);try{const C=await k.post(`/tracking/devices/${r}/reset-password`,{company_id:q,password:f});R({title:"Mot de passe réinitialisé",description:`Le nouveau mot de passe a été généré pour ${x}.`,tone:"success"}),N(C.data)}catch(C){R({title:"Réinitialisation impossible",description:((E=(c=C==null?void 0:C.response)==null?void 0:c.data)==null?void 0:E.message)||"Le mot de passe n'a pas pu être réinitialisé.",tone:"danger"})}finally{m(!1)}};return e.jsx("div",{className:"fixed inset-0 z-[120] flex items-center justify-center bg-slate-950/35 p-4",children:e.jsxs("div",{className:"w-full max-w-lg rounded-3xl border border-slate-200 bg-white shadow-2xl",children:[e.jsxs("div",{className:"border-b border-slate-200 px-6 py-5",children:[e.jsx("p",{className:"tracking-panel-title",children:"Réinitialiser le mot de passe"}),e.jsx("h3",{className:"mt-2 text-xl font-semibold text-slate-950",children:x})]}),e.jsxs("form",{onSubmit:T,className:"space-y-5 px-6 py-6",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{value:f,onChange:K=>a(K.target.value)}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>a(Re()),children:"Générer"})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:h,children:"Annuler"}),e.jsx("button",{type:"submit",className:"btn-primary",disabled:$,children:$?"Enregistrement...":"Enregistrer"})]})]})]})})}function Ct({payload:r}){if(!r)return null;const x=JSON.stringify(r.qr_code_data);return e.jsxs("div",{className:"card-panel border-emerald-200 bg-emerald-50/70 p-6",children:[e.jsx("p",{className:"tracking-panel-title",children:"Nouveau mot de passe"}),e.jsxs("div",{className:"mt-4 grid gap-5 lg:grid-cols-[1fr_180px]",children:[e.jsxs("div",{className:"space-y-2 text-sm text-slate-700",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-slate-900",children:"Serveur:"})," ",r.qr_code_data.server]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-slate-900",children:"Nom d'utilisateur:"})," ",r.qr_code_data.username]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-slate-900",children:"Mot de passe:"})," ",r.generated_password]})]}),e.jsx("div",{className:"rounded-2xl border border-emerald-200 bg-white p-3",children:e.jsx(nt,{value:x,size:148,className:"h-auto w-full"})})]})]})}function Rt({item:r,onClose:x}){if(!r)return null;const h=r.result||{},N=h.screenshot_url||h.file_url||null;let y=null;if(typeof h.response=="string")try{y=JSON.parse(h.response)}catch{y=null}return e.jsx("div",{className:"fixed inset-0 z-[130] flex items-center justify-center bg-slate-950/45 p-4",children:e.jsxs("div",{className:"max-h-[92vh] w-full max-w-5xl overflow-hidden rounded-3xl border border-slate-200 bg-white shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-slate-200 px-6 py-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"tracking-panel-title",children:"Résultat FreeKiosk"}),e.jsx("h3",{className:"mt-2 text-xl font-semibold text-slate-950",children:r.action||r.command_type||"Commande"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:["Statut: ",r.status||h.command_status||h.status||"en attente"]})]}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:x,children:"Fermer"})]}),e.jsxs("div",{className:"max-h-[72vh] overflow-auto px-6 py-6",children:[N?e.jsxs("div",{className:"mb-5 rounded-2xl border border-slate-200 bg-slate-50 p-3",children:[e.jsx("img",{src:N,alt:"Résultat FreeKiosk",className:"mx-auto max-h-[520px] rounded-xl object-contain"}),e.jsx("a",{className:"mt-3 inline-flex text-sm font-semibold text-emerald-700",href:N,target:"_blank",rel:"noreferrer",children:"Ouvrir l'image"})]}):null,h.message?e.jsx("div",{className:"mb-4 rounded-2xl border border-slate-200 bg-slate-50 p-4 text-sm text-slate-700",children:h.message}):null,y?e.jsx("pre",{className:"rounded-2xl bg-slate-950 p-4 text-xs text-slate-100",children:JSON.stringify(y,null,2)}):e.jsx("pre",{className:"rounded-2xl bg-slate-950 p-4 text-xs text-slate-100",children:JSON.stringify(h,null,2)})]})]})})}function Ht(){var we,Se,Ce;const{id:r}=Xe(),x=Ye(),h=et(),[N,y]=tt(),{selectedCompanyId:O,selectedCompany:R}=Ke(),{pushToast:f}=Pe(),[a,$]=n.useState(null),[m,q]=n.useState([]),[T,K]=n.useState([]),[c,E]=n.useState(null),[C,le]=n.useState(!0),[De,ne]=n.useState(!1),[Me,re]=n.useState(!1),[Ae,ie]=n.useState(!1),[_,oe]=n.useState(new Date().toISOString().slice(0,10)),[B,P]=n.useState(0),[ce,D]=n.useState(!1),[H,Ie]=n.useState(1),[J,ze]=n.useState(null),[M,Ee]=n.useState("7d"),[U,de]=n.useState({from:new Date(Date.now()-7*24*60*60*1e3).toISOString().slice(0,10),to:new Date().toISOString().slice(0,10)}),[Be,Ue]=n.useState(((we=h.state)==null?void 0:we.resetPayload)||null),[Ve,W]=n.useState(!1),[p,Z]=n.useState(""),[b,G]=n.useState(""),[L,Q]=n.useState(null),[me,pe]=n.useState(!1),o=O||(R==null?void 0:R.id)||"",j=N.get("tab")||"info";n.useEffect(()=>{if(!o)return;let t=!1;return le(!0),k.get(`/tracking/devices/${r}`,{params:{company_id:o}}).then(s=>{t||$(s.data.item)}).catch(s=>{var l,i;t||(f({title:"Chargement impossible",description:((i=(l=s==null?void 0:s.response)==null?void 0:l.data)==null?void 0:i.message)||"Le téléphone n'a pas pu être chargé.",tone:"danger"}),x("/tracking/devices"))}).finally(()=>{t||le(!1)}),()=>{t=!0}},[o,r,x,f]),n.useEffect(()=>{if(!o||!r)return;A.connect(),A.emit("company:subscribe",Number(o));const t=s=>{Number(s.device_id)===Number(r)&&((s.command_type==="freekiosk_rest_request"||s.command_type==="capture_freekiosk_screenshot")&&G(""),Z(l=>l===s.command_type?"":l),Q({action:s.command_type,command_id:s.command_id,command_type:s.command_type,status:s.status,result:s.result||{},acked_at:s.acked_at}))};return A.on("device:command_ack",t),()=>{A.off("device:command_ack",t),A.emit("company:unsubscribe",Number(o))}},[o,r]),n.useEffect(()=>{if(j!=="history"||!o)return;let t=!1;return ne(!0),k.get(`/tracking/devices/${r}/locations`,{params:{company_id:o,date:_,limit:500}}).then(s=>{if(!t){const l=(s.data.items||[]).slice().sort((i,d)=>new Date(i.device_timestamp).getTime()-new Date(d.device_timestamp).getTime());q(l),P(l.length?l.length-1:0)}}).finally(()=>{t||ne(!1)}),()=>{t=!0}},[o,j,r,_]),n.useEffect(()=>{if(j!=="trips"||!o)return;let t=!1;return re(!0),k.get(`/tracking/devices/${r}/trips`,{params:{company_id:o,from:`${_}T00:00:00.000Z`,to:`${_}T23:59:59.999Z`}}).then(s=>{t||K(s.data.items||[])}).finally(()=>{t||re(!1)}),()=>{t=!0}},[o,j,r,_]),n.useEffect(()=>{if(j!=="stats"||!o)return;const t=new Date().toISOString().slice(0,10),s={today:{from:t,to:t},"7d":{from:new Date(Date.now()-6*24*60*60*1e3).toISOString().slice(0,10),to:t},"30d":{from:new Date(Date.now()-29*24*60*60*1e3).toISOString().slice(0,10),to:t},custom:U};let l=!1;return ie(!0),k.get(`/tracking/devices/${r}/stats`,{params:{company_id:o,from:`${s[M].from}T00:00:00.000Z`,to:`${s[M].to}T23:59:59.999Z`}}).then(i=>{l||E(i.data.item)}).finally(()=>{l||ie(!1)}),()=>{l=!0}},[o,j,U,r,M]),n.useEffect(()=>{if(!ce||m.length<2)return;const t=window.setInterval(()=>{P(s=>s>=m.length-1?(D(!1),s):s+1)},1e3/H);return()=>{window.clearInterval(t)}},[m.length,H,ce]);const g=n.useMemo(()=>T.find(t=>t.id===J)||null,[J,T]),w=n.useMemo(()=>m.length?m.slice(0,Math.max(1,B+1)):[],[m,B]),v=w[w.length-1]||null,xe=async t=>{const s=await k.get(`/tracking/devices/${r}/export/${t}`,{params:{company_id:o,date:_},responseType:"blob"}),l=new Blob([s.data],{type:s.headers["content-type"]||(t==="csv"?"text/csv":"application/vnd.google-earth.kml+xml")}),i=window.URL.createObjectURL(l),d=document.createElement("a"),ee=(s.headers["content-disposition"]||"").match(/filename="?([^"]+)"?/i);d.href=i,d.download=(ee==null?void 0:ee[1])||`tracking-${r}-${_}.${t}`,d.click(),window.URL.revokeObjectURL(i)},qe=n.useMemo(()=>c!=null&&c.active_hours_by_day?c.active_hours_by_day.map(t=>{const s=new Set(t.hours||[]);return{...t,cells:$e.map(l=>s.has(l))}}):[],[c]),He=t=>{const s=new URLSearchParams(N);s.set("tab",t),y(s)},Je=async()=>{var t,s;if(window.confirm(`Désactiver ${a.device_name} ?`))try{await k.delete(`/tracking/devices/${a.id}`,{data:{company_id:o}}),f({title:"Téléphone désactivé",description:`${a.device_name} a été désactivé.`,tone:"success"}),x("/tracking/devices")}catch(l){f({title:"Désactivation impossible",description:((s=(t=l==null?void 0:l.response)==null?void 0:t.data)==null?void 0:s.message)||"Le téléphone n'a pas pu être désactivé.",tone:"danger"})}},S=async t=>{var l,i;Z(t);const s={ring_device:"sonnerie",force_sync:"synchronisation",request_location:"position immédiate",lock_device:"verrouillage",open_location_settings:"réglages localisation",restart_tracking:"relance tracking",reboot_device:"redémarrage",capture_screenshot:"capture écran"};try{await k.post(`/tracking/devices/${a.id}/commands`,{company_id:o,command_type:t}),f({title:"Commande envoyée",description:`La commande ${s[t]||t} a été envoyée au téléphone.`,tone:"success"})}catch(d){f({title:"Commande impossible",description:((i=(l=d==null?void 0:d.response)==null?void 0:l.data)==null?void 0:i.message)||"La commande distante n'a pas pu être envoyée.",tone:"danger"})}finally{Z("")}},We=async()=>{var t,s,l;pe(!0);try{const d=(t=(await k.post(`/tracking/devices/${a.id}/screen-share/request`,{company_id:o})).data.item)==null?void 0:t.id;f({title:"Partage d'écran demandé",description:"Le téléphone doit ouvrir l'application et accepter la capture d'écran Android.",tone:"success"}),d&&x(`/tracking/screen-share/${d}`)}catch(i){f({title:"Demande impossible",description:((l=(s=i==null?void 0:i.response)==null?void 0:s.data)==null?void 0:l.message)||"La demande de partage d'écran n'a pas pu être envoyée.",tone:"danger"})}finally{pe(!1)}},u=async(t,s={})=>{var l,i;G(t);try{const d=await k.post(`/tracking/devices/${a.id}/freekiosk/${t}`,{company_id:o,...s});Q(d.data.item),f({title:"Commande FreeKiosk exécutée",description:`Action ${t} terminée.`,tone:"success"})}catch(d){f({title:"FreeKiosk impossible",description:((i=(l=d==null?void 0:d.response)==null?void 0:l.data)==null?void 0:i.message)||"La commande FreeKiosk n'a pas pu être exécutée.",tone:"danger"})}finally{G("")}},Ze=()=>{if(a!=null&&a.freekiosk_enabled){u("screenshot");return}S("capture_screenshot")},ue=()=>{const t=window.prompt("URL à afficher dans FreeKiosk");t&&u("url",{url:t})},he=()=>{const t=window.prompt("Texte à afficher en toast");t&&u("toast",{text:t})},fe=()=>{const t=window.prompt("Luminosité 0-100","75");t!==null&&u("brightness_set",{value:Number(t)})},ge=()=>{const t=window.prompt("Volume 0-100","50");t!==null&&u("volume_set",{value:Number(t)})},be=()=>{const t=window.prompt("Texte à lire");t&&u("tts",{text:t})},je=()=>{const t=window.prompt("Package application","com.android.chrome");t&&u("app_launch",{package:t})},ve=()=>{const t=window.prompt("JavaScript à exécuter","document.title");t&&u("js",{code:t})},ke=()=>{const t=window.prompt("URL audio");t&&u("audio_play",{url:t,loop:!1,volume:50})},_e=()=>{const t=window.prompt("Touche clavier","enter");t&&u("keyboard_key",{key:t})},Ne=()=>{const t=window.prompt("Raccourci clavier","ctrl+r");t&&u("keyboard_combo",{map:t})},ye=()=>{const t=window.prompt("Texte à saisir");t&&u("remote_text",{text:t})};if(C||!a)return e.jsx("section",{className:"card-panel p-8",children:"Chargement..."});const X=rt(a),Y=it(a.last_battery),Ge=[["status","Status"],["info","Info"],["battery","Battery"],["screen_status","Screen status"],["wifi","WiFi"],["storage","Storage"],["memory","Memory"],["health","Health"],["screen_on","Écran ON"],["screen_off","Écran OFF"],["screensaver_on","Screensaver ON"],["screensaver_off","Screensaver OFF"],["wake","Wake"],["lock","Lock"],["reload","Reload"],["restart_ui","Restart UI"],["reboot","Reboot"],["audio_beep","Beep"],["audio_stop","Stop audio"],["clear_cache","Clear cache"],["screenshot","Screenshot"],["camera_back","Photo arrière"],["camera_front","Photo avant"],["camera_list","Caméras"],["volume_status","Volume"],["remote_up","↑"],["remote_down","↓"],["remote_left","←"],["remote_right","→"],["remote_select","OK"],["remote_back","Back"],["remote_home","Home"],["remote_menu","Menu"],["remote_playpause","Play/Pause"]],Qe=[["Ouvrir URL",ue],["Luminosité",fe],["Toast",he],["Volume",ge],["TTS",be],["App launch",je],["JavaScript",ve],["Audio URL",ke],["Key",_e],["Combo",Ne],["Saisir texte",ye]];return e.jsxs("section",{className:"space-y-6",children:[e.jsx("header",{className:"card-panel p-6",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"tracking-panel-title",children:"Tracking · Téléphone"}),e.jsx("h1",{className:"mt-2 text-3xl font-semibold text-slate-950",children:a.device_name}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3 text-sm text-slate-600",children:[e.jsxs("span",{className:`rounded-full px-2 py-1 text-xs font-semibold ${X.badgeClass}`,children:[X.dot," ",X.label]}),e.jsx("span",{children:a.owner_name}),e.jsx("span",{children:a.owner_phone||"—"}),e.jsx("span",{children:a.owner_department||"—"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("ring_device"),disabled:p==="ring_device",children:[e.jsx(st,{size:16}),p==="ring_device"?"Envoi...":"Faire sonner"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("force_sync"),disabled:p==="force_sync",children:[e.jsx(Te,{size:16}),p==="force_sync"?"Envoi...":"Forcer sync"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("request_location"),disabled:p==="request_location",children:[e.jsx(Nt,{size:16}),p==="request_location"?"Envoi...":"Position immédiate"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("lock_device"),disabled:p==="lock_device",children:[e.jsx(at,{size:16}),p==="lock_device"?"Envoi...":"Verrouiller"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("open_location_settings"),disabled:p==="open_location_settings",children:[e.jsx(lt,{size:16}),p==="open_location_settings"?"Envoi...":"Réglages GPS"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("restart_tracking"),disabled:p==="restart_tracking",children:[e.jsx(Te,{size:16}),p==="restart_tracking"?"Envoi...":"Relancer tracking"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>S("reboot_device"),disabled:p==="reboot_device",children:[e.jsx(yt,{size:16}),p==="reboot_device"?"Envoi...":"Redémarrer"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:Ze,disabled:p==="capture_screenshot"||b==="screenshot",children:[e.jsx(_t,{size:16}),p==="capture_screenshot"||b==="screenshot"?"Envoi...":"Capture écran"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:We,disabled:me,children:[e.jsx(ct,{size:16}),me?"Envoi...":"Demander partage écran"]}),e.jsx("button",{type:"button",className:"tracking-control",onClick:()=>x(`/tracking/devices/${a.id}/edit`),children:"Modifier"}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>W(!0),children:[e.jsx(dt,{size:16}),"Réinitialiser MDP"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:Je,children:[e.jsx(mt,{size:16}),"Désactiver"]})]})]})}),e.jsx(Ct,{payload:Be}),e.jsxs("section",{className:"card-panel p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"tracking-panel-title",children:"FreeKiosk · REST local"}),e.jsx("h2",{className:"mt-1 text-xl font-semibold text-slate-950",children:"Contrôle FreeKiosk"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:["TrackingApp exécute les URLs FreeKiosk directement sur le téléphone: ",a.freekiosk_base_url||"http://<ip-telephone>:8080"]})]}),e.jsx("span",{className:`rounded-full px-3 py-1 text-xs font-semibold ${a.freekiosk_enabled?"bg-emerald-100 text-emerald-700":"bg-slate-200 text-slate-600"}`,children:a.freekiosk_enabled?"Activé":"Non activé"})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[Ge.map(([t,s])=>e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||b===t,onClick:()=>u(t),children:b===t?"...":s},t)),Qe.map(([t,s])=>e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||!!b,onClick:s,children:t},t))]})]}),e.jsx("div",{className:"card-panel p-2",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:[["info","Informations"],["history","Historique"],["trips","Trajets"],["stats","Statistiques"]].map(([t,s])=>e.jsx("button",{type:"button",className:`rounded-xl px-4 py-2 text-sm font-medium ${j===t?"bg-emerald-600 text-white":"text-slate-600 hover:bg-slate-100"}`,onClick:()=>He(t),children:s},t))})}),j==="info"?e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[1.2fr_0.8fr]",children:[e.jsxs("section",{className:"card-panel p-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Informations"}),e.jsx("div",{className:"mt-5 grid gap-4 sm:grid-cols-2",children:[["Nom du téléphone",a.device_name],["Nom du propriétaire",a.owner_name],["N° téléphone",a.owner_phone||"—"],["Département",a.owner_department||"—"],["Nom d'utilisateur",a.login_username],["OS / Modèle",`${a.device_os||"—"} ${a.device_model?`· ${a.device_model}`:""}`],["Dernière vue",ot(a.last_seen)],["Adresse",a.last_address||"Adresse inconnue"]].map(([t,s])=>e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50 p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.16em] text-slate-500",children:t}),e.jsx("p",{className:"mt-2 text-sm font-medium text-slate-900",children:s})]},t))}),e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Batterie"}),e.jsx("span",{className:"font-mono text-slate-900",children:Y.label})]}),e.jsx("div",{className:"h-3 rounded-full bg-slate-200",children:e.jsx("div",{className:`h-3 rounded-full ${Y.barClass}`,style:{width:Y.width}})})]}),e.jsxs("div",{className:"mt-6 rounded-3xl border border-slate-200 bg-slate-50 p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-950",children:"FreeKiosk"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Commandes FreeKiosk via REST local exécutées par TrackingApp sur le téléphone. La localisation n'est pas utilisée ici."}),e.jsxs("p",{className:"mt-1 text-xs text-slate-500",children:["URL locale: ",a.freekiosk_base_url||"http://<ip-telephone>:8080"]})]}),e.jsx("span",{className:`rounded-full px-3 py-1 text-xs font-semibold ${a.freekiosk_enabled?"bg-emerald-100 text-emerald-700":"bg-slate-200 text-slate-600"}`,children:a.freekiosk_enabled?"Activé":"Non activé"})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[[["status","Status"],["info","Info"],["battery","Battery"],["screen_status","Screen status"],["wifi","WiFi"],["storage","Storage"],["memory","Memory"],["health","Health"],["screen_on","Écran ON"],["screen_off","Écran OFF"],["screensaver_on","Screensaver ON"],["screensaver_off","Screensaver OFF"],["wake","Wake"],["lock","Lock"],["reload","Reload"],["restart_ui","Restart UI"],["reboot","Reboot"],["audio_beep","Beep"],["audio_stop","Stop audio"],["clear_cache","Clear cache"],["screenshot","Screenshot"],["camera_back","Photo arrière"],["camera_front","Photo avant"],["camera_list","Caméras"],["volume_status","Volume"],["remote_up","↑"],["remote_down","↓"],["remote_left","←"],["remote_right","→"],["remote_select","OK"],["remote_back","Back"],["remote_home","Home"],["remote_menu","Menu"],["remote_playpause","Play/Pause"]].map(([t,s])=>e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||b===t,onClick:()=>u(t),children:b===t?"...":s},t)),e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||!!b,onClick:ue,children:"Ouvrir URL"}),e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||!!b,onClick:fe,children:"Luminosité"}),e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||!!b,onClick:he,children:"Toast"}),[["Volume",ge],["TTS",be],["App launch",je],["JavaScript",ve],["Audio URL",ke],["Key",_e],["Combo",Ne],["Saisir texte",ye]].map(([t,s])=>e.jsx("button",{type:"button",className:"tracking-control",disabled:!a.freekiosk_enabled||!!b,onClick:s,children:t},t))]}),L?e.jsxs("div",{className:"mt-4 rounded-2xl border border-slate-200 bg-white p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-sm font-semibold text-slate-900",children:["Résultat FreeKiosk: ",L.action]}),(Se=L.result)!=null&&Se.file_url?e.jsx("a",{className:"text-sm font-semibold text-emerald-700",href:L.result.file_url,target:"_blank",rel:"noreferrer",children:"Ouvrir la capture"}):null]}),e.jsx("pre",{className:"mt-3 max-h-56 overflow-auto rounded-xl bg-slate-950 p-3 text-xs text-slate-100",children:JSON.stringify(L.result,null,2)})]}):null]})]}),e.jsxs("section",{className:"space-y-6",children:[e.jsx("article",{className:"card-panel overflow-hidden p-4",children:e.jsx("div",{className:"h-[300px] overflow-hidden rounded-2xl",children:e.jsxs(te,{center:a.last_lat&&a.last_lng?[a.last_lat,a.last_lng]:[36.7,3],zoom:a.last_lat&&a.last_lng?14:6,className:"h-full w-full",scrollWheelZoom:!1,children:[e.jsx(se,{attribution:"© OpenStreetMap contributors",url:ae}),a.last_lat&&a.last_lng?e.jsx(I,{center:[a.last_lat,a.last_lng],radius:10,pathOptions:{color:"#059669",fillColor:"#10b981",fillOpacity:.9},children:e.jsx(z,{direction:"top",children:a.device_name})}):null]})})}),e.jsxs("article",{className:"card-panel p-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Derniers événements"}),e.jsx("div",{className:"mt-5 space-y-4",children:(Ce=a.events)!=null&&Ce.length?a.events.map(t=>e.jsxs("div",{className:"flex gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-4",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-emerald-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:t.title}),e.jsx("p",{className:"mt-1 text-sm text-slate-600",children:t.message||"—"}),e.jsx("p",{className:"mt-2 text-xs text-slate-500",children:F(t.created_at)})]})]},t.id)):e.jsx("div",{className:"text-sm text-slate-500",children:"Aucun événement disponible."})})]})]})]}):null,j==="history"?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"card-panel p-5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("input",{type:"date",value:_,onChange:t=>oe(t.target.value),className:"max-w-[220px]"}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>D(!0),children:[e.jsx(pt,{size:16}),"Rejouer le trajet"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>{D(!1),P(0)},children:[e.jsx(xt,{size:16}),"Début"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>D(!1),children:[e.jsx(ut,{size:16}),"Pause"]}),e.jsxs("button",{type:"button",className:"tracking-control",onClick:()=>{D(!1),P(Math.max(0,m.length-1))},children:[e.jsx(wt,{size:16}),"Fin"]}),[1,2,5,10].map(t=>e.jsxs("button",{type:"button",className:`tracking-control ${H===t?"border-emerald-300 bg-emerald-50 text-emerald-700":""}`,onClick:()=>Ie(t),children:[t,"x"]},t)),e.jsx("button",{type:"button",className:"tracking-control",onClick:()=>xe("csv"),children:"Télécharger CSV"}),e.jsx("button",{type:"button",className:"tracking-control",onClick:()=>xe("kml"),children:"Exporter KML"})]})}),e.jsxs("div",{className:"card-panel overflow-hidden p-4",children:[e.jsx("div",{className:"h-[420px] overflow-hidden rounded-2xl",children:e.jsxs(te,{center:v?[v.latitude,v.longitude]:[36.7,3],zoom:13,className:"h-full w-full",children:[e.jsx(se,{attribution:"© OpenStreetMap contributors",url:ae}),w.length>1?e.jsx(Le,{positions:w.map(t=>[t.latitude,t.longitude]),pathOptions:{color:"#2563eb",weight:4,opacity:.85}}):null,w.map((t,s)=>{const l=w.length>1?s/(w.length-1):1,i=l<.33?"#2563eb":l<.66?"#10b981":"#f97316";return e.jsx(I,{center:[t.latitude,t.longitude],radius:s===w.length-1?6:4,pathOptions:{color:i,fillColor:i,fillOpacity:.9,weight:1},children:e.jsx(z,{direction:"top",children:e.jsxs("div",{className:"text-xs",children:[e.jsx("div",{children:F(t.device_timestamp)}),e.jsxs("div",{children:["Vitesse: ",t.speed??"—"," km/h"]})]})})},t.id)}),v?e.jsx(I,{center:[v.latitude,v.longitude],radius:9,pathOptions:{color:"#0f172a",fillColor:"#10b981",fillOpacity:1,weight:2},children:e.jsx(z,{direction:"top",children:e.jsxs("div",{className:"text-xs",children:[e.jsx("div",{children:F(v.device_timestamp)}),e.jsxs("div",{children:["Vitesse: ",v.speed??"—"," km/h"]})]})})}):null]})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("input",{type:"range",min:"0",max:Math.max(0,m.length-1),value:Math.min(B,Math.max(0,m.length-1)),onChange:t=>P(Number(t.target.value))}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-slate-500",children:[e.jsxs("span",{children:["Point ",m.length?B+1:0," / ",m.length]}),e.jsx("span",{children:v?F(v.device_timestamp):"—"})]})]})]}),e.jsx("div",{className:"table-shell overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsx("tr",{children:["Heure","Latitude","Longitude","Vitesse","Adresse","Batterie","Précision"].map(t=>e.jsx("th",{className:"table-cell text-left font-semibold",children:t},t))})}),e.jsx("tbody",{children:De?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-10 text-center text-slate-500",children:"Chargement..."})}):m.length?m.map(t=>e.jsxs("tr",{className:"table-row",children:[e.jsx("td",{className:"table-cell",children:F(t.device_timestamp)}),e.jsx("td",{className:"table-cell font-mono",children:t.latitude}),e.jsx("td",{className:"table-cell font-mono",children:t.longitude}),e.jsx("td",{className:"table-cell",children:t.speed??"—"}),e.jsx("td",{className:"table-cell",children:t.address||"—"}),e.jsxs("td",{className:"table-cell",children:[t.battery_level??"—","%"]}),e.jsxs("td",{className:"table-cell",children:[t.accuracy??"—"," m"]})]},t.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-10 text-center text-slate-500",children:"Aucune position pour cette journée."})})})]})})})]}):null,j==="trips"?e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[0.95fr_1.05fr]",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"card-panel p-5",children:e.jsx("input",{type:"date",value:_,onChange:t=>oe(t.target.value),className:"max-w-[220px]"})}),e.jsx("div",{className:"table-shell overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsx("tr",{children:["Date","Départ","Arrivée","Durée","Distance","Vitesse moy"].map(t=>e.jsx("th",{className:"table-cell text-left font-semibold",children:t},t))})}),e.jsx("tbody",{children:Me?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-10 text-center text-slate-500",children:"Chargement..."})}):T.length?T.map(t=>e.jsxs("tr",{className:`table-row cursor-pointer ${J===t.id?"bg-emerald-50":""}`,onClick:()=>ze(t.id),children:[e.jsx("td",{className:"table-cell",children:F(t.start_time)}),e.jsx("td",{className:"table-cell",children:t.start_address||"—"}),e.jsx("td",{className:"table-cell",children:t.end_address||"—"}),e.jsxs("td",{className:"table-cell",children:[t.duration_minutes," min"]}),e.jsxs("td",{className:"table-cell",children:[t.distance_km," km"]}),e.jsxs("td",{className:"table-cell",children:[t.avg_speed," km/h"]})]},t.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-10 text-center text-slate-500",children:"Aucun trajet détecté."})})})]})})})]}),e.jsx("div",{className:"card-panel overflow-hidden p-4",children:e.jsx("div",{className:"h-[420px] overflow-hidden rounded-2xl",children:e.jsxs(te,{center:g?[g.start_latitude,g.start_longitude]:[36.7,3],zoom:g?13:6,className:"h-full w-full",children:[e.jsx(se,{attribution:"© OpenStreetMap contributors",url:ae}),g?e.jsxs(e.Fragment,{children:[e.jsx(Le,{positions:[[g.start_latitude,g.start_longitude],[g.end_latitude,g.end_longitude]],pathOptions:{color:"#10b981",weight:4}}),e.jsx(I,{center:[g.start_latitude,g.start_longitude],radius:7,pathOptions:{color:"#2563eb",fillColor:"#2563eb",fillOpacity:.9},children:e.jsx(z,{children:"Départ"})}),e.jsx(I,{center:[g.end_latitude,g.end_longitude],radius:7,pathOptions:{color:"#f97316",fillColor:"#f97316",fillOpacity:.9},children:e.jsx(z,{children:"Arrivée"})})]}):null]})})})]}):null,j==="stats"?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"card-panel p-5",children:e.jsxs("div",{className:"flex flex-wrap gap-3",children:[[["today","Aujourd'hui"],["7d","7 jours"],["30d","30 jours"],["custom","Personnalisé"]].map(([t,s])=>e.jsx("button",{type:"button",className:`rounded-xl px-4 py-2 text-sm font-medium ${M===t?"bg-emerald-600 text-white":"bg-slate-100 text-slate-600"}`,onClick:()=>Ee(t),children:s},t)),M==="custom"?e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx("input",{type:"date",value:U.from,onChange:t=>de(s=>({...s,from:t.target.value})),className:"max-w-[180px]"}),e.jsx("input",{type:"date",value:U.to,onChange:t=>de(s=>({...s,to:t.target.value})),className:"max-w-[180px]"})]}):null]})}),Ae||!c?e.jsx("div",{className:"card-panel p-8 text-slate-500",children:"Chargement..."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid gap-4 lg:grid-cols-3 xl:grid-cols-6",children:[["Distance totale",`${c.km_traveled} km`],["Temps en mouvement",`${Math.round(c.time_moving_seconds/60)} min`],["Temps arrêté",`${Math.round(c.time_stopped_seconds/60)} min`],["Vitesse max",`${c.max_speed} km/h`],["Vitesse moyenne",`${c.avg_speed} km/h`],["Pings reçus",c.locations_count]].map(([t,s])=>e.jsxs("div",{className:"card-panel p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.18em] text-slate-500",children:t}),e.jsx("p",{className:"mt-3 text-2xl font-semibold text-slate-950",children:s})]},t))}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs("article",{className:"card-panel p-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Distance par jour"}),e.jsx("div",{className:"mt-5 h-[280px]",children:e.jsx(Fe,{width:"100%",height:"100%",children:e.jsxs(gt,{data:c.distance_by_day||[],children:[e.jsx(bt,{dataKey:"date"}),e.jsx(jt,{}),e.jsx(Oe,{}),e.jsx(ht,{dataKey:"distance_km",fill:"#10b981",radius:[8,8,0,0]})]})})})]}),e.jsxs("article",{className:"card-panel p-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Répartition mouvement / arrêt"}),e.jsxs("div",{className:"mt-5 grid gap-6 lg:grid-cols-[1fr_180px]",children:[e.jsx("div",{className:"h-[260px]",children:e.jsx(Fe,{width:"100%",height:"100%",children:e.jsxs(vt,{children:[e.jsx(kt,{data:c.movement_breakdown,dataKey:"value",nameKey:"label",innerRadius:70,outerRadius:100,children:c.movement_breakdown.map((t,s)=>e.jsx(ft,{fill:s===0?"#10b981":"#cbd5e1"},t.label))}),e.jsx(Oe,{})]})})}),e.jsx("div",{className:"space-y-3",children:c.movement_breakdown.map((t,s)=>e.jsx("div",{className:"rounded-2xl border border-slate-200 bg-slate-50 px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-block h-3 w-3 rounded-full",style:{backgroundColor:s===0?"#10b981":"#cbd5e1"}}),e.jsx("span",{className:"text-sm font-medium text-slate-700",children:t.label})]}),e.jsxs("span",{className:"font-mono text-sm font-semibold text-slate-950",children:[Math.round(t.value/60)," min"]})]})},t.label))})]})]})]}),e.jsxs("article",{className:"card-panel overflow-x-auto p-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Heures actives par jour"}),e.jsx("div",{className:"mt-5 min-w-[720px]",children:e.jsxs("div",{className:"grid grid-cols-[140px_repeat(24,minmax(24px,1fr))] gap-2 text-[11px] text-slate-500",children:[e.jsx("div",{}),$e.map(t=>e.jsx("div",{className:"text-center",children:t.toString().padStart(2,"0")},t)),qe.map(t=>e.jsxs(n.Fragment,{children:[e.jsx("div",{className:"py-2 text-sm font-medium text-slate-900",children:t.date}),t.cells.map((s,l)=>e.jsx("div",{className:`h-8 rounded-lg border ${s?"border-emerald-200 bg-emerald-400/70":"border-slate-200 bg-slate-100"}`},`${t.date}-${l}`))]},t.date))]})})]})]})]}):null,Ve?e.jsx(St,{deviceId:a.id,deviceName:a.device_name,onClose:()=>W(!1),onSaved:t=>{Ue(t),$(s=>s&&{...s,is_online:!1,last_seen:new Date().toISOString()}),W(!1)}}):null,e.jsx(Rt,{item:L,onClose:()=>Q(null)})]})}export{Ht as default};
