PageSourceSearch

https://travelease.ai/static/js/8379.9bce4d08.chunk.js

js travelease.ai collected 2026-10-05 14:55:33 UTC 64,599 bytes, 2 lines download raw bytes

1"use strict";(self.webpackChunkfrontend=self.webpackChunkfrontend||[]).push([[8379],{18379:(e,t,s)=>{s.r(t),s.d(t,{default:()=>ke});var a=s(89379),l=s(65043),r=s(79722),i=s(56328),n=s(6742),d=s(96736),c=s(69772),o=s(49954),m=s(43118),x=s(47810),h=s(8567),p=s(25543),u=s(70492),v=s(69022),j=s(22024),g=s(50516),f=s(76833),b=s(71360),N=s(44285),k=s(41680),y=s(7104),w=s(1457),_=s(49761),A=s(99153),C=s(7365),S=s(88693),E=s(12967),T=s(50797),$=s(85692),I=s(37719),K=s(87978),O=s(70579);const V="".concat("https://travelease.ai","/api"),U="".concat(V,"/admin/compliance/tacho-import"),F={kjoring:"Kj\xf8ring",annet_arbeid:"Annet arbeid",tilgjengelighet:"Tilgjengelighet",pause:"Pause",ukategorisert:"Ukategorisert"};async function L(e,t){const s=await r.A.get(e,{responseType:"blob"}),a=s.headers["content-disposition"]||"",l=/filename\*?=(?:UTF-8'')?"?([^;"]+)"?/i.exec(a),i=l?decodeURIComponent(l[1]):t,n=window.URL.createObjectURL(new Blob([s.data])),d=document.createElement("a");d.href=n,d.download=i,d.click(),window.URL.revokeObjectURL(n)}function z(e){let{data:t,testid:s}=e;const a=Object.entries(t||{}).filter(e=>{let[,t]=e;return(t||0)>0});return 0===a.length?(0,O.jsx)("span",{className:"text-xs text-muted-foreground",children:"\u2014"}):(0,O.jsx)("span",{className:"flex flex-wrap gap-1","data-testid":s,children:a.map(e=>{let[t,s]=e;return(0,O.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded border ".concat("kjoring"===t?"bg-orange-50 border-orange-200 text-orange-700":"ukategorisert"===t?"bg-slate-100 border-slate-300 text-slate-600":"bg-indigo-50 border-indigo-200 text-indigo-700"),children:[F[t]||t,": ",s,"t"]},t)})})}function J(){var e,t,s;const[n,d]=(0,l.useState)(null),[o,m]=(0,l.useState)(!1),[x,v]=(0,l.useState)(!1),[g,b]=(0,l.useState)({}),[N,w]=(0,l.useState)({}),[_,C]=(0,l.useState)([]),[S,V]=(0,l.useState)(!1),[F,J]=(0,l.useState)(null),R=(0,l.useRef)(null),D=(0,l.useCallback)(async()=>{try{const{data:e}=await r.A.get("".concat(U,"/batches"));C(e.batches||[])}catch(e){}},[]);(0,l.useEffect)(()=>{D()},[D]);const q=(null===n||void 0===n?void 0:n.summary)||{};return(0,O.jsxs)("div",{className:"space-y-4 mt-3","data-testid":"tacho-import-panel",children:[(0,O.jsxs)("div",{className:"rounded-md border p-3 bg-indigo-50/40 space-y-2",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold text-indigo-700 uppercase",children:[(0,O.jsx)(A.A,{className:"h-3.5 w-3.5"})," Fartsskriver-import (CSV/JSON)"]}),(0,O.jsx)("p",{className:"text-xs text-muted-foreground",children:"Faktiske kj\xf8redata mates rett inn i regelmotoren. Fartsskriveren er den lovlige kilden og erstatter manuelle stemplinger for de ber\xf8rte dagene (de arkiveres, aldri slettet)."}),(0,O.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>L("".concat(U,"/template?format=csv"),"fartsskriver-mal.csv"),"data-testid":"tacho-template-csv",children:[(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"}),"CSV-mal"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>L("".concat(U,"/template?format=json"),"fartsskriver-mal.json"),"data-testid":"tacho-template-json",children:[(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"}),"JSON-mal"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:async()=>{try{const{data:e}=await r.A.get("".concat(U,"/schema"));J(e),V(!0)}catch(e){i.toast.error("Kunne ikke hente skjema")}},"data-testid":"tacho-schema-btn",children:[(0,O.jsx)(k.A,{className:"w-3.5 h-3.5 mr-1"}),"Vis skjema"]}),(0,O.jsx)("input",{ref:R,type:"file",accept:".csv,.json",onChange:async e=>{var t;const s=null===(t=e.target.files)||void 0===t?void 0:t[0];if(s){m(!0),d(null),b({}),w({});try{const e=new FormData;e.append("file",s);const{data:t}=await r.A.post("".concat(U,"/preview"),e);d(t),t.summary.rows_error>0&&i.toast.warning("".concat(t.summary.rows_error," rad(er) med feil \u2014 se feillisten"))}catch(n){var a,l;i.toast.error((null===n||void 0===n||null===(a=n.response)||void 0===a||null===(l=a.data)||void 0===l?void 0:l.detail)||"Kunne ikke lese filen")}finally{m(!1),R.current&&(R.current.value="")}}}
1,className:"hidden","data-testid":"tacho-file-input"}),(0,O.jsxs)(c.$,{size:"sm",onClick:()=>{var e;return null===(e=R.current)||void 0===e?void 0:e.click()},disabled:o,"data-testid":"tacho-upload-btn",children:[o?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(T.A,{className:"w-3.5 h-3.5 mr-1"}),"Last opp fil"]})]})]}),n&&(0,O.jsxs)("div",{className:"space-y-3","data-testid":"tacho-preview",children:[(0,O.jsxs)("div",{className:"flex flex-wrap gap-2 text-sm items-center",children:[(0,O.jsx)("span",{className:"font-medium",children:n.filename}),(0,O.jsxs)(h.E,{className:"bg-emerald-600 text-white",children:[q.rows_ok," rader OK"]}),q.rows_error>0&&(0,O.jsxs)(h.E,{className:"bg-red-600 text-white",children:[q.rows_error," feil"]}),(0,O.jsxs)(h.E,{variant:"outline",children:[q.drivers_matched," sj\xe5f\xf8r(er) matchet"]}),(0,O.jsxs)(h.E,{variant:"outline",children:[q.days_matched," dag(er)"]}),q.unmatched_cards>0&&(0,O.jsxs)(h.E,{className:"bg-amber-500 text-white",children:[q.unmatched_cards," umatchet kort"]})]}),(null===(e=n.matched)||void 0===e?void 0:e.length)>0&&(0,O.jsxs)("div",{children:[(0,O.jsx)("p",{className:"text-xs font-semibold text-slate-600 uppercase mb-1",children:"Endringer per sj\xe5f\xf8r + dag"}),(0,O.jsx)("div",{className:"space-y-1","data-testid":"tacho-matched-list",children:n.matched.map(e=>(0,O.jsxs)("div",{className:"border rounded p-2 text-sm","data-testid":"tacho-diff-".concat(e.driver_id,"-").concat(e.date),children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[(0,O.jsx)("span",{className:"font-medium",children:e.driver_name}),(0,O.jsx)(h.E,{variant:"outline",className:"text-[10px]",children:e.date}),e.will_reimport&&(0,O.jsx)(h.E,{className:"bg-amber-500 text-white text-[10px]",children:"re-import"})]}),(0,O.jsxs)("div",{className:"flex items-center gap-2 flex-wrap text-xs",children:[(0,O.jsxs)("span",{className:"text-muted-foreground w-16",children:["F\xf8r (",e.existing_entries,"):"]}),(0,O.jsx)(z,{data:e.existing_breakdown}),(0,O.jsx)($.A,{className:"w-3.5 h-3.5 text-slate-400"}),(0,O.jsxs)("span",{className:"text-muted-foreground w-16",children:["Etter (",e.imported_entries,"):"]}),(0,O.jsx)(z,{data:e.imported_breakdown,testid:"tacho-imported-".concat(e.driver_id,"-").concat(e.date)})]})]},"".concat(e.driver_id,"-").concat(e.date)))})]}),(null===(t=n.unmatched)||void 0===t?void 0:t.length)>0&&(0,O.jsxs)("div",{children:[(0,O.jsxs)("p",{className:"text-xs font-semibold text-amber-700 uppercase mb-1 flex items-center gap-1",children:[(0,O.jsx)(I.A,{className:"w-3.5 h-3.5"}),"Umatchede kort \u2014 velg sj\xe5f\xf8r (ellers importeres de ikke)"]}),(0,O.jsx)("div",{className:"space-y-1","data-testid":"tacho-unmatched-list",children:n.unmatched.map(e=>(0,O.jsxs)("div",{className:"border rounded p-2 flex items-center gap-2 flex-wrap text-sm","data-testid":"tacho-unmatched-".concat(e.driver_card_number),children:[(0,O.jsx)("code",{className:"text-xs bg-slate-100 px-1.5 py-0.5 rounded",children:e.driver_card_number}),(0,O.jsxs)("span",{className:"text-xs text-muted-foreground",children:[e.rows," rad(er)"]}),(0,O.jsxs)(p.l6,{value:g[e.driver_card_number]||"",onValueChange:t=>b(s=>(0,a.A)((0,a.A)({},s),{},{[e.driver_card_number]:t})),children:[(0,O.jsx)(p.bq,{className:"h-8 w-52","data-testid":"tacho-assign-".concat(e.driver_card_number),children:(0,O.jsx)(p.yv,{placeholder:"Velg sj\xe5f\xf8r\u2026"})}),(0,O.jsx)(p.gC,{children:(n.drivers||[]).map(e=>(0,O.jsxs)(p.eb,{value:e.id,children:[e.name,e.has_card?" \u2022":""]},e.id))})]}),g[e.driver_card_number]&&(0,O.jsxs)("label",{className:"flex items-center gap-1.5 text-xs cursor-pointer",children:[(0,O.jsx)(E.S,{checked:!!N[e.driver_card_number],onCheckedChange:t=>w(s=>(0,a.A)((0,a.A)({},s),{},{[e.driver_card_number]:!!t})),"data-testid":"tacho-savecard-".concat(e.driver_card_number)}),"Lagre kortnr p\xe5 profil"]})]},e.driver_card_number))})]}),(null===(s=n.errors)||void 0===s?void 0:s.length)>0&&(0,O.jsxs)("div",{children:[(0,O.jsx)("p",{className:"text-xs font-semibold text-red-700 uppercase mb-1",children:"Feilliste"}),(0,O.jsx)("ul",{className:"space-y-0.5 max-h-40 overflow-y-auto","data-testid":"tach
1o-error-list",children:n.errors.map((e,t)=>(0,O.jsxs)("li",{className:"text-xs text-red-700 bg-red-50 border border-red-200 rounded px-2 py-1",children:["Rad ",e.row,": ",e.message]},t))})]}),(0,O.jsxs)("div",{className:"flex gap-2",children:[(0,O.jsxs)(c.$,{onClick:async()=>{if(n){v(!0);try{const e=Object.entries(N).filter(e=>{let[t,s]=e;return s&&g[t]}).map(e=>{let[t]=e;return g[t]}),{data:t}=await r.A.post("".concat(U,"/commit"),{import_id:n.import_id,manual_assignments:g,save_card_numbers:e}),s=t.stats||{};i.toast.success("Import fullf\xf8rt: ".concat(s.entries_imported," oppf\xf8ringer importert, ").concat(s.entries_archived," manuelle arkivert (").concat(s.days," dager, ").concat(s.drivers," sj\xe5f\xf8rer)")),(t.skipped_unmatched||[]).length&&i.toast.warning("".concat(t.skipped_unmatched.length," umatchede kort ble ikke importert")),d(null),D()}catch(s){var e,t;i.toast.error((null===s||void 0===s||null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Import feilet")}finally{v(!1)}}},disabled:x||0===q.days_matched&&0===Object.keys(g).length,className:"bg-indigo-600 hover:bg-indigo-700","data-testid":"tacho-commit-btn",children:[x?(0,O.jsx)(j.A,{className:"w-4 h-4 mr-1 animate-spin"}):(0,O.jsx)(f.A,{className:"w-4 h-4 mr-1"}),"Importer (erstatt ber\xf8rte dager)"]}),(0,O.jsx)(c.$,{variant:"outline",onClick:()=>d(null),"data-testid":"tacho-cancel-btn",children:"Avbryt"})]})]}),_.length>0&&(0,O.jsxs)("div",{children:[(0,O.jsxs)("p",{className:"text-xs font-semibold text-slate-600 uppercase mb-1 flex items-center gap-1",children:[(0,O.jsx)(K.A,{className:"w-3.5 h-3.5"}),"Import-historikk"]}),(0,O.jsx)("ul",{className:"space-y-1","data-testid":"tacho-history-list",children:_.slice(0,10).map(e=>(0,O.jsxs)("li",{className:"text-xs border rounded px-2 py-1 flex items-center gap-2 flex-wrap",children:[(0,O.jsx)(h.E,{variant:"outline",className:"text-[10px]",children:"committed"===e.status?"Fullf\xf8rt":"Utkast"}),(0,O.jsx)("span",{className:"font-medium",children:e.filename}),(0,O.jsx)("span",{className:"text-muted-foreground",children:new Date(e.created_at).toLocaleString("nb-NO")}),e.stats&&(0,O.jsxs)("span",{className:"text-muted-foreground",children:["\xb7 ",e.stats.entries_imported," importert, ",e.stats.entries_archived," arkivert"]}),e.committed_by_name&&(0,O.jsxs)("span",{className:"text-muted-foreground",children:["\xb7 av ",e.committed_by_name]})]},e.id))})]}),(0,O.jsx)(u.lG,{open:S,onOpenChange:V,children:(0,O.jsxs)(u.Cf,{"data-testid":"tacho-schema-dialog",children:[(0,O.jsxs)(u.c7,{children:[(0,O.jsx)(u.L3,{children:"Fartsskriver-skjema"}),(0,O.jsx)(u.rr,{children:"Dokumentert CSV/JSON-format for import av fartsskriverdata."})]}),(0,O.jsx)("pre",{className:"text-xs whitespace-pre-wrap bg-slate-50 border rounded p-3 max-h-[60vh] overflow-y-auto",children:null===F||void 0===F?void 0:F.schema_doc})]})})]})}var R=s(46403),D=s(36401);const q="".concat("https://travelease.ai","/api"),P="".concat(q,"/admin/compliance"),B=()=>(new Date).toISOString().slice(0,10),M=()=>{const e=new Date;return new Date(e.getFullYear(),e.getMonth(),1).toISOString().slice(0,10)},G={varsel:{label:"Varsel",cls:"bg-amber-100 text-amber-800 border-amber-300",Icon:I.A},overstyring:{label:"Overstyring",cls:"bg-teal-100 text-teal-800 border-teal-300",Icon:v.A},import:{label:"Import",cls:"bg-indigo-100 text-indigo-800 border-indigo-300",Icon:A.A}},X={aapen:"\xc5pen",under_oppfolging:"Under oppf\xf8lging",lukket:"Lukket"},H={aapen:"bg-red-100 text-red-700 border-red-300",under_oppfolging:"bg-amber-100 text-amber-700 border-amber-300",lukket:"bg-emerald-100 text-emerald-700 border-emerald-300"};function Y(){var e,t,s,a,n;const[d,v]=(0,l.useState)(M()),[b,N]=(0,l.useState)(B()),[k,w]=(0,l.useState)("all"),[_,A]=(0,l.useState)("all"),[C,S]=(0,l.useState)("all"),[E,T]=(0,l.useState)(null),[$,I]=(0,l.useState)([]),[K,V]=(0,l.useState)(!1),[U,F]=(0,l.useState)(!1),[L,z]=(0,l.useState)(null),[J,Y]=(0,l.useState)(""),[Z,W]=(0,l.useState)("aapen");(0,l.useEffect)(()=>{r.A.get("".concat(q,"/admin/drivers")).then(e=>{let{data:t}=e;return I(Array.isArray(t)?t:t.drivers||[])}).catch(()=>{})},[]);const Q=(0,l.useCallback)(()=>{let e="date_from=".concat(d,"&date_to=").concat(b);return"all"!==k&&(e+="&driver_id=".concat(k)),"all"!==_&&(e+="&type=".concat(_)),"all"!==C&&(e+="&level=".concat(C)),e},[d,b,k,_,C]),ee=(0,l.useCallback)(async()=>
1{if(d>b)i.toast.error("Ugyldig datointervall");else{V(!0);try{const{data:e}=await r.A.get("".concat(P,"/deviations?").concat(Q()));T(e)}catch(e){i.toast.error("Kunne ikke hente avvikslogg")}finally{V(!1)}}},[Q,d,b]);(0,l.useEffect)(()=>{ee()},[]);const te=(null===E||void 0===E?void 0:E.counts)||{};return(0,O.jsxs)("div",{className:"space-y-4 mt-3","data-testid":"deviation-log-panel",children:[(0,O.jsxs)("div",{className:"rounded-md border p-3 bg-slate-50/40 grid gap-3 sm:grid-cols-6 items-end",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Fra dato"}),(0,O.jsx)(o.p,{type:"date",value:d,onChange:e=>v(e.target.value),className:"h-9","data-testid":"dev-from"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Til dato"}),(0,O.jsx)(o.p,{type:"date",value:b,onChange:e=>N(e.target.value),className:"h-9","data-testid":"dev-to"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Sj\xe5f\xf8r"}),(0,O.jsxs)(p.l6,{value:k,onValueChange:w,children:[(0,O.jsx)(p.bq,{className:"h-9","data-testid":"dev-driver",children:(0,O.jsx)(p.yv,{})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"all",children:"Alle sj\xe5f\xf8rer"}),$.map(e=>(0,O.jsx)(p.eb,{value:e.id,children:e.name||e.email},e.id))]})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Type"}),(0,O.jsxs)(p.l6,{value:_,onValueChange:A,children:[(0,O.jsx)(p.bq,{className:"h-9","data-testid":"dev-type",children:(0,O.jsx)(p.yv,{})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"all",children:"Alle typer"}),(0,O.jsx)(p.eb,{value:"varsel",children:"Varsel"}),(0,O.jsx)(p.eb,{value:"overstyring",children:"Overstyring"}),(0,O.jsx)(p.eb,{value:"import",children:"Import"})]})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Niv\xe5"}),(0,O.jsxs)(p.l6,{value:C,onValueChange:S,children:[(0,O.jsx)(p.bq,{className:"h-9","data-testid":"dev-level",children:(0,O.jsx)(p.yv,{})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"all",children:"Alle niv\xe5er"}),(0,O.jsx)(p.eb,{value:"breach",children:"Brudd"}),(0,O.jsx)(p.eb,{value:"warning",children:"Forvarsel"})]})]})]}),(0,O.jsx)("div",{className:"flex gap-2",children:(0,O.jsxs)(c.$,{size:"sm",onClick:ee,disabled:K,"data-testid":"dev-refresh",children:[K?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(g.A,{className:"w-3.5 h-3.5 mr-1"}),"Oppdater"]})})]}),(0,O.jsxs)("div",{className:"flex flex-wrap gap-2 items-center",children:[(0,O.jsxs)(h.E,{variant:"outline",children:[null!==(e=te.total)&&void 0!==e?e:0," hendelser"]}),(0,O.jsxs)(h.E,{className:"bg-red-600 text-white",children:[null!==(t=te.breach)&&void 0!==t?t:0," brudd"]}),(0,O.jsxs)(h.E,{className:"bg-amber-500 text-white",children:[null!==(s=te.warning)&&void 0!==s?s:0," forvarsler"]}),(0,O.jsxs)(h.E,{className:"bg-teal-600 text-white",children:[null!==(a=te.overstyring)&&void 0!==a?a:0," overstyringer"]}),(0,O.jsxs)(h.E,{className:"bg-indigo-600 text-white",children:[null!==(n=te.import)&&void 0!==n?n:0," importer"]}),(0,O.jsxs)("div",{className:"ml-auto flex gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>async function(e,t){const s=await r.A.get(e,{responseType:"blob"}),a=window.URL.createObjectURL(new Blob([s.data])),l=document.createElement("a");l.href=a,l.download=t,l.click(),window.URL.revokeObjectURL(a)}("".concat(P,"/deviations/export?").concat(Q()),"Avvikslogg_".concat(d,"_").concat(b,".csv")),"data-testid":"dev-export-csv",children:[(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"}),"CSV"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:async()=>{const e=b.slice(0,7);F(!0);try{const{data:t}=await r.A.post("".concat(P,"/monthly-review"),{month:e});i.toast.success("Gjennomgang bekreftet for ".concat(e,": ").concat(t.counts.closed," lukket / ").concat(t.counts.open," \xe5pne avvik"))}catch(t){i.toast.error("Kunne ikke bekrefte gjennomgang")}finally{F(!1)}},disabled:U,"data-testid":"dev-monthly-review",children:[U?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(R.A,{className:"w-3.5 h-3.5 mr-1"}),"Bekreft gjennomgang (",b.slice(0,7),")"]})]})]}),(0,O.jsx)("div",{className:"border rounded-md overflow-hidden",children:(0,O.jsxs)("table",{className:"w-full text-sm","data-testid":"deviation-table",children:[(0,O.jsx)("thead",{className:"bg-slate-100 text-slate-600 text-xs uppercase",children:(0,O.jsxs)("tr",{children:[(0,O.jsx)("th",{className:"text-left p-2",children:"Tidspunkt"}),(0,O.jsx)("th",{className:"text-left p-2",children:"Type"}),(0,O.jsx)("th",{className:"text-left p-2",children:"Sj\xe5f\xf8r"}),(0,O.jsx)("th",{className:"text-left p-2",children:"Hendelse"}),(0,O.jsx)("th",{className:"text-left p-2",children:"Hvem"}),(0,O.jsx)("th",{className:"text-left p-2",children:"Status / tiltak"})]})}),(0,O.jsxs)("tbody",{children:[((null===E||void 0===E?void 0:E.events)||[]).map(e=>{const t=G[e.event_type]||G.varsel;return(0,O.jsxs)("tr",{className:"border-t align-top","data-testid":"dev-row-".concat(e.ref_id),children:[(0,O.jsx)("td",{className:"p-2 whitespace-nowrap text-xs text-muted-foreground",children:String(e.timestamp||"").slice(0,16).replace("T"," ")}),(0,O.jsxs)("td",{className:"p-2",children:[(0,O.jsxs)(h.E,{variant:"outline",className:"text-[10px] ".concat(t.cls),children:[(0,O.jsx)(t.Icon,{className:"w-3 h-3 mr-1"}),t.label]}),e.regime&&(0,O.jsx)("div",{className:"text-[10px] mt-1 text-muted-foreground",children:"kjoretid"===e.regime?"Kj\xf8retid (561/2006)":"Arbeidstid"}),"breach"===e.level&&(0,O.jsx)(h.E,{className:"bg-red-600 text-white text-[10px] ml-1",children:"Brudd"}),"warning"===e.level&&(0,O.jsx)(h.E,{className:"bg-amber-500 text-white text-[10px] ml-1",children:"Forvarsel"})]}),(0,O.jsx)("td",{className:"p-2 text-xs",children:e.driver_name||"\u2014"}),(0,O.jsxs)("td",{className:"p-2 text-xs max-w-md",children:[(0,O.jsx)("div",{className:"font-medium",children:e.title}),e.detail&&(0,O.jsx)("div",{className:"text-muted-foreground",children:e.detail}),e.why&&"varsel"!==e.event_type&&(0,O.jsxs)("div",{className:"text-muted-foreground italic",children:["\xab",e.why,"\xbb"]})]}),(0,O.jsx)("td",{className:"p-2 text-xs",children:e.who||"\u2014"}),(0,O.jsx)("td",{className:"p-2 text-xs",children:"varsel"===e.event_type?(0,O.jsxs)("div",{className:"space-y-1",children:[(0,O.jsx)(h.E,{variant:"outline",className:"text-[10px] ".concat(H[e.followup_status]||""),children:X[e.followup_status]||"\xc5pen"}
1),e.tiltak&&(0,O.jsx)("div",{className:"text-muted-foreground",children:e.tiltak}),(0,O.jsxs)(c.$,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",onClick:()=>(e=>{z(e),Y(e.tiltak||""),W(e.followup_status||"aapen")})(e),"data-testid":"dev-followup-".concat(e.ref_id),children:[(0,O.jsx)(D.A,{className:"w-3 h-3 mr-1"}),"F\xf8lg opp"]})]}):(0,O.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})})]},"".concat(e.source,"-").concat(e.ref_id))}),(!(null!==E&&void 0!==E&&E.events)||0===E.events.length)&&(0,O.jsx)("tr",{children:(0,O.jsx)("td",{colSpan:6,className:"p-6 text-center text-sm text-muted-foreground","data-testid":"dev-empty",children:"Ingen avvik i valgt periode"})})]})]})}),(0,O.jsx)(u.lG,{open:!!L,onOpenChange:e=>!e&&z(null),children:(0,O.jsxs)(u.Cf,{"data-testid":"dev-followup-dialog",children:[(0,O.jsxs)(u.c7,{children:[(0,O.jsx)(u.L3,{children:"F\xf8lg opp avvik"}),(0,O.jsx)(u.rr,{children:null===L||void 0===L?void 0:L.title})]}),(0,O.jsxs)("div",{className:"space-y-3",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Status"}),(0,O.jsxs)(p.l6,{value:Z,onValueChange:W,children:[(0,O.jsx)(p.bq,{className:"h-9","data-testid":"dev-followup-status",children:(0,O.jsx)(p.yv,{})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"aapen",children:"\xc5pen"}),(0,O.jsx)(p.eb,{value:"under_oppfolging",children:"Under oppf\xf8lging"}),(0,O.jsx)(p.eb,{value:"lukket",children:"Lukket"})]})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Tiltak (fritekst)"}),(0,O.jsx)(x.T,{value:J,onChange:e=>Y(e.target.value),rows:3,placeholder:"Hva ble gjort for \xe5 lukke avviket?","data-testid":"dev-followup-tiltak"})]})]}),(0,O.jsxs)(u.Es,{children:[(0,O.jsx)(c.$,{variant:"outline",onClick:()=>z(null),children:"Avbryt"}),(0,O.jsxs)(c.$,{onClick:async()=>{if(L)try{await r.A.put("".concat(P,"/alerts/").concat(L.ref_id,"/followup"),{tiltak:J,followup_status:Z}),i.toast.success("Tiltak og status lagret"),z(null),ee()}catch(e){i.toast.error("Kunne ikke lagre oppf\xf8lging")}},"data-testid":"dev-followup-save",children:[(0,O.jsx)(f.A,{className:"w-4 h-4 mr-1"}),"Lagre"]})]})]})})]})}var Z=s(11827),W=s(76245),Q=s(3308),ee=s(7118),te=s(35746),se=s(53986),ae=s(36383),le=s(92382),re=s(15074);const ie=["className"],ne=["className","children"],de=["className","children"],ce=ae.bL,oe=l.forwardRef((e,t)=>{let{className:s}=e,l=(0,se.A)(e,ie);return(0,O.jsx)(ae.q7,(0,a.A)({ref:t,className:(0,re.cn)("border-b",s)},l))});oe.displayName="AccordionItem";const me=l.forwardRef((e,t)=>{let{className:s,children:l}=e,r=(0,se.A)(e,ne);return(0,O.jsx)(ae.Y9,{className:"flex",children:(0,O.jsxs)(ae.l9,(0,a.A)((0,a.A)({ref:t,className:(0,re.cn)("flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",s)},r),{},{children:[l,(0,O.jsx)(le.A,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200"})]}))})});me.displayName=ae.l9.displayName;const xe=l.forwardRef((e,t)=>{let{className:s,children:l}=e,r=(0,se.A)(e,de);return(0,O.jsx)(ae.UC,(0,a.A)((0,a.A)({ref:t,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"},r),{},{children:(0,O.jsx)("div",{className:(0,re.cn)("pb-4 pt-0",s),children:l})}))});xe.displayName=ae.UC.displayName;var he=s(92499);const pe="".concat("https://travelease.ai","/api"),ue={would_push:{label:"Vil pushes",cls:"bg-sky-100 text-sky-700"},would_update:{label:"Vil oppdateres",cls:"bg-sky-100 text-sky-700"},pushed:{label:"Pushet",cls:"bg-emerald-100 text-emerald-700"},updated:{label:"Oppdatert",cls:"bg-emerald-100 text-emerald-700"},already_sent:{label:"Allerede sendt",cls:"bg-slate-100 text-slate-600"},changed_needs_force:{label:"Endret \u2013 krever tving",cls:"bg-amber-100 text-amber-700"},failed:{label:"Feilet",cls:"bg-red-100 text-red-700"}};function ve(e){var t,s,n;let{from:d,to:x,validRange:u}=e;const[b,N]=(0,l.useState)(null),[k,y]=(0,l.useState)(!1),[w,_]=(0,l.useState)(!1),[A,C]=(0,l.useState)(""),[E,T]=(0,l.useState)(""),[$,K]=(0,l.useState)(""),[V,U]=(0,l.useState)("production"),[F,L]=(0,l.useState)({}),[z,J]=(0,l.useState)({}),[R,D]=(0,l.useState)(!1),[q,P]=(0,l.useState)(!1),[B,M]=(0,l.useState)(null),[G,X]=(0,l.useState)(""),H=(0,l.useCallback)(async()=>{y(!0);try{var e;const{data:t}=await r.A.get("".concat(pe,"/tripletex/timesheet/config"));N(t),U(t.environment||"production"),K((null===(e=t.credentials)||void 0===e?void 0:e.company_id)||"");const s={};Object.entries(t.activity_map||{}
1).forEach(e=>{let[t,a]=e;s[t]=String(a)}),L(s);const a={};Object.entries(t.employee_map||{}).forEach(e=>{let[t,s]=e;a[t]=String(s)}),J(a)}catch(t){i.toast.error("Kunne ikke hente Tripletex-oppsett")}finally{y(!1)}},[]);(0,l.useEffect)(()=>{H()},[H]);const Y=async(e,t)=>{if(u){X(e?"preview":t?"force":"push");try{const{data:s}=await r.A.post("".concat(pe,"/tripletex/timesheet/push"),{date_from:d,date_to:x,dry_run:e,force:t});if(M(s),!e){const e=s.summary||{};i.toast.success("Push ferdig: ".concat(e.pushed||0," nye, ").concat(e.updated||0," oppdatert, ").concat(e.failed||0," feilet")),await H()}}catch(l){var s,a;i.toast.error((null===l||void 0===l||null===(s=l.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Push feilet")}finally{X("")}}else i.toast.error("Ugyldig datointervall")},se=(null===b||void 0===b?void 0:b.activities)||[],ae=(null===b||void 0===b?void 0:b.employees)||[],le=(null===b||void 0===b?void 0:b.drivers)||[],re=!(null===b||void 0===b||!b.connected),ie=!(null===b||void 0===b||null===(t=b.credentials)||void 0===t||!t.configured),ne=e=>{const t=se.find(t=>Number(t.id)===Number(e));return t?t.name:"Aktivitet ".concat(e)};return(0,O.jsxs)("div",{className:"rounded-md border p-3 space-y-3 sm:col-span-2","data-testid":"tripletex-push-card",children:[(0,O.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-sky-700",children:[(0,O.jsx)(Z.A,{className:"h-4 w-4"})," Direkte Tripletex-push (l\xf8nnstimer)"]}),(0,O.jsxs)("div",{className:"flex items-center gap-2",children:[(0,O.jsxs)(h.E,{variant:"outline",className:"text-[11px]","data-testid":"tripletex-env-badge",children:["Milj\xf8: ","test"===V?"TEST (api-test.tripletex.tech)":"Produksjon (tripletex.no)"]}),k?(0,O.jsx)(j.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}):re?(0,O.jsxs)(h.E,{className:"bg-emerald-100 text-emerald-700 hover:bg-emerald-100","data-testid":"tripletex-connected-badge",children:[(0,O.jsx)(f.A,{className:"h-3 w-3 mr-1"})," Tilkoblet"]}):(0,O.jsxs)(h.E,{variant:"outline",className:"text-muted-foreground","data-testid":"tripletex-disconnected-badge",children:[(0,O.jsx)(W.A,{className:"h-3 w-3 mr-1"})," ",ie?"Ikke tilkoblet":"Ikke konfigurert"]})]})]}),(0,O.jsx)("p",{className:"text-xs text-muted-foreground",children:"Sender aktive timer (pause utelatt) rett til Tripletex som timeliste-oppf\xf8ringer. Ukategoriserte timer pushes ALDRI mot standardaktivitet \u2014 de m\xe5 mappes eksplisitt eller hoppes over med advarsel."}),(0,O.jsx)(ce,{type:"single",collapsible:!0,className:"border rounded-md",children:(0,O.jsxs)(oe,{value:"setup",className:"border-b-0",children:[(0,O.jsx)(me,{className:"px-3 py-2 text-sm","data-testid":"tripletex-setup-toggle",children:"Oppsett: milj\xf8, n\xf8kler og mapping"}),(0,O.jsxs)(xe,{className:"px-3 pb-3 space-y-4",children:[(0,O.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Milj\xf8"}),(0,O.jsxs)(p.l6,{value:V,onValueChange:U,children:[(0,O.jsx)(p.bq,{"data-testid":"tripletex-env-select",className:"h-9",children:(0,O.jsx)(p.yv,{})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"test",children:"Test \u2014 api-test.tripletex.tech"}),(0,O.jsx)(p.eb,{value:"production",children:"Produksjon \u2014 tripletex.no"})]})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Selskaps-ID (Tripletex)"}),(0,O.jsx)(o.p,{value:$,onChange:e=>K(e.target.value),placeholder:"0 = egen bedrift",className:"h-9","data-testid":"tripletex-companyid-input"})]})]}),(0,O.jsxs)("div",{className:"rounded-md border p-3 space-y-2 bg-slate-50/50",children:[(0,O.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold",children:[(0,O.jsx)(Q.A,{className:"h-3.5 w-3.5"})," API-n\xf8kler"]}),ie&&!w&&(0,O.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground","data-testid":"tripletex-creds-masked",children:[(0,O.jsxs)("span",{children:["Consumer ",null===b||void 0===b||null===(s=b.credentials)||void 0===s?void 0:s.consumer_masked]}),(0,O.jsxs)("span",{children:["Employee ",null===b||void 0===b||null===(n=b.credentials)||void 0===n?void 0:n.employee_masked]})]}),(0,O.jsx)(c.$,{size:"sm",variant:"outline",onClick:()=>_(e=>!e),"data-testid":"tripletex-creds-edit-btn",children:w?"Avbryt":ie?"Bytt n\xf8kkel":"Legg inn n\xf8kler"})]}),w&&(0,O.jsxs)("div",{className:"space-y-2",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Consumer token"}),(0,O.jsx)(o.p,{value:A,onChange:e=>C(e.target.value),placeholder:"eyJ0b2tlbklk...",className:"h-9 font-mono text-xs","data-testid":"tripletex-consumer-input"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Employee token"}),(0,O.jsx)(o.p,{value:E,onChange:e=>T(e.target.value),placeholder:"eyJ0b2tlbklk...",className:"h-9 font-mono text-xs","data-testid":"tripletex-employee-input"})]}),(0,O.jsxs)("p",{className:"text-[11px] text-amber-600 flex items-center gap-1",children:[(0,O.jsx)(v.A,{className:"h-3 w-3"})," Bruk KUN test-n\xf8kler i preview. N\xf8kler lagres kryptert og vises aldri i klartekst igjen."]}),(0,O.jsxs)(c.$,{size:"sm",onClick:async()=>{D(!0);try{await r.A.put("".concat(pe,"/tripletex/timesheet/credentials"),{consumer_token:A||void 0,employee_token:E||void 0,company_id:$,environment:V}),i.toast.success("Tripletex-n\xf8kler lagret (kryptert)"),C(""),T(""),_(!1),await H()}catch(s){var e,t;i.toast.error((null===s||void 0===s||null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Kunne ikke lagre n\xf8kler")}finally{D(!1)}},disabled:R,"data-testid":"tripletex-save-creds-btn",children:[R?(0,O.jsx)(j.A,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,O.jsx)(S.A,{className:"h-3.5 w-3.5 mr-1"})," Lagre n\xf8kler"]})]})]}),(0,O.jsxs)("div",{className:"space-y-2",children:[(0,O.jsx)("div",{className:"text-xs font-semibold",children:"Kategori \u2192 Tripletex-aktivitet"}),!re&&(0,O.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Koble til Tripletex for \xe5 hente aktiviteter."}),((null===b||void 0===b?void 0:b.activity_categories)||[]).map(e=>(0,O.jsxs)("div",{className:"grid grid-cols-[140px_1fr] items-center gap-2",children:[(0,O.jsxs)(m.J,{className:"text-xs",children:[e.label,"ukategorisert"===e.key&&(0,O.jsx)("span",{className:"text-amber-600",children:" *"})]}),(0,O.jsxs)(p.l6,{value:F[e.key]||"none",onValueChange:t=>L(s=>(0,a.A)((0,a.A)({},s),{},{[e.key]:t})),children:[(0,O.jsx)(p.bq,{className:"h-9","data-testid":"tripletex-activity-".concat(e.key,"-select"),children:(0,O.jsx)(p.yv,{placeholder:"Ikke mappet"})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"none",children:"ukategorisert"===e.key?"Ikke mappet (hoppes over m/advarsel)":"Bruk standardaktivitet"}),se.map(e=>(0,O.jsxs)(p.eb,{value:String(e.id),children:[e.name,e.is_general?" \xb7 generell":""]},e.id))]})]})]},e.key)),(0,O.jsx)("p",{className:"text-[11px] text-amber-600",children:"* Ukategorisert faller aldri tilbake til standard. Tips: generelle aktiviteter kan brukes uten prosjekt."})]}),(0,O.jsxs)("div",{className:"space-y-2",children:[(0,O.jsxs)("div",{className:"text-xs font-semibold flex items-center gap-1",children:[(0,O.jsx)(ee.A,{className:"h-3.5 w-3.5"})," Sj\xe5f\xf8r \u2192 Tripletex-ansatt"]}),!re&&(0,O.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Koble til Tripletex for \xe5 hente ansatte."}),(0,O.jsx)("div",{className:"max-h-56 overflow-auto space-y-1 pr-1",children:le.map(e=>(0,O.jsxs)("div",{className:"grid grid-cols-[140px_1fr] items-center gap-2",children:[(0,O.jsx)(m.J,{className:"text-xs truncate",title:e.name,children:e.name}),(0,O.jsxs)(p.l6,{value:z[e.id]||"none",onValueChange:t=>J(s=>(0,a.A)((0,a.A)({},s),{},{[e.id]:t})),children:[(0,O.jsx)(p.bq,{className:"h-9","data-testid":"tripletex-employee-map-".concat(e.id,"-select"),children:(0,O.jsx)(p.yv,{placeholder:"Ikke mappet"})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"none",children:"Ikke mappet"}),ae.map(e=>(0,O.jsxs)(p.eb,{value:String(e.id),children:[e.name,e.email?" (".concat(e.email,")"):""]},e.id))]})]})]},e.id))})]}),(0,O.jsx)("div",{className:"flex justify-end",children:(0,O.jsxs)(c.$,{size:"sm",onClick:async()=>{P(!0);try{const e={};
1Object.entries(F).forEach(t=>{let[s,a]=t;a&&"none"!==a&&(e[s]=Number(a))});const t={};Object.entries(z).forEach(e=>{let[s,a]=e;a&&"none"!==a&&(t[s]=Number(a))}),await r.A.put("".concat(pe,"/tripletex/timesheet/config"),{environment:V,activity_map:e,employee_map:t}),i.toast.success("Oppsett lagret"),await H()}catch(s){var e,t;i.toast.error((null===s||void 0===s||null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Kunne ikke lagre oppsett")}finally{P(!1)}},disabled:q,"data-testid":"tripletex-save-mapping-btn",children:[q?(0,O.jsx)(j.A,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,O.jsx)(S.A,{className:"h-3.5 w-3.5 mr-1"})," Lagre oppsett"]})})]})]})}),(0,O.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>Y(!0,!1),disabled:""!==G,"data-testid":"tripletex-push-preview-btn",children:["preview"===G?(0,O.jsx)(j.A,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,O.jsx)(g.A,{className:"h-3.5 w-3.5 mr-1"})," Forh\xe5ndsvis"]}),(0,O.jsxs)(c.$,{size:"sm",className:"bg-sky-600 hover:bg-sky-700",onClick:()=>Y(!1,!1),disabled:""!==G||!re,"data-testid":"tripletex-push-btn",children:["push"===G?(0,O.jsx)(j.A,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,O.jsx)(te.A,{className:"h-3.5 w-3.5 mr-1"})," Push til Tripletex"]}),(0,O.jsxs)(he.Lt,{children:[(0,O.jsx)(he.tv,{asChild:!0,children:(0,O.jsxs)(c.$,{size:"sm",variant:"outline",className:"border-amber-400 text-amber-700",disabled:""!==G||!re,"data-testid":"tripletex-force-push-btn",children:[(0,O.jsx)(I.A,{className:"h-3.5 w-3.5 mr-1"})," Tving re-push"]})}),(0,O.jsxs)(he.EO,{"data-testid":"tripletex-force-confirm",children:[(0,O.jsxs)(he.wd,{children:[(0,O.jsx)(he.r7,{children:"Tving re-push til Tripletex?"}),(0,O.jsxs)(he.$v,{children:["Dette overskriver allerede sendte og endrede timeliste-oppf\xf8ringer i Tripletex for perioden"," ".concat(d," \u2013 ").concat(x),". Handlingen loggf\xf8res. Bruk kun n\xe5r du vet at Tripletex skal oppdateres."]})]}),(0,O.jsxs)(he.ck,{children:[(0,O.jsx)(he.Zr,{children:"Avbryt"}),(0,O.jsx)(he.Rx,{onClick:()=>Y(!1,!0),"data-testid":"tripletex-force-confirm-btn",children:"Ja, tving re-push"})]})]})]})]}),B&&(0,O.jsxs)("div",{className:"space-y-2","data-testid":"tripletex-push-results",children:[B.dry_run&&(0,O.jsx)(h.E,{variant:"outline",className:"text-[11px]",children:"Forh\xe5ndsvisning (ingen data sendt)"}),(0,O.jsx)("div",{className:"flex flex-wrap gap-1.5 text-[11px]",children:Object.entries(B.summary||{}).map(e=>{var t;let[s,a]=e;return a>0?(0,O.jsxs)(h.E,{variant:"secondary",className:"text-[11px]",children:[(null===(t=ue[s])||void 0===t?void 0:t.label)||s,": ",a]},s):null})}),(B.warnings||[]).length>0&&(0,O.jsx)("div",{className:"rounded-md border border-amber-300 bg-amber-50 p-2 space-y-1","data-testid":"tripletex-push-warnings",children:B.warnings.map((e,t)=>(0,O.jsxs)("div",{className:"text-[11px] text-amber-800 flex items-start gap-1",children:[(0,O.jsx)(I.A,{className:"h-3 w-3 mt-0.5 shrink-0"})," ",e]},t))}),(B.items||[]).length>0?(0,O.jsx)("div",{className:"overflow-auto max-h-72 rounded-md border",children:(0,O.jsxs)("table",{className:"w-full text-xs",children:[(0,O.jsx)("thead",{className:"bg-slate-50 sticky top-0",children:(0,O.jsxs)("tr",{className:"text-left",children:[(0,O.jsx)("th",{className:"p-2",children:"Status"}),(0,O.jsx)("th",{className:"p-2",children:"Sj\xe5f\xf8r"}),(0,O.jsx)("th",{className:"p-2",children:"Dato"}),(0,O.jsx)("th",{className:"p-2",children:"Aktivitet"}),(0,O.jsx)("th",{className:"p-2 text-right",children:"Timer"}),(0,O.jsx)("th",{className:"p-2",children:"Kommentar / feil"})]})}),(0,O.jsx)("tbody",{children:B.items.map((e,t)=>{var s,a;return(0,O.jsxs)("tr",{className:"border-t","data-testid":"tripletex-push-row",children:[(0,O.jsx)("td",{className:"p-2",children:(0,O.jsx)(h.E,{className:"text-[10px] ".concat((null===(s=ue[e.status])||void 0===s?void 0:s.cls)||"bg-slate-100"),children:(null===(a=ue[e.status])||void 0===a?void 0:a.label)||e.status})}),(0,O.jsx)("td",{className:"p-2",children:e.driver_name}),(0,O.jsx)("td",{className:"p-2",children:e.date}),(0,O.jsx)("td",{className:"p-2",children:ne(e.activity_id)}),(0,O.jsx)("td",{className:"p-2 text-right",children:e.hours}),(0,O.jsx)("td",{className:"p-2 text-muted-foreground",children:e.error?(0,O.jsx)("span",{className:"text-red-600",children:e.error}):e.comment})]},t)})})]})}):(0,O.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Ingen linjer \xe5 pushe for perioden."})]})]})}const je="".concat("https://travelease.ai","/api");const ge=()=>(new Date).toISOString().slice(0,10),fe=()=>{const e=new Date;return new Date(e.getFullYear(),e.getMonth(),1).toISOString().slice(0,10)},be=e=>(0,O.jsx)(h.E,{className:"".concat({critical:"bg-red-600 text-white",warning:"bg-amber-500 text-white",info:"bg-blue-500 text-white"}[e]||"bg-slate-400 text-white"," text-[10px]"),children:e}),Ne=[{v:"privatkjoring",l:"Privatkj\xf8ring"},{v:"verkstedkjoring",l:"Verkstedkj\xf8ring"},{v:"posisjonskjoring",l:"Posisjonskj\xf8ring"},{v:"annet",l:"Annet"}];function ke(){return(0,O.jsxs)(n.Zp,{"data-testid":"compliance-center",children:[(0,O.jsx)(n.aR,{children:(0,O.jsxs)(n.ZB,{className:"flex items-center gap-2",children:[(0,O.jsx)(v.A,{className:"h-5 w-5 text-emerald-600"})," SVV-kontroll & rapporter"]})}),(0,O.jsx)(n.Wu,{children:(0,O.jsxs)(d.tU,{defaultValue:"alerts",children:[(0,O.jsxs)(d.j7,{className:"grid w-full grid-cols-6",children:[(0,O.jsx)(d.Xi,{value:"alerts","data-testid":"compliance-alerts-tab",children:"Utl\xf8psvarsler"}),(0,O.jsx)(d.Xi,{value:"deviations","data-testid":"compliance-deviations-tab",children:"Avvikslogg"}),(0,O.jsx)(d.Xi,{value:"events","data-testid":"compliance-events-tab",children:"Avvik"}),(0,O.jsx)(d.Xi,{value:"nonrevenue","data-testid":"compliance-nonrevenue-tab",children:"Kj\xf8ring utenom oppdrag"}),(0,O.jsx)(d.Xi,{value:"reports","data-testid":"compliance-reports-tab",children:"Rapporter"}),(0,O.jsx)(d.Xi,{value:"tacho","data-testid":"compliance-tacho-tab",children:"Fartsskriver"})]}),(0,O.jsx)(d.av,{value:"alerts",children:(0,O.jsx)(ye,{})}),(0,O.jsx)(d.av,{value:"deviations",children:(0,O.jsx)(Y,{})}),(0,O.jsx)(d.av,{value:"events",children:(0,O.jsx)(we,{})}),(0,O.jsx)(d.av,{value:"nonrevenue",children:(0,O.jsx)(_e,{})}),(0,O.jsx)(d.av,{value:"reports",children:(0,O.jsx)(Ae,{})}),(0,O.jsx)(d.av,{value:"tacho",children:(0,O.jsx)(Ee,{})})]})})]})}function ye(){const[e,t]=(0,l.useState)([]),[s,a]=(0,l.useState)({}),[n,d]=(0,l.useState)(!0),[o,m]=(0,l.useState)(!1),x=(0,l.useCallback)(async()=>{d(!0);try{const{data:e}=await r.A.get("".concat(je,"/admin/compliance/credential-alerts"));t(e.alerts||[]),a(e.summary||{})}catch(e){i.toast.error("Kunne ikke laste varsler")}finally{d(!1)}},[]);(0,l.useEffect)(()=>{x()},[x]);return n?(0,O.jsx)("div",{className:"py-8 text-center text-muted-foreground",children:(0,O.jsx)(j.A,{className:"w-5 h-5 animate-spin inline"})}):(0,O.jsxs)("div",{className:"space-y-3 mt-3",children:[(0,O.jsxs)("div",{className:"flex items-center justify-between",children:[(0,O.jsxs)("div",{className:"flex gap-2 text-sm",children:[(0,O.jsxs)(h.E,{className:"bg-red-600 text-white",children:[s.critical||0," kritisk"]}),(0,O.jsxs)(h.E,{className:"bg-amber-500 text-white",children:[s.warning||0," advarsel"]}),(0,O.jsxs)(h.E,{className:"bg-blue-500 text-white",children:[s.info||0," kommende"]})]}),(0,O.jsxs)(c.$,{size:"sm",onClick:async()=>{m(!0);try{const{data:e}=await r.A.post("".concat(je,"/admin/compliance/credential-check"));i.toast.success("Sjekk fullf\xf8rt: ".concat(e.events_created," nye avvik, ").concat(e.notifications_created," varsler")),await x()}catch(e){i.toast.error("Sjekk feilet")}finally{m(!1)}},disabled:o,"data-testid":"run-credential-check-btn",children:[o?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(g.A,{className:"w-3.5 h-3.5 mr-1"})," Kj\xf8r sjekk n\xe5"]})]}),0===e.length?(0,O.jsx)("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Ingen utl\xf8psvarsler innenfor 90 dager."}):(0,O.jsx)("ul",{className:"space-y-1","data-testid":"credential-alerts-list",children:e.map((e,t)=>(0,O.jsxs)("li",{className:"flex items-center gap-2 text-sm border rounded p-2 bg-slate-50/50",children:[be(e.severity),(0,O.jsx)("span",{className:"font-medium",children:e.label}),(0,O.jsxs)("span",{className:"text-muted-foreground",children:["\u2014 ",e.driver_name||e.registration_number]}),(0,O.jsxs)("span",{className:"ml-auto text-xs",children:[e.due_date," (",e.days_remaining<0?"utl\xf8pt ".concat(Math.abs(e.days_remaining)," d"):"".concat(e.days_remaining," d"),")"]})]},t))})]})}function we(){const[e,t]=(0,l.useState)([]),[s,a]=(0,l.useState)(!0),[n,d]=(0,l.useState)("unresolved"),[o,m]=(0,l.useState)(null),[v,g]=(0,l.useState)(""),b=(0,l.useCallback)(async()=>{a(!0);try{const e="all"===n?"":"resolved"===n?"?resolved=true":"?resolved=false",{data:s}=await r.A.get("".concat(je,"/admin/compliance/events").concat(e));t(s.events||[])}catch(e){i.toast.error("Kunne ikke laste avvik")}finally{a(!1)}},[n]);(0,l.useEffect)(()=>{b()},[b]);return(0,O.jsxs)("div",{className:"space-y-3 mt-3",children:[(0,O.jsxs)(p.l6,{value:n,onValueChange:d,children:[(0,O.jsx)(p.bq,{className:"w-56","data-testid":"events-filter",children:(0,O.jsx)(p.yv,{})}),(0,O.jsxs)(p.gC,{children:[(0,O.jsx)(p.eb,{value:"unresolved",children:"Ul\xf8ste"}),(0,O.jsx)(p.eb,{value:"resolved",children:"Lukkede"}),(0,O.jsx)(p.eb,{value:"all",children:"Alle"})]})]}),s?(0,O.jsx)("div",{className:"py-6 text-center",children:(0,O.jsx)(j.A,{className:"w-5 h-5 animate-spin inline"})}):0===e.length?(0,O.jsx)("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Ingen avvik."}):(0,O.jsx)("ul",{className:"space-y-1","data-testid":"compliance-events-list",children:e.map(e=>(0,O.jsxs)("li",{className:"flex items-center gap-2 text-sm border rounded p-2",children:[be(e.severity),(0,O.jsx)(h.E,{variant:"outline",className:"text-[10px]",children:e.type}),(0,O.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.message}),e.resolved_at?(0,O.jsxs)(h.E,{className:"bg-emerald-600 text-white text-[10px]",children:[(0,O.jsx)(f.A,{className:"h-3 w-3 mr-0.5"}),"Lukket"]}):(0,O.jsx)(c.$,{size:"sm",variant:"outline",onClick:()=>{m(e),g("")},"data-testid":"resolve-event-".concat(e.id),children:"Tiltak"})]},e.id))}),(0,O.jsx)(u.lG,{open:!!o,onOpenChange:e=>!e&&m(null),children:(0,O.jsxs)(u.Cf,{"data-testid":"resolve-event-dialog",children:[(0,O.jsx)(u.c7,{children:(0,O.jsx)(u.L3,{children:"Registrer tiltak"})}),(0,O.jsx)("p",{className:"text-sm text-muted-foreground",children:null===o||void 0===o?void 0:o.message}
1),(0,O.jsx)(x.T,{value:v,onChange:e=>g(e.target.value),placeholder:"Beskriv tiltaket som er gjort/planlagt\u2026","data-testid":"resolution-input"}),(0,O.jsxs)(u.Es,{children:[(0,O.jsx)(c.$,{variant:"outline",onClick:()=>m(null),children:"Avbryt"}),(0,O.jsx)(c.$,{onClick:async()=>{if(v.trim())try{await r.A.put("".concat(je,"/admin/compliance/events/").concat(o.id,"/resolve"),{resolution:v.trim()}),i.toast.success("Avvik lukket med tiltak"),m(null),g(""),await b()}catch(e){i.toast.error("Kunne ikke lukke avvik")}else i.toast.error("Tiltak er p\xe5krevd")},"data-testid":"confirm-resolve-btn",children:"Lukk avvik"})]})]})})]})}function _e(){const[e,t]=(0,l.useState)([]),[s,n]=(0,l.useState)([]),[d,x]=(0,l.useState)(!0),[u,v]=(0,l.useState)({category:"verkstedkjoring",vehicle_id:"",person_name:"",date_from:"",time_from:"",date_to:"",time_to:"",reason:""}),[g,f]=(0,l.useState)(!1),k=(0,l.useCallback)(async()=>{x(!0);try{const[e,s]=await Promise.all([r.A.get("".concat(je,"/admin/compliance/non-revenue-trips")),r.A.get("".concat(je,"/admin/vehicles"))]);t(e.data.trips||[]),n(Array.isArray(s.data)?s.data:[])}catch(e){i.toast.error("Kunne ikke laste")}finally{x(!1)}},[]);(0,l.useEffect)(()=>{k()},[k]);const y=async(e,t)=>{try{await r.A.post("".concat(je,"/admin/compliance/non-revenue-trips/").concat(e,"/").concat(t),"approve"===t?{}:void 0),i.toast.success("approve"===t?"Godkjent":"Fullf\xf8rt"),await k()}catch(l){var s,a;i.toast.error((null===l||void 0===l||null===(s=l.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Handling feilet")}};return(0,O.jsxs)("div",{className:"space-y-4 mt-3",children:[(0,O.jsxs)("div",{className:"rounded-md border border-dashed p-3 bg-slate-50/40 space-y-2","data-testid":"nonrevenue-form",children:[(0,O.jsxs)("div",{className:"text-xs font-semibold text-emerald-700 uppercase flex items-center gap-1",children:[(0,O.jsx)(b.A,{className:"h-3.5 w-3.5"})," Ny registrering"]}),(0,O.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Kategori"}),(0,O.jsxs)(p.l6,{value:u.category,onValueChange:e=>v((0,a.A)((0,a.A)({},u),{},{category:e})),children:[(0,O.jsx)(p.bq,{"data-testid":"nr-category",children:(0,O.jsx)(p.yv,{})}),(0,O.jsx)(p.gC,{children:Ne.map(e=>(0,O.jsx)(p.eb,{value:e.v,children:e.l},e.v))})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Kj\xf8ret\xf8y"}),(0,O.jsxs)(p.l6,{value:u.vehicle_id,onValueChange:e=>v((0,a.A)((0,a.A)({},u),{},{vehicle_id:e})),children:[(0,O.jsx)(p.bq,{"data-testid":"nr-vehicle",children:(0,O.jsx)(p.yv,{placeholder:"Velg"})}),(0,O.jsx)(p.gC,{children:s.map(e=>(0,O.jsx)(p.eb,{value:e.id,children:e.registration_number},e.id))})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Person (sj\xe5f\xf8r/mekaniker)"}),(0,O.jsx)(o.p,{value:u.person_name,onChange:e=>v((0,a.A)((0,a.A)({},u),{},{person_name:e.target.value})),placeholder:"Navn","data-testid":"nr-person"})]}),(0,O.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Fra dato"}),(0,O.jsx)(o.p,{type:"date",value:u.date_from,onChange:e=>v((0,a.A)((0,a.A)({},u),{},{date_from:e.target.value})),"data-testid":"nr-date-from"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Til dato"}),(0,O.jsx)(o.p,{type:"date",value:u.date_to,onChange:e=>v((0,a.A)((0,a.A)({},u),{},{date_to:e.target.value})),"data-testid":"nr-date-to"})]})]}),(0,O.jsxs)("div",{className:"col-span-2",children:[(0,O.jsx)(m.J,{className:"text-xs",children:"\xc5rsak"}),(0,O.jsx)(o.p,{value:u.reason,onChange:e=>v((0,a.A)((0,a.A)({},u),{},{reason:e.target.value})),placeholder:"f.eks. Til verksted for service","data-testid":"nr-reason"})]})]}),(0,O.jsxs)(c.$,{size:"sm",onClick:async()=>{if(u.vehicle_id&&u.date_from&&u.date_to&&u.reason.trim()&&u.person_name.trim()){f(!0);try{await r.A.post("".concat(je,"/admin/compliance/non-revenue-trips"),u),i.toast.success("Registrert (venter godkjenning)"),v({category:"verkstedkjoring",vehicle_id:"",person_name:"",date_from:"",time_from:"",date_to:"",time_to:"",reason:""}),await k()}catch(s){var e,t;i.toast.error((null===s||void 0===s||null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Kunne ikke registrere")}finally{f(!1)}}else i.toast.error("Kj\xf8ret\xf8y, person, datoer og \xe5rsak er p\xe5krevd")},disabled:g,"data-testid":"nr-create-btn",children:[g?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(b.A,{className:"w-3.5 h-3.5 mr-1"})," Registrer"]})]}),d?(0,O.jsx)("div",{className:"py-6 text-center",children:(0,O.jsx)(j.A,{className:"w-5 h-5 animate-spin inline"})}):(0,O.jsxs)("ul",{className:"space-y-1","data-testid":"nonrevenue-list",children:[e.map(e=>{return(0,O.jsxs)("li",{className:"flex items-center gap-2 text-sm border rounded p-2",children:[(0,O.jsx)(N.A,{className:"h-3.5 w-3.5 text-slate-500"}),(t=e.status,(0,O.jsx)(h.E,{className:"".concat({requested:"bg-amber-500",approved:"bg-blue-500",completed:"bg-emerald-600"}[t]||"bg-slate-400"," text-white text-[10px]"),children:{requested:"Forespurt",approved:"Godkjent",completed:"Fullf\xf8rt"}[t]||t})),(0,O.jsx)("span",{className:"font-medium",children:e.vehicle_reg}),(0,O.jsxs)("span",{className:"text-muted-foreground truncate",children:[e.person_name," \xb7 ",e.category," \xb7 ",e.date_from]}),(0,O.jsxs)("div",{className:"ml-auto flex gap-1",children:["requested"===e.status&&(0,O.jsx)(c.$,{size:"sm",variant:"outline",onClick:()=>y(e.id,"approve"),"data-testid":"nr-approve-".concat(e.id),children:"Godkjenn"}),"approved"===e.status&&(0,O.jsx)(c.$,{size:"sm",variant:"outline",onClick:()=>y(e.id,"complete"),"data-testid":"nr-complete-".concat(e.id),children:"Fullf\xf8r"})]})]},e.id);var t}),0===e.length&&(0,O.jsx)("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Ingen registreringer."})]})]})}function Ae(){var e,t,s,a,n,d,x,p,u;const[v,f]=(0,l.useState)(fe()),[b,N]=(0,l.useState)(ge()),[C,S]=(0,l.useState)(null),[E,T]=(0,l.useState)(!1),[$,I]=(0,l.useState)(""),K=!!v&&!!b&&v<=b,V=(0,l.useCallback)(async()=>
1{if(K){T(!0);try{const{data:e}=await r.A.get("".concat(je,"/admin/compliance/control-report/preview"),{params:{date_from:v,date_to:b}});S(e)}catch(e){i.toast.error("Kunne ikke hente forh\xe5ndsvisning")}finally{T(!1)}}else i.toast.error("Ugyldig datointervall")},[v,b,K]),U=async(e,t,s)=>{if(K){I(e);try{await async function(e,t){const s=await r.A.get(e,{responseType:"blob"}),a=s.headers["content-disposition"]||s.headers["Content-Disposition"]||"",l=/filename\*?=(?:UTF-8'')?"?([^;"]+)"?/i.exec(a),i=l?decodeURIComponent(l[1]):t,n=window.URL.createObjectURL(new Blob([s.data])),d=document.createElement("a");d.href=n,d.download=i,document.body.appendChild(d),d.click(),d.remove(),window.URL.revokeObjectURL(n)}(t,s),i.toast.success("Nedlasting startet")}catch(a){i.toast.error("Nedlasting feilet")}finally{I("")}}else i.toast.error("Ugyldig datointervall")},F="date_from=".concat(v,"&date_to=").concat(b);return(0,O.jsxs)("div",{className:"space-y-4 mt-3","data-testid":"reports-tab",children:[(0,O.jsxs)("div",{className:"rounded-md border p-3 bg-slate-50/40 grid grid-cols-2 gap-3 sm:max-w-md",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Fra dato"}),(0,O.jsx)(o.p,{type:"date",value:v,onChange:e=>f(e.target.value),"data-testid":"report-date-from",className:"h-9"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Til dato"}),(0,O.jsx)(o.p,{type:"date",value:b,onChange:e=>N(e.target.value),"data-testid":"report-date-to",className:"h-9"})]}),(0,O.jsx)("div",{className:"col-span-2",children:(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:V,disabled:E,"data-testid":"report-preview-btn",children:[E?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(g.A,{className:"w-3.5 h-3.5 mr-1"})," Forh\xe5ndsvis antall"]})})]}),C&&(0,O.jsxs)("div",{className:"flex flex-wrap gap-2 text-sm","data-testid":"report-preview",children:[(0,O.jsxs)(h.E,{variant:"outline",children:[null!==(e=null===(t=C.counts)||void 0===t?void 0:t.vehicles)&&void 0!==e?e:0," kj\xf8ret\xf8y"]}),(0,O.jsxs)(h.E,{variant:"outline",children:[null!==(s=null===(a=C.counts)||void 0===a?void 0:a.drivers)&&void 0!==s?s:0," sj\xe5f\xf8rer"]}),(0,O.jsxs)(h.E,{variant:"outline",children:[null!==(n=null===(d=C.counts)||void 0===d?void 0:d.trips)&&void 0!==n?n:0," turer"]}),(0,O.jsxs)(h.E,{variant:"outline",children:[null!==(x=null===(p=C.counts)||void 0===p?void 0:p.events)&&void 0!==x?x:0," hendelser"]}),(0,O.jsxs)(h.E,{variant:"outline",children:[null!==(u=C.section_c_count)&&void 0!==u?u:0," avvik"]})]}),(0,O.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,O.jsxs)("div",{className:"rounded-md border p-3 space-y-2",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-emerald-700",children:[(0,O.jsx)(k.A,{className:"h-4 w-4"})," Myndighetskontroll"]}),(0,O.jsx)("p",{className:"text-xs text-muted-foreground",children:"Samlet foretakskontroll-rapport (kj\xf8reliste, aktivitet per sj\xe5f\xf8r, avvik, gyldighetsstatus)."}),(0,O.jsxs)("div",{className:"flex gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",onClick:()=>U("control-pdf","".concat(je,"/admin/compliance/control-report?").concat(F,"&format=pdf"),"Myndighetskontroll_".concat(v,"_").concat(b,".pdf")),disabled:"control-pdf"===$,"data-testid":"download-control-pdf",children:["control-pdf"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"})," PDF"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>U("control-xlsx","".concat(je,"/admin/compliance/control-report?").concat(F,"&format=xlsx"),"Myndighetskontroll_".concat(v,"_").concat(b,".xlsx")),disabled:"control-xlsx"===$,"data-testid":"download-control-xlsx",children:["control-xlsx"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(w.A,{className:"w-3.5 h-3.5 mr-1"})," Excel"]})]})]}),(0,O.jsxs)("div",{className:"rounded-md border p-3 space-y-2",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-emerald-700",children:[(0,O.jsx)(_.A,{className:"h-4 w-4"})," Timeliste (Arbeidstilsynet)"]}),(0,O.jsx)("p",{className:"text-xs text-muted-foreground",children:"Timeliste per sj\xe5f\xf8r med ukesum og periodesum (midnatt-korrigert arbeidstid)."}),(0,O.jsxs)("div",{className:"flex gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",onClick:()=>U("ts-xlsx","".concat(je,"/admin/compliance/timesheet-export?").concat(F,"&format=xlsx"),"Timeliste_".concat(v,"_").concat(b,".xlsx")),disabled:"ts-xlsx"===$,"data-testid":"download-timesheet-xlsx",children:["ts-xlsx"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(w.A,{className:"w-3.5 h-3.5 mr-1"})," Excel"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>U("ts-csv","".concat(je,"/admin/compliance/timesheet-export?").concat(F,"&format=csv"),"Timeliste_".concat(v,"_").concat(b,".csv")),disabled:"ts-csv"===$,"data-testid":"download-timesheet-csv",children:["ts-csv"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"})," CSV"]})]})]}),(0,O.jsxs)("div",{className:"rounded-md border p-3 space-y-2","data-testid":"compliance-report-card",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-indigo-700",children:[(0,O.jsx)(A.A,{className:"h-4 w-4"})," Compliance-rapport (SVV)"]}),(0,O.jsx)("p",{className:"text-xs text-muted-foreground",children:"Kj\xf8re-/hviletid (561/2006) + arbeidstid, avvik, overstyringer og datakilde per dag (fartsskriver vs. manuell). Klar for SVV-kontroll."}),(0,O.jsxs)("div",{className:"flex gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",className:"bg-indigo-600 hover:bg-indigo-700",onClick:()=>U("comp-pdf","".concat(je,"/admin/compliance/compliance-report?").concat(F,"&format=pdf"),"Compliance_".concat(v,"_").concat(b,".pdf")),disabled:"comp-pdf"===$,"data-testid":"download-compliance-pdf",children:["comp-pdf"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"})," PDF"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>U("comp-xlsx","".concat(je,"/admin/compliance/compliance-report?").concat(F,"&format=xlsx"),"Compliance_".concat(v,"_").concat(b,".xlsx")),disabled:"comp-xlsx"===$,"data-testid":"download-compliance-xlsx",children:["comp-xlsx"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(w.A,{className:"w-3.5 h-3.5 mr-1"})," Excel"]})]})]}),(0,O.jsxs)("div",{className:"rounded-md border p-3 space-y-2","data-testid":"tripletex-export-card",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-sky-700",children:[(0,O.jsx)(w.A,{className:"h-4 w-4"})," Tripletex l\xf8nnseksport"]}),(0,O.jsx)("p",{className:"text-xs text-muted-foreground",children:"Aktive timer per sj\xe5f\xf8r/dag/kategori (etter fartsskriver-erstatning). Pause utelates, ukategorisert tas med. Egen import_id-kolonne for sporing."}),(0,O.jsxs)("div",{className:"flex gap-2",children:[(0,O.jsxs)(c.$,{size:"sm",onClick:()=>U("tex-xlsx","".concat(je,"/admin/compliance/tripletex-export?").concat(F,"&format=xlsx"),"Tripletex_".concat(v,"_").concat(b,".xlsx")),disabled:"tex-xlsx"===$,"data-testid":"download-tripletex-xlsx",children:["tex-xlsx"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(w.A,{className:"w-3.5 h-3.5 mr-1"})," Excel"]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",onClick:()=>U("tex-csv","".concat(je,"/admin/compliance/tripletex-export?").concat(F,"&format=csv"),"Tripletex_".concat(v,"_").concat(b,".csv")),disabled:"tex-csv"===$,"data-testid":"download-tripletex-csv",children:["tex-csv"===$?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(y.A,{className:"w-3.5 h-3.5 mr-1"})," CSV"]})]})]}),(0,O.jsx)(ve,{from:v,to:b,validRange:K})]})]})}const Ce={forfalt:{cls:"bg-red-600",label:"Forfalt"},advarsel:{cls:"bg-amber-500",label:"Advarsel"},mangler:{cls:"bg-slate-500",label:"Mangler"},ok:{cls:"bg-emerald-600",label:"OK"}},Se=[{v:"manuell_nedlasting",l:"Manuell nedlasting"},{v:"fjernnedlasting",l:"Fjernnedlasting"},{v:"verksted",l:"Verksted"}];function Ee(){var e,t;const[s,a]=(0,l.useState)({rows:[],summary:{},settings:{}}),[n,d]=(0,l.useState)(!0),[x,v]=(0,l.useState)(!1),[f,N]=(0,l.useState)(null),[k,y]=(0,l.useState)(ge()),[w,_]=(0,l.useState)("manuell_nedlasting"),[E,T]=(0,l.useState)(!1),[$,I]=(0,l.useState)("28"),[K,V]=(0,l.useState)("90"),[U,F]=(0,l.useState)(!1),L=(0,l.useCallback)(async()=>{d(!0);try{var e,t,s,l;const{data:i}=await r.A.get("".concat(je,"/admin/compliance/tacho-downloads"));a(i),I(String(null!==(e=null===(t=i.settings)||void 0===t?void 0:t.card_days)&&void 0!==e?e:28)),V(String(null!==(s=null===(l=i.settings)||void 0===l?void 0:l.vehicle_days)&&void 0!==s?s:90))}catch(n){i.toast.error("Kunne ikke laste fartsskriver-tavle")}finally{d(!1)}},[]);(0,l.useEffect)(()=>{L()},[L]);const z=s.summary||{},R=(null===(e=s.rows)||void 0===e?void 0:e.filter(e=>"driver_card"===e.type))||[],D=(null===(t=s.rows)||void 0===t?void 0:t.filter(e=>"vehicle_unit"===e.type))||[],q=e=>
1{const t=Ce[e.status]||Ce.mangler;return(0,O.jsxs)("li",{className:"flex items-center gap-2 text-sm border rounded p-2","data-testid":"tacho-row-".concat(e.subject_id),children:[(0,O.jsx)(A.A,{className:"h-3.5 w-3.5 text-slate-500"}),(0,O.jsx)(h.E,{className:"".concat(t.cls," text-white text-[10px]"),children:t.label}),(0,O.jsx)("span",{className:"font-medium",children:e.subject_label}),(0,O.jsxs)("span",{className:"text-muted-foreground text-xs",children:[e.last_download?"Sist: ".concat(e.last_download):"Aldri lastet ned",null!=e.days_since&&" \xb7 ".concat(e.days_since," d siden")," \xb7 intervall ".concat(e.interval_days," d"),null!=e.next_due_in&&" \xb7 ".concat(e.next_due_in>0?"".concat(e.next_due_in," d igjen"):"".concat(Math.abs(e.next_due_in)," d over"))]}),(0,O.jsxs)(c.$,{size:"sm",variant:"outline",className:"ml-auto",onClick:()=>(e=>{N(e),y(ge()),_("manuell_nedlasting")})(e),"data-testid":"tacho-register-".concat(e.subject_id),children:[(0,O.jsx)(b.A,{className:"w-3.5 h-3.5 mr-1"})," Registrer"]})]},"".concat(e.type,"-").concat(e.subject_id))};return n?(0,O.jsx)("div",{className:"py-8 text-center text-muted-foreground mt-3",children:(0,O.jsx)(j.A,{className:"w-5 h-5 animate-spin inline"})}):(0,O.jsxs)("div",{className:"space-y-4 mt-3","data-testid":"tacho-tab",children:[(0,O.jsx)(J,{}),(0,O.jsx)("div",{className:"border-t pt-4",children:(0,O.jsx)("p",{className:"text-xs font-semibold text-slate-600 uppercase mb-2",children:"Nedlasting-sporing"})}),(0,O.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[(0,O.jsxs)("div",{className:"flex gap-2 text-sm",children:[(0,O.jsxs)(h.E,{className:"bg-red-600 text-white",children:[z.forfalt||0," forfalt"]}),(0,O.jsxs)(h.E,{className:"bg-amber-500 text-white",children:[z.advarsel||0," advarsel"]}),(0,O.jsxs)(h.E,{className:"bg-slate-500 text-white",children:[z.mangler||0," mangler"]}),(0,O.jsxs)(h.E,{className:"bg-emerald-600 text-white",children:[z.ok||0," OK"]})]}),(0,O.jsxs)(c.$,{size:"sm",onClick:async()=>{v(!0);try{const{data:e}=await r.A.post("".concat(je,"/admin/compliance/tacho-check"));i.toast.success("Sjekk fullf\xf8rt: ".concat(e.events_created," nye avvik")),await L()}catch(e){i.toast.error("Sjekk feilet")}finally{v(!1)}},disabled:x,"data-testid":"run-tacho-check-btn",children:[x?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(g.A,{className:"w-3.5 h-3.5 mr-1"})," Kj\xf8r sjekk n\xe5"]})]}),(0,O.jsxs)("div",{className:"rounded-md border p-3 bg-slate-50/40 space-y-2","data-testid":"tacho-settings",children:[(0,O.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold text-emerald-700 uppercase",children:[(0,O.jsx)(C.A,{className:"h-3.5 w-3.5"})," Intervaller (dager)"]}),(0,O.jsxs)("div",{className:"flex items-end gap-3 flex-wrap",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Sj\xe5f\xf8rkort"}),(0,O.jsx)(o.p,{type:"number",min:"1",value:$,onChange:e=>I(e.target.value),className:"h-9 w-24","data-testid":"tacho-card-days"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Kj\xf8ret\xf8ysenhet"}),(0,O.jsx)(o.p,{type:"number",min:"1",value:K,onChange:e=>V(e.target.value),className:"h-9 w-24","data-testid":"tacho-vehicle-days"})]}),(0,O.jsxs)(c.$,{size:"sm",onClick:async()=>{F(!0);try{await r.A.put("".concat(je,"/admin/compliance/tacho-settings"),{card_days:parseInt($)||28,vehicle_days:parseInt(K)||90}),i.toast.success("Intervaller lagret"),await L()}catch(s){var e,t;i.toast.error((null===s||void 0===s||null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Kunne ikke lagre")}finally{F(!1)}},disabled:U,"data-testid":"save-tacho-settings-btn",children:[U?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(S.A,{className:"w-3.5 h-3.5 mr-1"})," Lagre"]})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("p",{className:"text-xs font-semibold text-slate-600 uppercase mb-1",children:"Sj\xe5f\xf8rkort"}),(0,O.jsxs)("ul",{className:"space-y-1","data-testid":"tacho-cards-list",children:[R.map(q),0===R.length&&(0,O.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"Ingen sj\xe5f\xf8rkort."})]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("p",{className:"text-xs font-semibold text-slate-600 uppercase mb-1",children:"Kj\xf8ret\xf8ysenheter"}
1),(0,O.jsxs)("ul",{className:"space-y-1","data-testid":"tacho-units-list",children:[D.map(q),0===D.length&&(0,O.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"Ingen kj\xf8ret\xf8y."})]})]}),(0,O.jsx)(u.lG,{open:!!f,onOpenChange:e=>!e&&N(null),children:(0,O.jsxs)(u.Cf,{"data-testid":"tacho-register-dialog",children:[(0,O.jsx)(u.c7,{children:(0,O.jsxs)(u.L3,{children:["Registrer nedlasting \u2014 ",null===f||void 0===f?void 0:f.subject_label]})}),(0,O.jsxs)("div",{className:"space-y-3",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Nedlastingsdato"}),(0,O.jsx)(o.p,{type:"date",value:k,onChange:e=>y(e.target.value),"data-testid":"tacho-reg-date"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)(m.J,{className:"text-xs",children:"Metode"}),(0,O.jsxs)(p.l6,{value:w,onValueChange:_,children:[(0,O.jsx)(p.bq,{"data-testid":"tacho-reg-method",children:(0,O.jsx)(p.yv,{})}),(0,O.jsx)(p.gC,{children:Se.map(e=>(0,O.jsx)(p.eb,{value:e.v,children:e.l},e.v))})]})]})]}),(0,O.jsxs)(u.Es,{children:[(0,O.jsx)(c.$,{variant:"outline",onClick:()=>N(null),children:"Avbryt"}),(0,O.jsxs)(c.$,{onClick:async()=>{if(k){T(!0);try{await r.A.post("".concat(je,"/admin/compliance/tacho-downloads"),{type:f.type,subject_id:f.subject_id,subject_label:f.subject_label,download_date:k,method:w}),i.toast.success("Nedlasting registrert"),N(null),await L()}catch(s){var e,t;i.toast.error((null===s||void 0===s||null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Kunne ikke registrere")}finally{T(!1)}}else i.toast.error("Dato er p\xe5krevd")},disabled:E,"data-testid":"confirm-tacho-register-btn",children:[E?(0,O.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):(0,O.jsx)(S.A,{className:"w-3.5 h-3.5 mr-1"})," Registrer"]})]})]})})]})}}}]);
2//# sourceMappingURL=8379.9bce4d08.chunk.js.map

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.