signalk-siparu 0.2.18 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-siparu",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "Kept aboard, proven ashore. Position, wind, depth and voyage history, recorded on the boat and readable from anywhere: sealed to the devices you name, signed on the way out. A read-only Signal K plugin with a built-in dashboard.",
5
5
  "keywords": [
6
6
  "signalk-node-server-plugin",
@@ -0,0 +1,5 @@
1
+ import type { IRouter, RequestHandler } from 'express';
2
+ export interface ReadRegistrar {
3
+ get(path: string, ...handlers: RequestHandler[]): unknown;
4
+ }
5
+ export declare function readable(router: IRouter): ReadRegistrar;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readable = readable;
4
+ function readable(router) {
5
+ const access = router.access;
6
+ if (typeof access === 'function') {
7
+ const registrar = access.call(router, 'readonly');
8
+ if (registrar && typeof registrar.get === 'function')
9
+ return registrar;
10
+ }
11
+ return router;
12
+ }
@@ -1,5 +1,6 @@
1
1
  import type { ServerAPI } from '@signalk/server-api';
2
2
  import type { IRouter } from 'express';
3
+ import { allowConfigure } from './pairing';
3
4
  interface ConfigDeps {
4
5
  app: ServerAPI;
5
6
  acceptOpenNetwork: () => boolean;
@@ -10,6 +11,5 @@ interface ConfigDeps {
10
11
  };
11
12
  restart: (configuration: object) => void;
12
13
  }
13
- export declare function allowConfigure(app: ServerAPI, req: unknown): boolean;
14
+ export { allowConfigure };
14
15
  export declare function registerConfigRoutes(router: IRouter, deps: ConfigDeps): void;
15
- export {};
@@ -1,18 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allowConfigure = allowConfigure;
3
+ exports.allowConfigure = void 0;
4
4
  exports.registerConfigRoutes = registerConfigRoutes;
5
5
  const pairing_1 = require("./pairing");
6
+ Object.defineProperty(exports, "allowConfigure", { enumerable: true, get: function () { return pairing_1.allowConfigure; } });
6
7
  const origin_guard_1 = require("./origin-guard");
7
- function allowConfigure(app, req) {
8
- try {
9
- const ss = app.securityStrategy;
10
- return ss?.allowConfigure?.(req) === true;
11
- }
12
- catch {
13
- return false;
14
- }
15
- }
8
+ const access_1 = require("./access");
16
9
  function readJsonBody(req) {
17
10
  return new Promise((resolve) => {
18
11
  const parsed = req.body;
@@ -41,7 +34,7 @@ function readJsonBody(req) {
41
34
  }
42
35
  function registerConfigRoutes(router, deps) {
43
36
  const { app, acceptOpenNetwork, getConfig, fuelPathsView, restart } = deps;
44
- router.get('/config/fuel-paths', (_req, res) => {
37
+ (0, access_1.readable)(router).get('/config/fuel-paths', (_req, res) => {
45
38
  res.json(fuelPathsView());
46
39
  });
47
40
  router.post('/config/fuel-paths', (0, origin_guard_1.sameOrigin)((req, res) => {
@@ -51,7 +44,7 @@ function registerConfigRoutes(router, deps) {
51
44
  return;
52
45
  }
53
46
  }
54
- else if (!allowConfigure(app, req)) {
47
+ else if (!(0, pairing_1.allowConfigure)(app, req)) {
55
48
  res.status(403).json({ error: 'admin_required' });
56
49
  return;
57
50
  }
@@ -8,11 +8,11 @@ export type PairScreen = {
8
8
  state: 'idle';
9
9
  } | {
10
10
  state: 'showing_code';
11
- userCode: string;
11
+ userCode: string | null;
12
12
  expiresAt: string;
13
13
  } | {
14
14
  state: 'awaiting_approval';
15
- userCode: string;
15
+ userCode: string | null;
16
16
  email: string | null;
17
17
  expiresAt: string;
18
18
  device?: {
@@ -38,6 +38,9 @@ export type PairStatus = PairScreen & {
38
38
  };
39
39
  export declare function securityOff(app: ServerAPI, req: unknown): boolean;
40
40
  export declare function writeLocked(app: ServerAPI, req: unknown, acceptOpenNetwork: boolean): boolean;
41
+ export declare function allowConfigure(app: ServerAPI, req: unknown): boolean;
42
+ export declare function privileged(app: ServerAPI, req: unknown): boolean;
43
+ export declare function forTheCrew(screen: PairScreen): PairScreen;
41
44
  export declare const WRITE_LOCKED_MESSAGE = "Signal K security is off, so Siparu will not pair, unpair or edit the log. Add an admin user in Signal K, or accept the open-network risk in the plugin settings.";
42
45
  interface Deps {
43
46
  app: ServerAPI;
@@ -3,10 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RelayRefused = exports.WRITE_LOCKED_MESSAGE = void 0;
4
4
  exports.securityOff = securityOff;
5
5
  exports.writeLocked = writeLocked;
6
+ exports.allowConfigure = allowConfigure;
7
+ exports.privileged = privileged;
8
+ exports.forTheCrew = forTheCrew;
6
9
  exports.maskEmail = maskEmail;
7
10
  exports.registerPairRoutes = registerPairRoutes;
8
11
  exports.retryPendingUnlinks = retryPendingUnlinks;
9
12
  exports.__resetPairingState = __resetPairingState;
13
+ const access_1 = require("./access");
10
14
  const fingerprint_1 = require("./fingerprint");
11
15
  const origin_guard_1 = require("./origin-guard");
12
16
  function securityOff(app, req) {
@@ -21,6 +25,30 @@ function securityOff(app, req) {
21
25
  function writeLocked(app, req, acceptOpenNetwork) {
22
26
  return securityOff(app, req) && !acceptOpenNetwork;
23
27
  }
28
+ function allowConfigure(app, req) {
29
+ try {
30
+ const ss = app.securityStrategy;
31
+ return ss?.allowConfigure?.(req) === true;
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ }
37
+ function privileged(app, req) {
38
+ return securityOff(app, req) || allowConfigure(app, req);
39
+ }
40
+ function forTheCrew(screen) {
41
+ switch (screen.state) {
42
+ case 'showing_code':
43
+ return { state: 'showing_code', userCode: null, expiresAt: screen.expiresAt };
44
+ case 'awaiting_approval':
45
+ return { state: 'awaiting_approval', userCode: null, email: null, expiresAt: screen.expiresAt };
46
+ case 'paired':
47
+ return { ...screen, email: null };
48
+ default:
49
+ return screen;
50
+ }
51
+ }
24
52
  exports.WRITE_LOCKED_MESSAGE = 'Signal K security is off, so Siparu will not pair, unpair or edit the log. Add an admin user in Signal K, or accept the open-network risk in the plugin settings.';
25
53
  let deviceCode = null;
26
54
  let userCode = null;
@@ -110,8 +138,9 @@ function registerPairRoutes(router, deps) {
110
138
  pairedAt: remote.pairedAt,
111
139
  uplink: uplinkStatus() ?? undefined
112
140
  });
113
- router.get('/pair/status', (0, origin_guard_1.sameOrigin)((req, res) => {
114
- const json = (screen) => {
141
+ (0, access_1.readable)(router).get('/pair/status', (0, origin_guard_1.sameOrigin)((req, res) => {
142
+ const json = (full) => {
143
+ const screen = privileged(app, req) ? full : forTheCrew(full);
115
144
  const status = { ...screen };
116
145
  if (securityOff(app, req)) {
117
146
  status.security_off = true;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.setRestDeps = setRestDeps;
37
37
  exports.registerRoutes = registerRoutes;
38
38
  const nodePath = __importStar(require("node:path"));
39
+ const access_1 = require("./access");
39
40
  const charts_1 = require("./charts");
40
41
  const query_1 = require("./query");
41
42
  let deps = null;
@@ -60,17 +61,18 @@ function intParam(req, name) {
60
61
  return n;
61
62
  }
62
63
  function registerRoutes(router) {
63
- router.get('/live', (_req, res) => {
64
+ const read = (0, access_1.readable)(router);
65
+ read.get('/live', (_req, res) => {
64
66
  if (!deps)
65
67
  return sendError(res, 503, 'NOT_STARTED', 'plugin is not started');
66
68
  res.json(deps.live());
67
69
  });
68
- router.get('/inventory', (_req, res) => {
70
+ read.get('/inventory', (_req, res) => {
69
71
  if (!deps)
70
72
  return sendError(res, 503, 'NOT_STARTED', 'plugin is not started');
71
73
  res.json(deps.inventory());
72
74
  });
73
- router.get('/snapshots', (req, res) => {
75
+ read.get('/snapshots', (req, res) => {
74
76
  if (!deps)
75
77
  return sendError(res, 503, 'NOT_STARTED', 'plugin is not started');
76
78
  let q;
@@ -97,7 +99,7 @@ function registerRoutes(router) {
97
99
  sendInternal(res, err);
98
100
  });
99
101
  });
100
- router.get('/health', (_req, res) => {
102
+ read.get('/health', (_req, res) => {
101
103
  if (!deps)
102
104
  return sendError(res, 503, 'NOT_STARTED', 'plugin is not started');
103
105
  deps
@@ -106,7 +108,7 @@ function registerRoutes(router) {
106
108
  .catch((err) => sendInternal(res, err));
107
109
  });
108
110
  const asyncGet = (path, handler) => {
109
- router.get(path, (req, res) => {
111
+ read.get(path, (req, res) => {
110
112
  if (!deps)
111
113
  return sendError(res, 503, 'NOT_STARTED', 'plugin is not started');
112
114
  const d = deps;
@@ -144,7 +146,7 @@ function registerRoutes(router) {
144
146
  return d.rollupHours(from, to);
145
147
  });
146
148
  asyncGet('/map-config', async (d) => d.mapConfig());
147
- router.get('/charts/*', (req, res) => {
149
+ read.get('/charts/*', (req, res) => {
148
150
  if (!deps)
149
151
  return sendError(res, 503, 'NOT_STARTED', 'plugin is not started');
150
152
  const rest = req.params['0'];
@@ -4,6 +4,7 @@ exports.registerVoyageEditRoutes = registerVoyageEditRoutes;
4
4
  const pairing_1 = require("./pairing");
5
5
  const config_routes_1 = require("./config-routes");
6
6
  const origin_guard_1 = require("./origin-guard");
7
+ const access_1 = require("./access");
7
8
  const STATUS = {
8
9
  not_found: 404,
9
10
  no_previous: 409,
@@ -12,7 +13,7 @@ const STATUS = {
12
13
  };
13
14
  function registerVoyageEditRoutes(router, deps) {
14
15
  const { app, acceptOpenNetwork, edits, mergeWithPrevious, undoMerge } = deps;
15
- router.get('/voyages/edits', (_req, res) => {
16
+ (0, access_1.readable)(router).get('/voyages/edits', (_req, res) => {
16
17
  res.json(edits());
17
18
  });
18
19
  const edit = (name, run) => {
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./tz-DxphYhHy.js","./rolldown-runtime-CNC7AqOf.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{t as r}from"./visibleInterval-CFxPzgzx.js";import{A as i,C as a,D as o,E as s,F as c,N as l,O as u,P as d,S as f,T as p,_ as m,b as h,c as g,d as _,g as v,k as y,l as b,o as x,p as S,s as C,v as w,w as T}from"./index-gLen3lD8.js";import{a as E,d as D,i as O,l as k,n as A,o as j,r as M,t as N,u as P}from"./export-CGdOfqNp.js";var F=e(t(),1),I={key:`ts`,head:`UTC`,book:`bridge`,cell:()=>``};function L(e,t,n,r){if(e===null)return`·`;let i=Math.abs(e),a=Math.floor(i),o=(i-a)*60;return`${String(a).padStart(t,`0`)}°${o.toFixed(3).padStart(6,`0`)}' ${e<0?r:n}`}function R(e){return[{col:{key:`lat`,head:`LAT`,book:`bridge`,lanes:2,cell:e=>L(e.lat,2,`N`,`S`)},has:e=>e.lat!==null},{col:{key:`lon`,head:`LON`,book:`bridge`,lanes:2,cell:e=>L(e.lon,3,`E`,`W`)},has:e=>e.lon!==null},{col:{key:`sog`,head:`SOG`,book:`bridge`,unit:`kn`,cell:e=>h(o(e.sog),1)},has:e=>e.sog!==null},{col:{key:`cog`,head:`COG`,book:`bridge`,cell:e=>{let t=s(e.cog);return t===null?`·`:Math.round(t)+`°`}},has:e=>e.cog!==null},{col:{key:`hdg`,head:`HDG`,book:`bridge`,cell:e=>{let t=s(e.heading_true??e.heading_mag);return t===null?`·`:Math.round(t)+`°`}},has:e=>(e.heading_true??e.heading_mag)!==null},{col:{key:`wind`,head:e===`kn`?`TWS`:`BFT`,book:`bridge`,unit:e===`kn`?`kn`:void 0,tappable:!0,cell:t=>{let n=T(t.wind_speed_true);return n===null?`·`:String(e===`kn`?Math.round(n):a(n)??`·`)}},has:e=>e.wind_speed_true!==null},{col:{key:`awa`,head:`AWA`,book:`bridge`,cell:e=>{let t=s(e.wind_angle_apparent);if(t===null)return`·`;let n=(t+180)%360-180;return`${Math.abs(Math.round(n))}°${n<0?`P`:`S`}`}},has:e=>e.wind_angle_apparent!==null},{col:{key:`baro`,head:`BARO`,book:`bridge`,unit:`hPa`,dim:!0,cell:e=>{let t=p(e.air_pressure_pa);return t===null?`·`:String(Math.round(t))}},has:e=>e.air_pressure_pa!==null},{col:{key:`air`,head:`AIR`,book:`bridge`,unit:`°C`,cell:e=>h(f(e.air_temp_k),1)},has:e=>e.air_temp_k!==null},{col:{key:`sea`,head:`SEA`,book:`bridge`,unit:`°C`,cell:e=>h(f(e.water_temp_k),1)},has:e=>e.water_temp_k!==null},{col:{key:`depth`,head:`DEP`,book:`bridge`,unit:`m`,cell:e=>e.depth===null?`·`:e.depth.toFixed(1)},has:e=>e.depth!==null}]}var z={Revolutions:`RPM`,Temperature:`TEMP`,"Oil pressure":`OIL`,"Oil temperature":`OILT`,"Coolant temperature":`COOL`,"Coolant pressure":`COOLP`,"Exhaust temperature":`EXH`,"Intake manifold temperature":`INTK`,"Boost pressure":`BOOST`,"Engine load":`LOAD`,"Engine torque":`TORQ`,"Run time":`HRS`,"Fuel rate":`FUEL`,"Fuel per mile":`L/NM`,"Fuel used (since reset)":`USED`,"Fuel pressure":`FUELP`,"Alternator voltage":`ALT`,"Gearbox oil temperature":`GBOXT`,"Gearbox oil pressure":`GBOXP`,"Current level":`LEVEL`,Voltage:`VOLT`,Current:`AMP`};function B(e){return z[e]??e.split(` `)[0].toUpperCase()}function V(e){return e.sub===null?e.tab===`tanks`?`Current level`:null:e.sub}function H(e){let t=/^(Engine|Generator|Fuel|Fresh water|Black water|Grey water|Lubrication)\s+(\S+)$/.exec(e);return t?`${t[1].split(` `).map(e=>e[0]).join(``)}${t[2]}`.toUpperCase():e.slice(0,1).toUpperCase()}function U(e){let t=[];for(let n of e)for(let e of Object.keys(n.path_values??{}))t.includes(e)||t.push(e);let n=[];for(let e of t){let t=u(e);if(!t)continue;let r=V(t);r!==null&&n.push({path:e,d:{...t,sub:r}})}let r=new Map;for(let{d:e}of n)r.has(e.tab)||r.set(e.tab,new Set),r.get(e.tab).add(e.label);let a=[];for(let{path:e,d:t}of n){let n=B(t.sub);a.push({col:{key:`p:${e}`,head:r.get(t.tab).size>1?`${H(t.label)} ${n}`:n,book:`engine`,tab:t.tab,unit:i(e),cell:t=>{let n=t.path_values?.[e];if(typeof n!=`number`)return`·`;let r=y(e,n).value;return Number.isFinite(r)?Number.isInteger(r)?String(r):r.toFixed(1):`·`}},has:t=>typeof t.path_values?.[e]==`number`})}return a}function W(e,t){return[I,...[...R(t),...U(e)].filter(t=>e.some(t.has)).map(e=>e.col)]}function G(e,t){return e.filter(e=>e.key===`ts`||e.book===t)}var ee={engine:`ENGINES`,generator:`GENERATORS`,tanks:`TANKS`};function K(e){let t=[],n=new Map,r=new Map;for(let i of e)for(let e of Object.keys(i.path_values??{})){let i=u(e);if(!i)continue;let a=V(i);if(a===null)continue;n.has(i.tab)||(t.push(i.tab),n.set(i.tab,new Map),r.set(i.tab,[]));let o=n.get(i.tab);o.has(i.label)||o.set(i.label,new Map),o.get(i.label).set(a,e);let s=r.get(i.tab);s.includes(a)||s.push(a)}return t.map(e=>{let t=[...n.get(e)].map(([e,t])=>({key:e,head:e.toUpperCase(),paths:Object.fromEntries(t)})),a=r.get(e).map(e=>{let n=t.map(t=>t.paths[e]).find(e=>e!==void 0);return{key:e,head:B(e),unit:n===void 0?``:i(n)}});return{tab:e,head:ee[e]??e.toUpperCase(),units:t,metrics:a}})}function te(e,t,n){let r=t.paths[n.key];if(r===void 0)return`·`;let i=e.path_values?.[r];if(typeof i!=`number`)return`·`;let a=y(r,i).value;return Number.isFinite(a)?Number.isInteger(a)?String(a):a.toFixed(1):`·`}function ne(e,t){let[n,r]=(0,F.useState)(e),[i,a]=(0,F.useState)(!1);return(0,F.useEffect)(()=>{if(e===n)return;a(!0);let i=setTimeout(()=>{r(e),a(!1)},t);return()=>clearTimeout(i)},[e,n,t]),[n,i]}var q=new Map;function J(e,t,n){let r=`${t}|${e}`,i=q.get(r);if(i===void 0){try{i=new Intl.DateTimeFormat(`en-GB`,{...n,timeZone:e})}catch{i=null}q.set(r,i)}return i}var re={hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`},Y={hour:`2-digit`,timeZoneName:`shortOffset`},X={weekday:`short`,day:`2-digit`,month:`short`,year:`numeric`},Z=e=>e!==null&&J(e,`clock`,re)&&J(e,`offset`,Y)&&J(e,`day`,X)?e:`UTC`;function ie(e,t){return J(Z(t),`clock`,re).format(e)}function ae(e,t){let n=J(Z(t),`offset`,Y);if(!n)return`UTC`;let r=(n.formatToParts(e).find(e=>e.type===`timeZoneName`)?.value??``).replace(/^(GMT|UTC)/,``);return/[1-9]/.test(r)?`UTC${r}`:`UTC`}function oe(e,t){return J(Z(t),`day`,X).format(e).replace(/,\s*/,` · `).toUpperCase()}function se(e,t){let n=new Map,r=new Map,i=(e,n)=>{let i=`${Math.round(e*10)},${Math.round(n*10)}`,a=r.get(i);if(a===void 0){try{a=t(e,n)}catch{a=null}r.set(i,a)}return a},a=[...e].sort((e,t)=>e.ts-t.ts),o=a.map(e=>t!==null&&e.lat!==null&&e.lon!==null?i(e.lat,e.lon):null),s=a.flatMap((e,t)=>o[t]===null?[]:[{ts:e.ts,zone:o[t]}]),c=0;return a.forEach((e,t)=>{if(o[t]!==null||s.length===0){n.set(e.ts,o[t]);return}for(;c+1<s.length&&Math.abs(s[c+1].ts-e.ts)<Math.abs(s[c].ts-e.ts);)c++;n.set(e.ts,s[c].zone)}),n}function ce(e,t){let n=se(e,t),r=e=>n.get(e)??null,i=new Set(e.map(e=>ae(e.ts,r(e.ts)))),a=i.size>1;return{head:a?`SHIP`:i.values().next().value??`UTC`,mixed:a,clock:e=>ie(e,r(e)),day:e=>oe(e,r(e)),offset:e=>ae(e,r(e)),dayLine:e=>`${oe(e,r(e))} · ${ae(e,r(e))}`}}var le=null;function ue(t){let[n,r]=(0,F.useState)(()=>le);return(0,F.useEffect)(()=>{let t=!0;return c(()=>import(`./tz-DxphYhHy.js`).then(t=>e(t.default,1)).then(e=>{le=e.default,t&&r(()=>e.default)}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{}),()=>{t=!1}},[]),(0,F.useMemo)(()=>ce(t,n),[t,n])}var de=e=>`lb:columns:${e}`,fe={off:[]};function pe(e){return e.key===`ts`}function Q(e,t){return pe(e)||!t.off.includes(e.key)}function me(e,t){return e.filter(e=>Q(e,t))}function he(e){return e.filter(e=>!pe(e))}function ge(e,t){return pe(t)?e:{off:Q(t,e)?[...e.off,t.key]:e.off.filter(e=>e!==t.key)}}function _e(e,t){return{off:t?[]:he(e).map(e=>e.key)}}function ve(e,t){return xe(e.off)===xe(t.off)}function ye(e){try{let t=globalThis.localStorage?.getItem(de(e));if(!t)return fe;let n=JSON.parse(t);return{off:Array.isArray(n.off)?n.off.filter(e=>typeof e==`string`):[]}}catch{return fe}}function be(e,t){try{globalThis.localStorage?.setItem(de(e),JSON.stringify(t))}catch{}}function xe(e){return[...new Set(e)].sort().join(` `)}var $=n();function Se({cols:e,applied:t,onApply:n,onCancel:r}){let[i,a]=(0,F.useState)(t),o=ve(i,t),s=he(e),c=s.filter(e=>Q(e,i)).length;return(0,$.jsxs)(`div`,{className:`lb-pick`,children:[(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Columns`}),(0,$.jsxs)(`span`,{className:`lbp-s`,children:[c,` of `,s.length]}),(0,$.jsxs)(`span`,{className:`lbp-all`,children:[(0,$.jsx)(`button`,{onClick:()=>a(_e(e,!0)),children:`All`}),(0,$.jsx)(`button`,{onClick:()=>a(_e(e,!1)),children:`None`})]})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:s.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${Q(e,i)?` on`:``}`,"aria-pressed":Q(e,i),onClick:()=>a(ge(i,e)),children:e.head},e.key))})]}),(0,$.jsxs)(`div`,{className:`lbp-act`,children:[(0,$.jsx)(`button`,{onClick:r,children:`Cancel`}),(0,$.jsx)(`button`,{className:`lbp-go`,disabled:o,onClick:()=>n(i),children:`Show these columns`})]})]})}var Ce={"1m":1,"1h":60,"6h":360,"1d":1440},we={"1m":`Every minute`,"1h":`Hourly`,"6h":`Six-hourly`,"1d":`Daily`},Te={"1m":60,"1h":48,"6h":40,"1d":30},Ee=15e3;function De(e){let t=l(),[n,i]=(0,F.useState)(0),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)([]),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(e);m!==e&&(h(e),i(0),o(!1));let g=Ce[e],_=Te[e]+n*Te[e],v=(0,F.useCallback)(async()=>{p(!0),d(null);try{let e=_+1,n=g===1?(await t.logbook.minutes({limit:e,order:`desc`})).rows:await t.logbook.snapshots({bucket:g,limit:e,order:`desc`});o(n.length>_),c(n.slice(0,_))}catch(e){d(e.message)}finally{p(!1)}},[g,_]);return(0,F.useEffect)(()=>{v();let e=r(v,Ee);return()=>e()},[v]),{snaps:s,err:u,busy:f,hasMore:a,loadMore:(0,F.useCallback)(()=>i(e=>e+1),[])}}function Oe(){let e=l(),[t,n]=(0,F.useState)(w()),[i,a]=(0,F.useState)([]),[o,s]=(0,F.useState)(null),[c,u]=(0,F.useState)(!1),d=(0,F.useRef)(!0),f=S(6e4),p=w(new Date(f)),h=(0,F.useMemo)(()=>m(t),[t]),g=h+24*36e5,_=t===p;(0,F.useEffect)(()=>{d.current&&t!==p&&n(p)},[p,t]);let v=(0,F.useCallback)(e=>{d.current=e===w(),n(e)},[]),y=(0,F.useCallback)(async()=>{u(!0),s(null);try{let t=await e.logbook.snapshots({from:h,to:g,limit:5e3,order:`desc`,bucket:60});a(t)}catch(e){s(e.message)}finally{u(!1)}},[h,g]);return(0,F.useEffect)(()=>{if(y(),!_)return;let e=r(y,Ee);return()=>e()},[y,_]),{dateStr:t,setDateStr:v,dayStart:h,isToday:_,snaps:i,err:o,busy:c,prevDay:(0,F.useCallback)(()=>v(w(new Date(h-864e5))),[h,v]),nextDay:(0,F.useCallback)(()=>v(w(new Date(h+864e5))),[h,v]),goToday:(0,F.useCallback)(()=>v(w()),[v])}}var ke=5e3;async function Ae(e,t,n){let r=await e({from:t,to:n,limit:5001,order:`desc`});return{rows:r.rows.slice(0,ke),truncated:r.clamped||r.rows.length>5e3,minutesFrom:r.minutesFrom}}function je(e,t,n,r=`last`){let i=l(),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(!1),[h,g]=(0,F.useState)(!1),[_,v]=(0,F.useState)(null),[y,b]=(0,F.useState)([]),x=(0,F.useMemo)(()=>m(e),[e]),S=(0,F.useMemo)(()=>m(t)+864e5-1,[t]),C=Ce[n],w=(0,F.useCallback)(async()=>{if(Number.isNaN(x)||Number.isNaN(S)||S<x){o([]),b([]),p(!1),c(null),g(!0);return}g(!1),d(!0),c(null);try{if(b([]),C===1){let e=await Ae(e=>i.logbook.minutes(e),x,S);v(e.minutesFrom),p(e.truncated),o(e.rows);return}let e=await i.logbook.rollupHours(x,S);v(null);let t=P(e,n),a=t.map(e=>D(e,r)),s=e=>e.slice(Math.max(0,e.length-ke));p(a.length>ke),o(s(a)),r!==`last`&&b(s(t.map(e=>D(e,`last`))))}catch(e){c(e.message)}finally{d(!1),g(!0)}},[x,S,C,n,r]);return(0,F.useEffect)(()=>{w()},[w]),{snaps:a,err:s,busy:u,truncated:f,loaded:h,minutesFrom:_,plain:y}}var Me=[`1m`,`1h`,`6h`,`1d`],Ne=[{v:`csv`,name:`CSV`,note:`a file for a spreadsheet`},{v:`pdf`,name:`PDF`,note:`the page, through your printer`}],Pe=[{v:`screen`,name:`Screen`},{v:`paper`,name:`Paper`}],Fe=[`last`,`avg`,`min`,`max`];function Ie(e,t,n){return e===`pdf`?[n]:t.includes(n)?t.filter(e=>e!==n):[...t,n]}function Le(e,t){return e===`pdf`?[t[0]??`last`]:t}function Re(){return w(new Date(Date.now()-7*864e5))}function ze({initial:e,onView:t,onSave:n}){let[r,i]=(0,F.useState)(e?.from??Re()),[a,o]=(0,F.useState)(e?.to??w()),[s,c]=(0,F.useState)(e?.gran??`1h`),[l,u]=(0,F.useState)(e?.format??`csv`),[d,f]=(0,F.useState)(e?.stats??[`last`]),[p,m]=(0,F.useState)(e?.distance??!1),[h,g]=(0,F.useState)(e?.samples??!1),[_,v]=(0,F.useState)(e?.style??`screen`),y=a<r,b={from:r,to:a,gran:s,format:l,stats:Le(l,d),distance:p,samples:h,style:_},x=s!==`1m`,S=l===`pdf`,C=x&&!S&&d.length===0&&!p&&!h,T=e=>f(t=>Ie(l,t,e)),E=Le(l,d),D=e=>E.includes(e);return(0,$.jsxs)(`div`,{className:`lb-pick lb-exp`,children:[(0,$.jsxs)(`div`,{className:`lbp-books`,children:[(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Window`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:`UTC days, both ends included`})]}),(0,$.jsxs)(`div`,{className:`lbe-dates`,children:[(0,$.jsxs)(`label`,{children:[(0,$.jsx)(`span`,{children:`From`}),(0,$.jsx)(`input`,{type:`date`,className:`dt`,value:r,max:w(),onChange:e=>i(e.target.value)})]}),(0,$.jsxs)(`label`,{children:[(0,$.jsx)(`span`,{children:`To`}),(0,$.jsx)(`input`,{type:`date`,className:`dt`,value:a,max:w(),onChange:e=>o(e.target.value)})]})]})]}),(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Interval`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:`one row per`})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:Me.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${s===e?` on`:``}`,onClick:()=>c(e),children:we[e]},e))})]}),(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Save as`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:Ne.find(e=>e.v===l)?.note})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:Ne.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${l===e.v?` on`:``}`,onClick:()=>u(e.v),children:e.name},e.v))})]}),(0,$.jsxs)(`div`,{className:`lbp-book${S?``:` off`}`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Style`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:S?_===`screen`?`the app's own dark ink`:`white, for a printer`:`the page's ink; a file carries none`})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:Pe.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${_===e.v?` on`:``}`,disabled:!S,onClick:()=>v(e.v),children:e.name},e.v))})]})]}),x&&(0,$.jsxs)(`div`,{className:`lbp-book lbp-figs`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Figures`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:S?`one: a table cell holds one number`:`one or more: a column each`})]}),(0,$.jsxs)(`div`,{className:`lbp-chips`,children:[Fe.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${D(e)?` on`:``}`,onClick:()=>T(e),children:k[e]},e)),(0,$.jsx)(`button`,{className:`lbp-c${p?` on`:``}`,disabled:S,onClick:()=>m(!p),children:`Distance`}),(0,$.jsx)(`button`,{className:`lbp-c${h?` on`:``}`,disabled:S,onClick:()=>g(!h),children:`Samples`})]})]}),y&&(0,$.jsx)(`div`,{className:`lbe-warn`,children:`That window ends before it begins.`}),C&&(0,$.jsx)(`div`,{className:`lbe-warn`,children:`Choose at least one figure to put in the file.`}),(0,$.jsxs)(`div`,{className:`lbp-act`,children:[S&&(0,$.jsx)(`button`,{disabled:y,onClick:()=>t(b),children:`View`}),(0,$.jsxs)(`button`,{className:`lbp-go`,disabled:y||C,onClick:()=>n(b),children:[`Save `,l.toUpperCase()]})]})]})}function Be({open:e,style:t,cls:n,children:r}){let[i,a]=(0,F.useState)(e);return e&&!i&&a(!0),i?(0,$.jsx)(`div`,{className:`lb-open${e?``:` shut`}${n??``}`,style:t,onAnimationEnd:t=>{t.target===t.currentTarget&&!e&&a(!1)},children:(0,$.jsx)(`div`,{className:`lb-open-in`,children:r})}):null}function Ve(e){let t=e-32-58;return Math.max(1,Math.floor(t/52))}function He(e){return e.reduce((e,t)=>e+(t.lanes??1),0)}function Ue(e,t){if(t===null||e.length===0)return e;let n=Ve(t),r=e.slice(0,1);for(let t of e.slice(1)){let e=t.lanes??1;if(e>n)break;n-=e,r.push(t)}return r}function We(e,t,n){return t===null?e:e.slice(0,Ve(t-(n?108:0)))}var Ge=180,Ke=[`1m`,`1h`,`6h`,`1d`],qe={"1m":`Last hour`,"1h":`Last 2 days`,"6h":`Last 10 days`,"1d":`Last month`};function Je({book:e}){let t=l(),[n,r]=(0,F.useState)(`live`),[i,a]=(0,F.useState)(`1h`),[o,s]=(0,F.useState)(null),[c,u]=ne((0,F.useMemo)(()=>({book:e,mode:n,gran:i,family:o}),[e,n,i,o]),Ge),{book:d,mode:f,gran:p,family:h}=c,g=n!==f,[v,y]=(0,F.useState)(()=>localStorage.getItem(`lb:windUnit`)||`kn`),b=()=>y(e=>{let t=e===`kn`?`bft`:`kn`;return localStorage.setItem(`lb:windUnit`,t),t}),x=(0,F.useRef)([]),S=(0,F.useRef)(0),[C,w]=(0,F.useState)(()=>ye(d)),[T,E]=(0,F.useState)(d);T!==d&&(E(d),w(ye(d)),x.current=[],S.current=0);let[O,k]=(0,F.useState)(!1),I=e=>{w(e),be(d,e),k(!1)},[L,R]=_(),z=(0,F.useRef)(null),B=(0,F.useRef)(null),V=(0,F.useCallback)(e=>{B.current=e,L(e)},[L]),H=(0,F.useRef)(null);(0,F.useLayoutEffect)(()=>{let e=B.current;if(!e)return;let t=()=>e.querySelectorAll(`.lb-ctrl, .lb-pick, .lb-frame`);if(u){let e=new Map;t().forEach(t=>e.set(t,t.getBoundingClientRect().width)),H.current=e;return}let n=H.current;if(H.current=null,!n||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let r=parseFloat(getComputedStyle(e).getPropertyValue(`--lb-fade-in`))||0;t().forEach(e=>{let t=n.get(e);if(t===void 0||typeof e.animate!=`function`)return;let i=e.getBoundingClientRect().width;Math.abs(i-t)<1||e.animate([{maxWidth:`${t}px`},{maxWidth:`${i}px`}],{duration:r,easing:`cubic-bezier(0.32, 0.72, 0, 1)`})})},[u,c]);let[U,ee]=(0,F.useState)(!1),[K,te]=(0,F.useState)(null),[q,J]=(0,F.useState)(!1),[re,Y]=(0,F.useState)(null),[X,Z]=(0,F.useState)(null),ie={book:d,mode:n,setMode:r,gran:i,setGran:a,shownGran:p,family:o,setFamily:s,shownFamily:h,leaving:u,modeLeaving:g,lanesHold:z,groupsHold:x,chosenHold:S,windUnit:v,toggleWind:b,selection:C,picking:O,setPicking:k,applySelection:I,width:R,exporting:U,setExporting:ee,request:K,onView:e=>{te(e),r(`range`),Y(null)},onSave:async e=>{if(ee(!1),Y(null),Z(null),e.format===`pdf`){te(e),r(`range`),J(!0);return}try{let n=m(e.from),r=m(e.to)+864e5-1;if(e.gran===`1m`){let{rows:e,truncated:i}=await Ae(e=>t.logbook.minutes(e),n,r),a=me(G(W(e,v),d),C);A(M(`logbook-${d}`,n,`csv`,i?`-partial`:``),`text/csv`,j(e,a)),i&&Z(`That window holds more than ${ke} minutes, so the file stops at the most recent ${ke} and its name ends in -partial. A longer interval covers the same days in fewer rows.`);return}let i=P(await t.logbook.rollupHours(n,r),e.gran),a=e.stats.map(e=>({stat:e,cols:me(G(W(i.map(t=>D(t,e)),v),d),C)})).filter(e=>e.cols.length>1);A(M(`logbook-${d}`,n,`csv`),`text/csv`,N(i,a,{distance:e.distance,samples:e.samples}))}catch(e){Y(e.message)}},saveErr:re,saveNote:X};return(0,$.jsxs)(`div`,{className:`lb`,ref:V,children:[(0,$.jsx)(`style`,{children:`@media print { @page { size: A4 landscape; } }`}),f===`live`?(0,$.jsx)(_t,{...ie}):f===`day`?(0,$.jsx)(vt,{...ie}):(0,$.jsx)(wt,{...ie,req:K,printing:q,donePrinting:()=>J(!1)})]})}function Ye({mode:e,setMode:t}){return(0,$.jsxs)(`div`,{className:`seg`,children:[(0,$.jsx)(`button`,{className:e===`live`?`on`:``,onClick:()=>t(`live`),children:`Live`}),(0,$.jsx)(`button`,{className:e===`day`?`on`:``,onClick:()=>t(`day`),children:`Day`})]})}function Xe({leaving:e,children:t}){return(0,$.jsx)(`div`,{className:`lb-win${e?` leaving`:``}`,children:t})}function Ze({groups:e,family:t,setFamily:n}){if(e.length<2)return null;let r=e.find(e=>e.tab===t)??e[0];return(0,$.jsx)(`div`,{className:`seg`,children:e.map(e=>(0,$.jsx)(`button`,{className:e.tab===r.tab?`on`:``,onClick:()=>n(e.tab),children:e.head},e.tab))})}function Qe(e,t,n){if(e===null||m(t.from)>=e)return null;let r=new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`}),i=n[n.length-1];return`Minutes reach back to ${r}.${i!==void 0&&i.ts<e?` Earlier days in this window read one row per hour.`:``}`}function $e(e,t,n){let r=k[e].toLowerCase(),i=t.length===1?t[0]:`${t.slice(0,-1).join(`, `)} and ${t[t.length-1]}`,a=n.some(e=>e.lat!==null&&e.lon!==null),o=t.length===1;return`${i} ${o?`has`:`have`} no ${r}, so on each row ${o?`it carries`:`they carry`} the reading that window closed on${a?`, as the position does`:``}.`}function et(e,t){if(t.length===0)return e;let n=new Map(t.map(e=>[e.ts,e]));return e.map(e=>{let t=n.get(e.ts);if(!t)return e;let r={...e};for(let[e,n]of Object.entries(t))e!==`path_values`&&(r[e]===null||r[e]===void 0)&&n!=null&&(r[e]=n);if(t.path_values){let n={...e.path_values??{}};for(let[e,r]of Object.entries(t.path_values))(n[e]===void 0||n[e]===null)&&(n[e]=r);r.path_values=n}return r})}function tt(e){return m(e.to)+864e5-1>=Date.now()&&e.gran!==`1m`?`No row has closed at this interval yet. A shorter interval shows today's.`:`Nothing was logged between these dates.`}function nt(e,t,n){return e.length>1||t===null?lt(e):{"--lb-cols":n.current??Ve(t)}}function rt({what:e}){return(0,$.jsxs)(`div`,{className:`sp-empty`,children:[(0,$.jsx)(`div`,{className:`em-t`,children:`No snapshots`}),(0,$.jsx)(`div`,{className:`em-s`,children:e})]})}var it=(e,t)=>`u:${e}:${t}`;function at(e,t,n,r,i,a,o,s,c,l=!0){let u=st(e,t,n,r,i,a,o,s,c,l);if(t!==`engine`||u.groups.length<2)return u;let d=u,f=ot(u);for(let o of u.groups){if(o===u.group||o.tab===a)continue;let s=st(e,t,n,r,i,o.tab,{current:null},{current:[]},{current:0},l),c=ot(s);c>f&&(d=s,f=c)}return d===u?u:{...u,block:d.block,cls:d.cls}}function ot(e){let t=Math.max(1,Number(e.block[`--lb-cols`]??1));return 58+(e.cls.includes(`u`)?108:0)+t*164}function st(e,t,n,r,i,a,o,s,c,l){let u=t===`engine`?K(e):[];u.length>0&&(s.current=u);let d=u.length===0&&e.length===0?s.current:u,f=u.find(e=>e.tab===a)??u[0];if(f&&f.units.length>1){let e=f.metrics.map(e=>({key:it(f.tab,e.key),head:e.head})),t=f.metrics.filter(e=>Q({key:it(f.tab,e.key)},r)),n=l?We(t,i,!0):t,a={...f,metrics:n};return o.current=Math.max(1,n.length),t.length>0&&(c.current=t.length),{groups:d,group:a,drawn:[],pick:e,btn:{shown:n.length,chosen:t.length,kept:c.current,offered:e.length},block:{"--lb-cols":Math.max(1,n.length)},cls:` u`}}let p=G(W(e,n),t),m=f?p.filter(e=>e.key===`ts`||e.tab===f.tab):p,h=me(m,r),g=l?Ue(h,i):h;return g.length>1&&(o.current=He(g.slice(1))),h.length>1&&(c.current=h.length-1),{groups:d,group:null,drawn:g,pick:m,btn:{shown:g.length-1,chosen:h.length-1,kept:c.current,offered:m.length-1},block:nt(g,i,o),cls:``}}function ct(e){return{"--lb-cols":Math.max(1,e.metrics.length)}}function lt(e){return{"--lb-cols":He(e.slice(1))}}function ut(e){return(e.lanes??1)>1?` w${e.lanes}`:``}function dt(e,t){return t===`last`?we[e]:`${we[e]} · ${k[t]}`}function ft(e,t,n,r){return r===0?String(n):e<t?`${e} of ${t}`:String(t)}function pt({shown:e,chosen:t,kept:n,offered:r,open:i,onOpen:a}){let o=r===0;return(0,$.jsxs)(`button`,{className:`lb-colbtn${i?` on`:``}${o?` quiet`:``}`,onClick:a,disabled:o,children:[`Columns · `,(0,$.jsx)(`b`,{children:ft(e,t,n,r)})]})}function mt({open:e,onOpen:t}){return(0,$.jsx)(`button`,{className:`lb-colbtn${e?` on`:``}`,onClick:t,children:`View`})}function ht({cols:e,group:t,times:n,toggleWind:r}){if(t){let e=t.units.length>1;return(0,$.jsxs)(`div`,{className:`lb-cols${e?` u`:``}`,style:ct(t),children:[(0,$.jsx)(`span`,{children:n.head}),e&&(0,$.jsx)(`span`,{className:`un`,children:`Unit`}),t.metrics.map(e=>(0,$.jsxs)(`span`,{children:[e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key))]})}return(0,$.jsx)(`div`,{className:`lb-cols`,style:lt(e),children:e.map(e=>e.tappable?(0,$.jsxs)(`span`,{className:`tap${ut(e)}`,onClick:r,title:`Tap: knots ⇄ Beaufort`,children:[e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key):(0,$.jsxs)(`span`,{className:ut(e).trim(),children:[e.key===`ts`?n.head:e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key))})}function gt({of:e}){return(0,$.jsx)(`b`,{className:`lb-u`,children:e===void 0||e===``?`\xA0`:e})}function _t({book:e,mode:t,setMode:n,gran:r,setGran:i,shownGran:a,family:o,setFamily:s,shownFamily:c,leaving:l,modeLeaving:u,lanesHold:d,groupsHold:f,chosenHold:p,windUnit:m,toggleWind:h,selection:g,picking:_,setPicking:v,applySelection:y,width:b,exporting:x,setExporting:S,request:C,onView:w,onSave:T,saveErr:E,saveNote:D}){let{snaps:O,err:k,busy:A,hasMore:j,loadMore:M}=De(a),N=ue(O),P=(0,F.useMemo)(()=>Tt(O,N,!1),[O,N]),{groups:I,group:L,drawn:R,pick:z,btn:B,block:V,cls:H}=at(O,e,m,g,b,c,d,f,p);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`lb-ctrl${H}`,style:V,children:[(0,$.jsx)(Ye,{mode:t,setMode:n}),(0,$.jsx)(Xe,{leaving:u,children:(0,$.jsx)(`div`,{className:`seg`,children:Ke.map(e=>(0,$.jsx)(`button`,{className:r===e?`on`:``,onClick:()=>i(e),children:e},e))})}),(0,$.jsx)(Ze,{groups:I,family:o,setFamily:s}),(0,$.jsxs)(`div`,{className:`lb-acts`,children:[(0,$.jsx)(pt,{shown:B.shown,chosen:B.chosen,kept:B.kept,offered:B.offered,open:_,onOpen:()=>v(!_)}),(0,$.jsx)(mt,{open:x,onOpen:()=>S(!x)})]})]}),(0,$.jsx)(Be,{open:_,style:V,cls:H,children:(0,$.jsx)(Se,{cols:z,applied:g,onApply:y,onCancel:()=>v(!1)})}),(0,$.jsx)(Be,{open:x,style:V,cls:H,children:(0,$.jsx)(ze,{initial:C??void 0,onView:w,onSave:T})}),E&&(0,$.jsx)(`div`,{className:`lb-err`,children:E}),D&&(0,$.jsx)(`div`,{className:`lb-note`,children:D}),(0,$.jsxs)(`div`,{className:`lb-frame${P?` dated`:``}${N.mixed?` mixed`:``}${H}${l?` leaving`:``}`,style:V,children:[(0,$.jsx)(xt,{book:e,window:qe[a],interval:we[a],times:N}),(0,$.jsxs)(`div`,{className:`lb-day`,style:lt(R),children:[(0,$.jsx)(`span`,{children:qe[a]}),(0,$.jsx)(`b`,{children:O.length})]}),(0,$.jsx)(ht,{cols:R,group:L,times:N,toggleWind:h}),k&&(0,$.jsx)(`div`,{className:`lb-err`,children:k}),!A&&!k&&O.length===0?(0,$.jsx)(rt,{what:`Nothing was logged in this window (${qe[a].toLowerCase()}).`}):(0,$.jsx)(Et,{snaps:O,cols:R,group:L,times:N,lined:P,footer:j?(0,$.jsx)(`button`,{className:`lb-more`,onClick:M,disabled:A,children:A?`Loading…`:`Load ${Te[a]} more`}):null}),(0,$.jsx)(St,{})]})]})}function vt({book:e,mode:t,setMode:n,family:r,setFamily:i,shownFamily:a,leaving:o,modeLeaving:s,lanesHold:c,groupsHold:l,chosenHold:u,windUnit:d,toggleWind:f,selection:p,picking:m,setPicking:h,applySelection:g,width:_,exporting:v,setExporting:y,request:b,onView:x,onSave:S,saveErr:C,saveNote:T}){let{dateStr:E,setDateStr:D,isToday:O,snaps:k,err:A,busy:j,prevDay:M,nextDay:N,goToday:P}=Oe(),I=ue(k),L=(0,F.useMemo)(()=>Tt(k,I,`turns`),[k,I]),{groups:R,group:z,drawn:B,pick:V,btn:H,block:U,cls:W}=at(k,e,d,p,_,a,c,l,u),G=`${O?`Today · ${new Date(E).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,timeZone:`UTC`})}`:new Date(E).toLocaleDateString(`en-GB`,{weekday:`short`,day:`2-digit`,month:`short`,timeZone:`UTC`}).replace(/,/g,``)} · UTC day`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`lb-ctrl${W}`,style:U,children:[(0,$.jsx)(Ye,{mode:t,setMode:n}),(0,$.jsx)(Xe,{leaving:s,children:(0,$.jsxs)(`div`,{className:`lb-date`,children:[(0,$.jsx)(`button`,{className:`lb-step`,onClick:M,"aria-label":`Previous day`,children:`‹`}),(0,$.jsx)(`input`,{type:`date`,className:`dt`,value:E,max:w(),onChange:e=>D(e.target.value)}),(0,$.jsx)(`button`,{className:`lb-step`,onClick:N,disabled:O,"aria-label":`Next day`,children:`›`}),(0,$.jsx)(`button`,{onClick:P,disabled:O,children:`Now`})]})}),(0,$.jsx)(Ze,{groups:R,family:r,setFamily:i}),(0,$.jsxs)(`div`,{className:`lb-acts`,children:[(0,$.jsx)(pt,{shown:H.shown,chosen:H.chosen,kept:H.kept,offered:H.offered,open:m,onOpen:()=>h(!m)}),(0,$.jsx)(mt,{open:v,onOpen:()=>y(!v)})]})]}),(0,$.jsx)(Be,{open:m,style:U,cls:W,children:(0,$.jsx)(Se,{cols:V,applied:p,onApply:g,onCancel:()=>h(!1)})}),(0,$.jsx)(Be,{open:v,style:U,cls:W,children:(0,$.jsx)(ze,{initial:b??void 0,onView:x,onSave:S})}),C&&(0,$.jsx)(`div`,{className:`lb-err`,children:C}),T&&(0,$.jsx)(`div`,{className:`lb-note`,children:T}),(0,$.jsxs)(`div`,{className:`lb-frame${L?` dated`:``}${I.mixed?` mixed`:``}${W}${o?` leaving`:``}`,style:U,children:[(0,$.jsx)(xt,{book:e,window:G,interval:we[`1h`],times:I}),(0,$.jsxs)(`div`,{className:`lb-day`,style:lt(B),children:[(0,$.jsx)(`span`,{children:G}),(0,$.jsx)(`b`,{children:k.length})]}),(0,$.jsx)(ht,{cols:B,group:z,times:I,toggleWind:f}),A&&(0,$.jsx)(`div`,{className:`lb-err`,children:A}),!j&&k.length===0?(0,$.jsx)(rt,{what:`No telemetry was logged for this day.`}):(0,$.jsx)(Et,{snaps:k,cols:B,group:z,times:I,footer:null,lined:L}),(0,$.jsx)(St,{})]})]})}function yt(){let e=new Date,t=e.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`,timeZone:`UTC`}),n=e=>String(e).padStart(2,`0`);return`${t.toUpperCase()} · ${n(e.getUTCHours())}:${n(e.getUTCMinutes())} UTC`}var bt={bridge:`CHIEF OFFICER`,engine:`CHIEF ENGINEER`};function xt({book:e,window:t,interval:n,times:r}){let i=r.mixed?`SHIP'S TIME · OFFSET ON EACH DATED LINE`:r.head===`UTC`?`UTC`:`SHIP'S TIME · ${r.head}`;return(0,$.jsxs)(`div`,{className:`lb-print-hd`,children:[(0,$.jsxs)(`div`,{className:`ph-id`,children:[(0,$.jsxs)(`span`,{className:`sp-lockup`,children:[(0,$.jsx)(C,{className:`sp-glyph`}),(0,$.jsx)(`span`,{className:`ph-wm`,children:`Siparu`})]}),(0,$.jsxs)(`span`,{className:`ph-book`,children:[`LOGBOOK · `,(0,$.jsx)(`b`,{children:e.toUpperCase()}),` · `,bt[e]]})]}),(0,$.jsxs)(`div`,{className:`ph-meta`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`l`,children:`GENERATED`}),(0,$.jsx)(`b`,{children:yt()})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`l`,children:`WINDOW`}),(0,$.jsx)(`b`,{children:`${t} · ${n}`.toUpperCase()})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`l`,children:`CLOCK`}),(0,$.jsx)(`b`,{children:i})]})]})]})}function St(){return(0,$.jsx)(`div`,{className:`lb-print-ft`,children:(0,$.jsx)(`span`,{children:`siparu.app`})})}function Ct(e,t){let n=(e,t)=>new Date(e).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,...t?{year:`numeric`}:{},timeZone:`UTC`});return e===t?`${n(t,!0)} · UTC day`:`${n(e,!1)} - ${n(t,!0)} · UTC days`}function wt({book:e,req:t,setMode:n,family:r,setFamily:i,shownFamily:a,leaving:o,modeLeaving:s,lanesHold:c,groupsHold:l,chosenHold:u,windUnit:d,toggleWind:f,selection:p,picking:m,setPicking:h,applySelection:g,width:_,exporting:v,setExporting:y,request:b,onView:x,onSave:S,saveErr:C,saveNote:T,printing:D,donePrinting:k}){let A={from:w(),to:w(),gran:`1h`,format:`csv`,stats:[`last`],distance:!1,samples:!1,style:`screen`},j=t??A,M=j.stats[0]??`last`,{snaps:N,err:P,busy:I,truncated:L,loaded:R,minutesFrom:z,plain:B}=je(j.from,j.to,j.gran,M),V=(0,F.useMemo)(()=>et([...N].sort((e,t)=>e.ts-t.ts),B),[N,B]),H=ue(V),{groups:U,group:ee,drawn:K,pick:te,btn:ne,block:q,cls:J}=at(V,e,d,p,_,a,c,l,u,!1),re=(0,F.useCallback)(()=>k(),[k]);(0,F.useEffect)(()=>{!D||!R||I||(re(),O(E(`Siparu-Logbook`,Date.now()),j.style))},[D,R,I,re,j.style]);let Y=Ct(j.from,j.to),X=dt(j.gran,M),Z=(0,F.useMemo)(()=>{if(B.length===0)return[];let t=t=>me(G(W(t,d),e),p).map(e=>e.head),n=new Set(t(N));return t(B).filter(e=>!n.has(e))},[B,N,d,e,p]);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`lb-ctrl${J}`,style:q,children:[(0,$.jsx)(Ye,{mode:`range`,setMode:n}),(0,$.jsx)(Xe,{leaving:s,children:(0,$.jsxs)(`button`,{className:`lb-colbtn on`,onClick:()=>y(!v),children:[Y,` · `,(0,$.jsx)(`b`,{children:X})]})}),(0,$.jsx)(Ze,{groups:U,family:r,setFamily:i}),(0,$.jsx)(`div`,{className:`lb-acts`,children:(0,$.jsx)(pt,{shown:ne.shown,chosen:ne.chosen,kept:ne.kept,offered:ne.offered,open:m,onOpen:()=>h(!m)})})]}),(0,$.jsx)(Be,{open:m,style:q,cls:J,children:(0,$.jsx)(Se,{cols:te,applied:p,onApply:g,onCancel:()=>h(!1)})}),(0,$.jsx)(Be,{open:v,style:q,cls:J,children:(0,$.jsx)(ze,{initial:b??void 0,onView:x,onSave:S})}),C&&(0,$.jsx)(`div`,{className:`lb-err`,children:C}),T&&(0,$.jsx)(`div`,{className:`lb-note`,children:T}),(0,$.jsxs)(`div`,{className:`lb-frame dated${H.mixed?` mixed`:``}${J}${o?` leaving`:``}`,style:q,children:[(0,$.jsx)(xt,{book:e,window:Y,interval:X,times:H}),(0,$.jsxs)(`div`,{className:`lb-day`,style:lt(K),children:[(0,$.jsxs)(`span`,{children:[Y,` · `,X]}),(0,$.jsx)(`b`,{children:L?`${N.length} of more`:N.length})]}),(0,$.jsx)(ht,{cols:K,group:ee,times:H,toggleWind:f}),P&&(0,$.jsx)(`div`,{className:`lb-err`,children:P}),Z.length>0&&(0,$.jsx)(`div`,{className:`lb-note`,children:$e(M,Z,N)}),L&&(0,$.jsxs)(`div`,{className:`lb-note`,children:[`This window holds more than `,5e3,` rows. The most recent `,5e3,` are here; a longer interval covers the same days in fewer.`]}),Qe(z,j,N)&&(0,$.jsx)(`div`,{className:`lb-note`,children:Qe(z,j,N)}),!I&&V.length===0?(0,$.jsx)(rt,{what:tt(j)}):(0,$.jsx)(Et,{snaps:V,cols:K,group:ee,times:H,footer:null,lined:!0}),(0,$.jsx)(St,{})]})]})}function Tt(e,t,n){return n===!0?!0:n===!1&&!t.mixed?!1:new Set(e.map(e=>t.dayLine(e.ts))).size>1}function Et({snaps:e,cols:t,group:n,times:r,footer:i,lined:a}){let o=[],s=null;for(let i of e){if(a){let e=r.dayLine(i.ts);e!==s&&(o.push((0,$.jsx)(Dt,{day:r.day(i.ts),offset:r.offset(i.ts),cols:t,group:n},`sep-${i.ts}`)),s=e)}o.push(n?(0,$.jsx)(Ot,{s:i,group:n,times:r},i.ts):(0,$.jsx)(kt,{s:i,cols:t,times:r},i.ts))}return(0,$.jsxs)(`div`,{className:`lb-rows`,style:n?ct(n):lt(t),children:[o,i]})}function Dt({day:e,offset:t,cols:n,group:r}){let i=r!==null&&r.units.length>1,a=r?r.metrics.map(e=>({key:e.key,head:e.head,unit:e.unit,cls:``})):n.slice(1).map(e=>({key:e.key,head:e.head,unit:e.unit,cls:ut(e).trim()}));return(0,$.jsxs)(`div`,{className:`lb-sep${i?` u`:``}`,children:[(0,$.jsxs)(`span`,{className:`sd`,children:[e,t&&(0,$.jsxs)(`span`,{className:`so`,children:[` · `,t]})]}),i&&(0,$.jsx)(`span`,{className:`sh`}),a.map(e=>(0,$.jsxs)(`span`,{className:e.cls?`sh ${e.cls}`:`sh`,children:[e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key))]})}function Ot({s:e,group:t,times:n}){let r=t.units.length>1;return(0,$.jsx)($.Fragment,{children:t.units.map((i,a)=>(0,$.jsxs)(`div`,{className:`lb-row${r?` u`:``}${a>0?` cont`:``}`,children:[(0,$.jsx)(`span`,{className:`tm`,children:n.clock(e.ts)}),r&&(0,$.jsx)(`span`,{className:`un`,children:i.head}),t.metrics.map(t=>(0,$.jsx)(`span`,{className:`v`,children:te(e,i,t)},t.key))]},i.key))})}function kt({s:e,cols:t,times:n}){return(0,$.jsx)(`div`,{className:`lb-row`,children:t.map((t,r)=>(0,$.jsx)(`span`,{className:r===0?`tm`:`${t.dim?`v dim`:`v`}${ut(t)}`,children:t.key===`ts`?n.clock(e.ts):t.cell(e)},t.key))})}var At=[{to:`/logbook/bridge`,name:`Bridge`,keeper:`Chief officer`,holds:`Position, course and speed, the weather she ran in and the water under her.`,Icon:g},{to:`/logbook/engine`,name:`Engine`,keeper:`Chief engineer`,holds:`Engines, generators and tanks, as she reported them.`,Icon:b}];function jt(){let e=v();return(0,$.jsx)(`div`,{className:`lb-door`,children:(0,$.jsx)(`div`,{className:`lbd-cards`,children:At.map(({to:t,name:n,keeper:r,holds:i,Icon:a})=>(0,$.jsxs)(d,{to:e(t),replace:!0,className:`lbd-card`,children:[(0,$.jsx)(a,{size:42}),(0,$.jsx)(`span`,{className:`lbd-n`,children:n}),(0,$.jsx)(`span`,{className:`lbd-k`,children:r}),(0,$.jsx)(`span`,{className:`lbd-h`,children:i}),(0,$.jsxs)(`span`,{className:`lbd-go`,children:[`Open `,(0,$.jsx)(x,{size:15})]})]},t))})})}function Mt({book:e}){return e?(0,$.jsx)(Je,{book:e}):(0,$.jsx)(jt,{})}export{Mt as default};
2
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{t as r}from"./visibleInterval-CFxPzgzx.js";import{A as i,C as a,D as o,E as s,F as c,N as l,O as u,P as d,S as f,T as p,_ as m,b as h,c as g,d as _,g as v,k as y,l as b,o as x,p as S,s as C,v as w,w as T}from"./index-BeY0LLy7.js";import{a as E,d as D,i as O,l as k,n as A,o as j,r as M,t as N,u as P}from"./export-CGdOfqNp.js";var F=e(t(),1),I={key:`ts`,head:`UTC`,book:`bridge`,cell:()=>``};function L(e,t,n,r){if(e===null)return`·`;let i=Math.abs(e),a=Math.floor(i),o=(i-a)*60;return`${String(a).padStart(t,`0`)}°${o.toFixed(3).padStart(6,`0`)}' ${e<0?r:n}`}function R(e){return[{col:{key:`lat`,head:`LAT`,book:`bridge`,lanes:2,cell:e=>L(e.lat,2,`N`,`S`)},has:e=>e.lat!==null},{col:{key:`lon`,head:`LON`,book:`bridge`,lanes:2,cell:e=>L(e.lon,3,`E`,`W`)},has:e=>e.lon!==null},{col:{key:`sog`,head:`SOG`,book:`bridge`,unit:`kn`,cell:e=>h(o(e.sog),1)},has:e=>e.sog!==null},{col:{key:`cog`,head:`COG`,book:`bridge`,cell:e=>{let t=s(e.cog);return t===null?`·`:Math.round(t)+`°`}},has:e=>e.cog!==null},{col:{key:`hdg`,head:`HDG`,book:`bridge`,cell:e=>{let t=s(e.heading_true??e.heading_mag);return t===null?`·`:Math.round(t)+`°`}},has:e=>(e.heading_true??e.heading_mag)!==null},{col:{key:`wind`,head:e===`kn`?`TWS`:`BFT`,book:`bridge`,unit:e===`kn`?`kn`:void 0,tappable:!0,cell:t=>{let n=T(t.wind_speed_true);return n===null?`·`:String(e===`kn`?Math.round(n):a(n)??`·`)}},has:e=>e.wind_speed_true!==null},{col:{key:`awa`,head:`AWA`,book:`bridge`,cell:e=>{let t=s(e.wind_angle_apparent);if(t===null)return`·`;let n=(t+180)%360-180;return`${Math.abs(Math.round(n))}°${n<0?`P`:`S`}`}},has:e=>e.wind_angle_apparent!==null},{col:{key:`baro`,head:`BARO`,book:`bridge`,unit:`hPa`,dim:!0,cell:e=>{let t=p(e.air_pressure_pa);return t===null?`·`:String(Math.round(t))}},has:e=>e.air_pressure_pa!==null},{col:{key:`air`,head:`AIR`,book:`bridge`,unit:`°C`,cell:e=>h(f(e.air_temp_k),1)},has:e=>e.air_temp_k!==null},{col:{key:`sea`,head:`SEA`,book:`bridge`,unit:`°C`,cell:e=>h(f(e.water_temp_k),1)},has:e=>e.water_temp_k!==null},{col:{key:`depth`,head:`DEP`,book:`bridge`,unit:`m`,cell:e=>e.depth===null?`·`:e.depth.toFixed(1)},has:e=>e.depth!==null}]}var z={Revolutions:`RPM`,Temperature:`TEMP`,"Oil pressure":`OIL`,"Oil temperature":`OILT`,"Coolant temperature":`COOL`,"Coolant pressure":`COOLP`,"Exhaust temperature":`EXH`,"Intake manifold temperature":`INTK`,"Boost pressure":`BOOST`,"Engine load":`LOAD`,"Engine torque":`TORQ`,"Run time":`HRS`,"Fuel rate":`FUEL`,"Fuel per mile":`L/NM`,"Fuel used (since reset)":`USED`,"Fuel pressure":`FUELP`,"Alternator voltage":`ALT`,"Gearbox oil temperature":`GBOXT`,"Gearbox oil pressure":`GBOXP`,"Current level":`LEVEL`,Voltage:`VOLT`,Current:`AMP`};function B(e){return z[e]??e.split(` `)[0].toUpperCase()}function V(e){return e.sub===null?e.tab===`tanks`?`Current level`:null:e.sub}function H(e){let t=/^(Engine|Generator|Fuel|Fresh water|Black water|Grey water|Lubrication)\s+(\S+)$/.exec(e);return t?`${t[1].split(` `).map(e=>e[0]).join(``)}${t[2]}`.toUpperCase():e.slice(0,1).toUpperCase()}function U(e){let t=[];for(let n of e)for(let e of Object.keys(n.path_values??{}))t.includes(e)||t.push(e);let n=[];for(let e of t){let t=u(e);if(!t)continue;let r=V(t);r!==null&&n.push({path:e,d:{...t,sub:r}})}let r=new Map;for(let{d:e}of n)r.has(e.tab)||r.set(e.tab,new Set),r.get(e.tab).add(e.label);let a=[];for(let{path:e,d:t}of n){let n=B(t.sub);a.push({col:{key:`p:${e}`,head:r.get(t.tab).size>1?`${H(t.label)} ${n}`:n,book:`engine`,tab:t.tab,unit:i(e),cell:t=>{let n=t.path_values?.[e];if(typeof n!=`number`)return`·`;let r=y(e,n).value;return Number.isFinite(r)?Number.isInteger(r)?String(r):r.toFixed(1):`·`}},has:t=>typeof t.path_values?.[e]==`number`})}return a}function W(e,t){return[I,...[...R(t),...U(e)].filter(t=>e.some(t.has)).map(e=>e.col)]}function G(e,t){return e.filter(e=>e.key===`ts`||e.book===t)}var ee={engine:`ENGINES`,generator:`GENERATORS`,tanks:`TANKS`};function K(e){let t=[],n=new Map,r=new Map;for(let i of e)for(let e of Object.keys(i.path_values??{})){let i=u(e);if(!i)continue;let a=V(i);if(a===null)continue;n.has(i.tab)||(t.push(i.tab),n.set(i.tab,new Map),r.set(i.tab,[]));let o=n.get(i.tab);o.has(i.label)||o.set(i.label,new Map),o.get(i.label).set(a,e);let s=r.get(i.tab);s.includes(a)||s.push(a)}return t.map(e=>{let t=[...n.get(e)].map(([e,t])=>({key:e,head:e.toUpperCase(),paths:Object.fromEntries(t)})),a=r.get(e).map(e=>{let n=t.map(t=>t.paths[e]).find(e=>e!==void 0);return{key:e,head:B(e),unit:n===void 0?``:i(n)}});return{tab:e,head:ee[e]??e.toUpperCase(),units:t,metrics:a}})}function te(e,t,n){let r=t.paths[n.key];if(r===void 0)return`·`;let i=e.path_values?.[r];if(typeof i!=`number`)return`·`;let a=y(r,i).value;return Number.isFinite(a)?Number.isInteger(a)?String(a):a.toFixed(1):`·`}function ne(e,t){let[n,r]=(0,F.useState)(e),[i,a]=(0,F.useState)(!1);return(0,F.useEffect)(()=>{if(e===n)return;a(!0);let i=setTimeout(()=>{r(e),a(!1)},t);return()=>clearTimeout(i)},[e,n,t]),[n,i]}var q=new Map;function J(e,t,n){let r=`${t}|${e}`,i=q.get(r);if(i===void 0){try{i=new Intl.DateTimeFormat(`en-GB`,{...n,timeZone:e})}catch{i=null}q.set(r,i)}return i}var re={hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`},Y={hour:`2-digit`,timeZoneName:`shortOffset`},X={weekday:`short`,day:`2-digit`,month:`short`,year:`numeric`},Z=e=>e!==null&&J(e,`clock`,re)&&J(e,`offset`,Y)&&J(e,`day`,X)?e:`UTC`;function ie(e,t){return J(Z(t),`clock`,re).format(e)}function ae(e,t){let n=J(Z(t),`offset`,Y);if(!n)return`UTC`;let r=(n.formatToParts(e).find(e=>e.type===`timeZoneName`)?.value??``).replace(/^(GMT|UTC)/,``);return/[1-9]/.test(r)?`UTC${r}`:`UTC`}function oe(e,t){return J(Z(t),`day`,X).format(e).replace(/,\s*/,` · `).toUpperCase()}function se(e,t){let n=new Map,r=new Map,i=(e,n)=>{let i=`${Math.round(e*10)},${Math.round(n*10)}`,a=r.get(i);if(a===void 0){try{a=t(e,n)}catch{a=null}r.set(i,a)}return a},a=[...e].sort((e,t)=>e.ts-t.ts),o=a.map(e=>t!==null&&e.lat!==null&&e.lon!==null?i(e.lat,e.lon):null),s=a.flatMap((e,t)=>o[t]===null?[]:[{ts:e.ts,zone:o[t]}]),c=0;return a.forEach((e,t)=>{if(o[t]!==null||s.length===0){n.set(e.ts,o[t]);return}for(;c+1<s.length&&Math.abs(s[c+1].ts-e.ts)<Math.abs(s[c].ts-e.ts);)c++;n.set(e.ts,s[c].zone)}),n}function ce(e,t){let n=se(e,t),r=e=>n.get(e)??null,i=new Set(e.map(e=>ae(e.ts,r(e.ts)))),a=i.size>1;return{head:a?`SHIP`:i.values().next().value??`UTC`,mixed:a,clock:e=>ie(e,r(e)),day:e=>oe(e,r(e)),offset:e=>ae(e,r(e)),dayLine:e=>`${oe(e,r(e))} · ${ae(e,r(e))}`}}var le=null;function ue(t){let[n,r]=(0,F.useState)(()=>le);return(0,F.useEffect)(()=>{let t=!0;return c(()=>import(`./tz-DxphYhHy.js`).then(t=>e(t.default,1)).then(e=>{le=e.default,t&&r(()=>e.default)}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{}),()=>{t=!1}},[]),(0,F.useMemo)(()=>ce(t,n),[t,n])}var de=e=>`lb:columns:${e}`,fe={off:[]};function pe(e){return e.key===`ts`}function Q(e,t){return pe(e)||!t.off.includes(e.key)}function me(e,t){return e.filter(e=>Q(e,t))}function he(e){return e.filter(e=>!pe(e))}function ge(e,t){return pe(t)?e:{off:Q(t,e)?[...e.off,t.key]:e.off.filter(e=>e!==t.key)}}function _e(e,t){return{off:t?[]:he(e).map(e=>e.key)}}function ve(e,t){return xe(e.off)===xe(t.off)}function ye(e){try{let t=globalThis.localStorage?.getItem(de(e));if(!t)return fe;let n=JSON.parse(t);return{off:Array.isArray(n.off)?n.off.filter(e=>typeof e==`string`):[]}}catch{return fe}}function be(e,t){try{globalThis.localStorage?.setItem(de(e),JSON.stringify(t))}catch{}}function xe(e){return[...new Set(e)].sort().join(` `)}var $=n();function Se({cols:e,applied:t,onApply:n,onCancel:r}){let[i,a]=(0,F.useState)(t),o=ve(i,t),s=he(e),c=s.filter(e=>Q(e,i)).length;return(0,$.jsxs)(`div`,{className:`lb-pick`,children:[(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Columns`}),(0,$.jsxs)(`span`,{className:`lbp-s`,children:[c,` of `,s.length]}),(0,$.jsxs)(`span`,{className:`lbp-all`,children:[(0,$.jsx)(`button`,{onClick:()=>a(_e(e,!0)),children:`All`}),(0,$.jsx)(`button`,{onClick:()=>a(_e(e,!1)),children:`None`})]})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:s.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${Q(e,i)?` on`:``}`,"aria-pressed":Q(e,i),onClick:()=>a(ge(i,e)),children:e.head},e.key))})]}),(0,$.jsxs)(`div`,{className:`lbp-act`,children:[(0,$.jsx)(`button`,{onClick:r,children:`Cancel`}),(0,$.jsx)(`button`,{className:`lbp-go`,disabled:o,onClick:()=>n(i),children:`Show these columns`})]})]})}var Ce={"1m":1,"1h":60,"6h":360,"1d":1440},we={"1m":`Every minute`,"1h":`Hourly`,"6h":`Six-hourly`,"1d":`Daily`},Te={"1m":60,"1h":48,"6h":40,"1d":30},Ee=15e3;function De(e){let t=l(),[n,i]=(0,F.useState)(0),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)([]),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(e);m!==e&&(h(e),i(0),o(!1));let g=Ce[e],_=Te[e]+n*Te[e],v=(0,F.useCallback)(async()=>{p(!0),d(null);try{let e=_+1,n=g===1?(await t.logbook.minutes({limit:e,order:`desc`})).rows:await t.logbook.snapshots({bucket:g,limit:e,order:`desc`});o(n.length>_),c(n.slice(0,_))}catch(e){d(e.message)}finally{p(!1)}},[g,_]);return(0,F.useEffect)(()=>{v();let e=r(v,Ee);return()=>e()},[v]),{snaps:s,err:u,busy:f,hasMore:a,loadMore:(0,F.useCallback)(()=>i(e=>e+1),[])}}function Oe(){let e=l(),[t,n]=(0,F.useState)(w()),[i,a]=(0,F.useState)([]),[o,s]=(0,F.useState)(null),[c,u]=(0,F.useState)(!1),d=(0,F.useRef)(!0),f=S(6e4),p=w(new Date(f)),h=(0,F.useMemo)(()=>m(t),[t]),g=h+24*36e5,_=t===p;(0,F.useEffect)(()=>{d.current&&t!==p&&n(p)},[p,t]);let v=(0,F.useCallback)(e=>{d.current=e===w(),n(e)},[]),y=(0,F.useCallback)(async()=>{u(!0),s(null);try{let t=await e.logbook.snapshots({from:h,to:g,limit:5e3,order:`desc`,bucket:60});a(t)}catch(e){s(e.message)}finally{u(!1)}},[h,g]);return(0,F.useEffect)(()=>{if(y(),!_)return;let e=r(y,Ee);return()=>e()},[y,_]),{dateStr:t,setDateStr:v,dayStart:h,isToday:_,snaps:i,err:o,busy:c,prevDay:(0,F.useCallback)(()=>v(w(new Date(h-864e5))),[h,v]),nextDay:(0,F.useCallback)(()=>v(w(new Date(h+864e5))),[h,v]),goToday:(0,F.useCallback)(()=>v(w()),[v])}}var ke=5e3;async function Ae(e,t,n){let r=await e({from:t,to:n,limit:5001,order:`desc`});return{rows:r.rows.slice(0,ke),truncated:r.clamped||r.rows.length>5e3,minutesFrom:r.minutesFrom}}function je(e,t,n,r=`last`){let i=l(),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(!1),[h,g]=(0,F.useState)(!1),[_,v]=(0,F.useState)(null),[y,b]=(0,F.useState)([]),x=(0,F.useMemo)(()=>m(e),[e]),S=(0,F.useMemo)(()=>m(t)+864e5-1,[t]),C=Ce[n],w=(0,F.useCallback)(async()=>{if(Number.isNaN(x)||Number.isNaN(S)||S<x){o([]),b([]),p(!1),c(null),g(!0);return}g(!1),d(!0),c(null);try{if(b([]),C===1){let e=await Ae(e=>i.logbook.minutes(e),x,S);v(e.minutesFrom),p(e.truncated),o(e.rows);return}let e=await i.logbook.rollupHours(x,S);v(null);let t=P(e,n),a=t.map(e=>D(e,r)),s=e=>e.slice(Math.max(0,e.length-ke));p(a.length>ke),o(s(a)),r!==`last`&&b(s(t.map(e=>D(e,`last`))))}catch(e){c(e.message)}finally{d(!1),g(!0)}},[x,S,C,n,r]);return(0,F.useEffect)(()=>{w()},[w]),{snaps:a,err:s,busy:u,truncated:f,loaded:h,minutesFrom:_,plain:y}}var Me=[`1m`,`1h`,`6h`,`1d`],Ne=[{v:`csv`,name:`CSV`,note:`a file for a spreadsheet`},{v:`pdf`,name:`PDF`,note:`the page, through your printer`}],Pe=[{v:`screen`,name:`Screen`},{v:`paper`,name:`Paper`}],Fe=[`last`,`avg`,`min`,`max`];function Ie(e,t,n){return e===`pdf`?[n]:t.includes(n)?t.filter(e=>e!==n):[...t,n]}function Le(e,t){return e===`pdf`?[t[0]??`last`]:t}function Re(){return w(new Date(Date.now()-7*864e5))}function ze({initial:e,onView:t,onSave:n}){let[r,i]=(0,F.useState)(e?.from??Re()),[a,o]=(0,F.useState)(e?.to??w()),[s,c]=(0,F.useState)(e?.gran??`1h`),[l,u]=(0,F.useState)(e?.format??`csv`),[d,f]=(0,F.useState)(e?.stats??[`last`]),[p,m]=(0,F.useState)(e?.distance??!1),[h,g]=(0,F.useState)(e?.samples??!1),[_,v]=(0,F.useState)(e?.style??`screen`),y=a<r,b={from:r,to:a,gran:s,format:l,stats:Le(l,d),distance:p,samples:h,style:_},x=s!==`1m`,S=l===`pdf`,C=x&&!S&&d.length===0&&!p&&!h,T=e=>f(t=>Ie(l,t,e)),E=Le(l,d),D=e=>E.includes(e);return(0,$.jsxs)(`div`,{className:`lb-pick lb-exp`,children:[(0,$.jsxs)(`div`,{className:`lbp-books`,children:[(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Window`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:`UTC days, both ends included`})]}),(0,$.jsxs)(`div`,{className:`lbe-dates`,children:[(0,$.jsxs)(`label`,{children:[(0,$.jsx)(`span`,{children:`From`}),(0,$.jsx)(`input`,{type:`date`,className:`dt`,value:r,max:w(),onChange:e=>i(e.target.value)})]}),(0,$.jsxs)(`label`,{children:[(0,$.jsx)(`span`,{children:`To`}),(0,$.jsx)(`input`,{type:`date`,className:`dt`,value:a,max:w(),onChange:e=>o(e.target.value)})]})]})]}),(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Interval`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:`one row per`})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:Me.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${s===e?` on`:``}`,onClick:()=>c(e),children:we[e]},e))})]}),(0,$.jsxs)(`div`,{className:`lbp-book`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Save as`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:Ne.find(e=>e.v===l)?.note})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:Ne.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${l===e.v?` on`:``}`,onClick:()=>u(e.v),children:e.name},e.v))})]}),(0,$.jsxs)(`div`,{className:`lbp-book${S?``:` off`}`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Style`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:S?_===`screen`?`the app's own dark ink`:`white, for a printer`:`the page's ink; a file carries none`})]}),(0,$.jsx)(`div`,{className:`lbp-chips`,children:Pe.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${_===e.v?` on`:``}`,disabled:!S,onClick:()=>v(e.v),children:e.name},e.v))})]})]}),x&&(0,$.jsxs)(`div`,{className:`lbp-book lbp-figs`,children:[(0,$.jsxs)(`div`,{className:`lbp-h`,children:[(0,$.jsx)(`span`,{className:`lbp-n`,children:`Figures`}),(0,$.jsx)(`span`,{className:`lbp-s`,children:S?`one: a table cell holds one number`:`one or more: a column each`})]}),(0,$.jsxs)(`div`,{className:`lbp-chips`,children:[Fe.map(e=>(0,$.jsx)(`button`,{className:`lbp-c${D(e)?` on`:``}`,onClick:()=>T(e),children:k[e]},e)),(0,$.jsx)(`button`,{className:`lbp-c${p?` on`:``}`,disabled:S,onClick:()=>m(!p),children:`Distance`}),(0,$.jsx)(`button`,{className:`lbp-c${h?` on`:``}`,disabled:S,onClick:()=>g(!h),children:`Samples`})]})]}),y&&(0,$.jsx)(`div`,{className:`lbe-warn`,children:`That window ends before it begins.`}),C&&(0,$.jsx)(`div`,{className:`lbe-warn`,children:`Choose at least one figure to put in the file.`}),(0,$.jsxs)(`div`,{className:`lbp-act`,children:[S&&(0,$.jsx)(`button`,{disabled:y,onClick:()=>t(b),children:`View`}),(0,$.jsxs)(`button`,{className:`lbp-go`,disabled:y||C,onClick:()=>n(b),children:[`Save `,l.toUpperCase()]})]})]})}function Be({open:e,style:t,cls:n,children:r}){let[i,a]=(0,F.useState)(e);return e&&!i&&a(!0),i?(0,$.jsx)(`div`,{className:`lb-open${e?``:` shut`}${n??``}`,style:t,onAnimationEnd:t=>{t.target===t.currentTarget&&!e&&a(!1)},children:(0,$.jsx)(`div`,{className:`lb-open-in`,children:r})}):null}function Ve(e){let t=e-32-58;return Math.max(1,Math.floor(t/52))}function He(e){return e.reduce((e,t)=>e+(t.lanes??1),0)}function Ue(e,t){if(t===null||e.length===0)return e;let n=Ve(t),r=e.slice(0,1);for(let t of e.slice(1)){let e=t.lanes??1;if(e>n)break;n-=e,r.push(t)}return r}function We(e,t,n){return t===null?e:e.slice(0,Ve(t-(n?108:0)))}var Ge=180,Ke=[`1m`,`1h`,`6h`,`1d`],qe={"1m":`Last hour`,"1h":`Last 2 days`,"6h":`Last 10 days`,"1d":`Last month`};function Je({book:e}){let t=l(),[n,r]=(0,F.useState)(`live`),[i,a]=(0,F.useState)(`1h`),[o,s]=(0,F.useState)(null),[c,u]=ne((0,F.useMemo)(()=>({book:e,mode:n,gran:i,family:o}),[e,n,i,o]),Ge),{book:d,mode:f,gran:p,family:h}=c,g=n!==f,[v,y]=(0,F.useState)(()=>localStorage.getItem(`lb:windUnit`)||`kn`),b=()=>y(e=>{let t=e===`kn`?`bft`:`kn`;return localStorage.setItem(`lb:windUnit`,t),t}),x=(0,F.useRef)([]),S=(0,F.useRef)(0),[C,w]=(0,F.useState)(()=>ye(d)),[T,E]=(0,F.useState)(d);T!==d&&(E(d),w(ye(d)),x.current=[],S.current=0);let[O,k]=(0,F.useState)(!1),I=e=>{w(e),be(d,e),k(!1)},[L,R]=_(),z=(0,F.useRef)(null),B=(0,F.useRef)(null),V=(0,F.useCallback)(e=>{B.current=e,L(e)},[L]),H=(0,F.useRef)(null);(0,F.useLayoutEffect)(()=>{let e=B.current;if(!e)return;let t=()=>e.querySelectorAll(`.lb-ctrl, .lb-pick, .lb-frame`);if(u){let e=new Map;t().forEach(t=>e.set(t,t.getBoundingClientRect().width)),H.current=e;return}let n=H.current;if(H.current=null,!n||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let r=parseFloat(getComputedStyle(e).getPropertyValue(`--lb-fade-in`))||0;t().forEach(e=>{let t=n.get(e);if(t===void 0||typeof e.animate!=`function`)return;let i=e.getBoundingClientRect().width;Math.abs(i-t)<1||e.animate([{maxWidth:`${t}px`},{maxWidth:`${i}px`}],{duration:r,easing:`cubic-bezier(0.32, 0.72, 0, 1)`})})},[u,c]);let[U,ee]=(0,F.useState)(!1),[K,te]=(0,F.useState)(null),[q,J]=(0,F.useState)(!1),[re,Y]=(0,F.useState)(null),[X,Z]=(0,F.useState)(null),ie={book:d,mode:n,setMode:r,gran:i,setGran:a,shownGran:p,family:o,setFamily:s,shownFamily:h,leaving:u,modeLeaving:g,lanesHold:z,groupsHold:x,chosenHold:S,windUnit:v,toggleWind:b,selection:C,picking:O,setPicking:k,applySelection:I,width:R,exporting:U,setExporting:ee,request:K,onView:e=>{te(e),r(`range`),Y(null)},onSave:async e=>{if(ee(!1),Y(null),Z(null),e.format===`pdf`){te(e),r(`range`),J(!0);return}try{let n=m(e.from),r=m(e.to)+864e5-1;if(e.gran===`1m`){let{rows:e,truncated:i}=await Ae(e=>t.logbook.minutes(e),n,r),a=me(G(W(e,v),d),C);A(M(`logbook-${d}`,n,`csv`,i?`-partial`:``),`text/csv`,j(e,a)),i&&Z(`That window holds more than ${ke} minutes, so the file stops at the most recent ${ke} and its name ends in -partial. A longer interval covers the same days in fewer rows.`);return}let i=P(await t.logbook.rollupHours(n,r),e.gran),a=e.stats.map(e=>({stat:e,cols:me(G(W(i.map(t=>D(t,e)),v),d),C)})).filter(e=>e.cols.length>1);A(M(`logbook-${d}`,n,`csv`),`text/csv`,N(i,a,{distance:e.distance,samples:e.samples}))}catch(e){Y(e.message)}},saveErr:re,saveNote:X};return(0,$.jsxs)(`div`,{className:`lb`,ref:V,children:[(0,$.jsx)(`style`,{children:`@media print { @page { size: A4 landscape; } }`}),f===`live`?(0,$.jsx)(_t,{...ie}):f===`day`?(0,$.jsx)(vt,{...ie}):(0,$.jsx)(wt,{...ie,req:K,printing:q,donePrinting:()=>J(!1)})]})}function Ye({mode:e,setMode:t}){return(0,$.jsxs)(`div`,{className:`seg`,children:[(0,$.jsx)(`button`,{className:e===`live`?`on`:``,onClick:()=>t(`live`),children:`Live`}),(0,$.jsx)(`button`,{className:e===`day`?`on`:``,onClick:()=>t(`day`),children:`Day`})]})}function Xe({leaving:e,children:t}){return(0,$.jsx)(`div`,{className:`lb-win${e?` leaving`:``}`,children:t})}function Ze({groups:e,family:t,setFamily:n}){if(e.length<2)return null;let r=e.find(e=>e.tab===t)??e[0];return(0,$.jsx)(`div`,{className:`seg`,children:e.map(e=>(0,$.jsx)(`button`,{className:e.tab===r.tab?`on`:``,onClick:()=>n(e.tab),children:e.head},e.tab))})}function Qe(e,t,n){if(e===null||m(t.from)>=e)return null;let r=new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`}),i=n[n.length-1];return`Minutes reach back to ${r}.${i!==void 0&&i.ts<e?` Earlier days in this window read one row per hour.`:``}`}function $e(e,t,n){let r=k[e].toLowerCase(),i=t.length===1?t[0]:`${t.slice(0,-1).join(`, `)} and ${t[t.length-1]}`,a=n.some(e=>e.lat!==null&&e.lon!==null),o=t.length===1;return`${i} ${o?`has`:`have`} no ${r}, so on each row ${o?`it carries`:`they carry`} the reading that window closed on${a?`, as the position does`:``}.`}function et(e,t){if(t.length===0)return e;let n=new Map(t.map(e=>[e.ts,e]));return e.map(e=>{let t=n.get(e.ts);if(!t)return e;let r={...e};for(let[e,n]of Object.entries(t))e!==`path_values`&&(r[e]===null||r[e]===void 0)&&n!=null&&(r[e]=n);if(t.path_values){let n={...e.path_values??{}};for(let[e,r]of Object.entries(t.path_values))(n[e]===void 0||n[e]===null)&&(n[e]=r);r.path_values=n}return r})}function tt(e){return m(e.to)+864e5-1>=Date.now()&&e.gran!==`1m`?`No row has closed at this interval yet. A shorter interval shows today's.`:`Nothing was logged between these dates.`}function nt(e,t,n){return e.length>1||t===null?lt(e):{"--lb-cols":n.current??Ve(t)}}function rt({what:e}){return(0,$.jsxs)(`div`,{className:`sp-empty`,children:[(0,$.jsx)(`div`,{className:`em-t`,children:`No snapshots`}),(0,$.jsx)(`div`,{className:`em-s`,children:e})]})}var it=(e,t)=>`u:${e}:${t}`;function at(e,t,n,r,i,a,o,s,c,l=!0){let u=st(e,t,n,r,i,a,o,s,c,l);if(t!==`engine`||u.groups.length<2)return u;let d=u,f=ot(u);for(let o of u.groups){if(o===u.group||o.tab===a)continue;let s=st(e,t,n,r,i,o.tab,{current:null},{current:[]},{current:0},l),c=ot(s);c>f&&(d=s,f=c)}return d===u?u:{...u,block:d.block,cls:d.cls}}function ot(e){let t=Math.max(1,Number(e.block[`--lb-cols`]??1));return 58+(e.cls.includes(`u`)?108:0)+t*164}function st(e,t,n,r,i,a,o,s,c,l){let u=t===`engine`?K(e):[];u.length>0&&(s.current=u);let d=u.length===0&&e.length===0?s.current:u,f=u.find(e=>e.tab===a)??u[0];if(f&&f.units.length>1){let e=f.metrics.map(e=>({key:it(f.tab,e.key),head:e.head})),t=f.metrics.filter(e=>Q({key:it(f.tab,e.key)},r)),n=l?We(t,i,!0):t,a={...f,metrics:n};return o.current=Math.max(1,n.length),t.length>0&&(c.current=t.length),{groups:d,group:a,drawn:[],pick:e,btn:{shown:n.length,chosen:t.length,kept:c.current,offered:e.length},block:{"--lb-cols":Math.max(1,n.length)},cls:` u`}}let p=G(W(e,n),t),m=f?p.filter(e=>e.key===`ts`||e.tab===f.tab):p,h=me(m,r),g=l?Ue(h,i):h;return g.length>1&&(o.current=He(g.slice(1))),h.length>1&&(c.current=h.length-1),{groups:d,group:null,drawn:g,pick:m,btn:{shown:g.length-1,chosen:h.length-1,kept:c.current,offered:m.length-1},block:nt(g,i,o),cls:``}}function ct(e){return{"--lb-cols":Math.max(1,e.metrics.length)}}function lt(e){return{"--lb-cols":He(e.slice(1))}}function ut(e){return(e.lanes??1)>1?` w${e.lanes}`:``}function dt(e,t){return t===`last`?we[e]:`${we[e]} · ${k[t]}`}function ft(e,t,n,r){return r===0?String(n):e<t?`${e} of ${t}`:String(t)}function pt({shown:e,chosen:t,kept:n,offered:r,open:i,onOpen:a}){let o=r===0;return(0,$.jsxs)(`button`,{className:`lb-colbtn${i?` on`:``}${o?` quiet`:``}`,onClick:a,disabled:o,children:[`Columns · `,(0,$.jsx)(`b`,{children:ft(e,t,n,r)})]})}function mt({open:e,onOpen:t}){return(0,$.jsx)(`button`,{className:`lb-colbtn${e?` on`:``}`,onClick:t,children:`View`})}function ht({cols:e,group:t,times:n,toggleWind:r}){if(t){let e=t.units.length>1;return(0,$.jsxs)(`div`,{className:`lb-cols${e?` u`:``}`,style:ct(t),children:[(0,$.jsx)(`span`,{children:n.head}),e&&(0,$.jsx)(`span`,{className:`un`,children:`Unit`}),t.metrics.map(e=>(0,$.jsxs)(`span`,{children:[e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key))]})}return(0,$.jsx)(`div`,{className:`lb-cols`,style:lt(e),children:e.map(e=>e.tappable?(0,$.jsxs)(`span`,{className:`tap${ut(e)}`,onClick:r,title:`Tap: knots ⇄ Beaufort`,children:[e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key):(0,$.jsxs)(`span`,{className:ut(e).trim(),children:[e.key===`ts`?n.head:e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key))})}function gt({of:e}){return(0,$.jsx)(`b`,{className:`lb-u`,children:e===void 0||e===``?`\xA0`:e})}function _t({book:e,mode:t,setMode:n,gran:r,setGran:i,shownGran:a,family:o,setFamily:s,shownFamily:c,leaving:l,modeLeaving:u,lanesHold:d,groupsHold:f,chosenHold:p,windUnit:m,toggleWind:h,selection:g,picking:_,setPicking:v,applySelection:y,width:b,exporting:x,setExporting:S,request:C,onView:w,onSave:T,saveErr:E,saveNote:D}){let{snaps:O,err:k,busy:A,hasMore:j,loadMore:M}=De(a),N=ue(O),P=(0,F.useMemo)(()=>Tt(O,N,!1),[O,N]),{groups:I,group:L,drawn:R,pick:z,btn:B,block:V,cls:H}=at(O,e,m,g,b,c,d,f,p);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`lb-ctrl${H}`,style:V,children:[(0,$.jsx)(Ye,{mode:t,setMode:n}),(0,$.jsx)(Xe,{leaving:u,children:(0,$.jsx)(`div`,{className:`seg`,children:Ke.map(e=>(0,$.jsx)(`button`,{className:r===e?`on`:``,onClick:()=>i(e),children:e},e))})}),(0,$.jsx)(Ze,{groups:I,family:o,setFamily:s}),(0,$.jsxs)(`div`,{className:`lb-acts`,children:[(0,$.jsx)(pt,{shown:B.shown,chosen:B.chosen,kept:B.kept,offered:B.offered,open:_,onOpen:()=>v(!_)}),(0,$.jsx)(mt,{open:x,onOpen:()=>S(!x)})]})]}),(0,$.jsx)(Be,{open:_,style:V,cls:H,children:(0,$.jsx)(Se,{cols:z,applied:g,onApply:y,onCancel:()=>v(!1)})}),(0,$.jsx)(Be,{open:x,style:V,cls:H,children:(0,$.jsx)(ze,{initial:C??void 0,onView:w,onSave:T})}),E&&(0,$.jsx)(`div`,{className:`lb-err`,children:E}),D&&(0,$.jsx)(`div`,{className:`lb-note`,children:D}),(0,$.jsxs)(`div`,{className:`lb-frame${P?` dated`:``}${N.mixed?` mixed`:``}${H}${l?` leaving`:``}`,style:V,children:[(0,$.jsx)(xt,{book:e,window:qe[a],interval:we[a],times:N}),(0,$.jsxs)(`div`,{className:`lb-day`,style:lt(R),children:[(0,$.jsx)(`span`,{children:qe[a]}),(0,$.jsx)(`b`,{children:O.length})]}),(0,$.jsx)(ht,{cols:R,group:L,times:N,toggleWind:h}),k&&(0,$.jsx)(`div`,{className:`lb-err`,children:k}),!A&&!k&&O.length===0?(0,$.jsx)(rt,{what:`Nothing was logged in this window (${qe[a].toLowerCase()}).`}):(0,$.jsx)(Et,{snaps:O,cols:R,group:L,times:N,lined:P,footer:j?(0,$.jsx)(`button`,{className:`lb-more`,onClick:M,disabled:A,children:A?`Loading…`:`Load ${Te[a]} more`}):null}),(0,$.jsx)(St,{})]})]})}function vt({book:e,mode:t,setMode:n,family:r,setFamily:i,shownFamily:a,leaving:o,modeLeaving:s,lanesHold:c,groupsHold:l,chosenHold:u,windUnit:d,toggleWind:f,selection:p,picking:m,setPicking:h,applySelection:g,width:_,exporting:v,setExporting:y,request:b,onView:x,onSave:S,saveErr:C,saveNote:T}){let{dateStr:E,setDateStr:D,isToday:O,snaps:k,err:A,busy:j,prevDay:M,nextDay:N,goToday:P}=Oe(),I=ue(k),L=(0,F.useMemo)(()=>Tt(k,I,`turns`),[k,I]),{groups:R,group:z,drawn:B,pick:V,btn:H,block:U,cls:W}=at(k,e,d,p,_,a,c,l,u),G=`${O?`Today · ${new Date(E).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,timeZone:`UTC`})}`:new Date(E).toLocaleDateString(`en-GB`,{weekday:`short`,day:`2-digit`,month:`short`,timeZone:`UTC`}).replace(/,/g,``)} · UTC day`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`lb-ctrl${W}`,style:U,children:[(0,$.jsx)(Ye,{mode:t,setMode:n}),(0,$.jsx)(Xe,{leaving:s,children:(0,$.jsxs)(`div`,{className:`lb-date`,children:[(0,$.jsx)(`button`,{className:`lb-step`,onClick:M,"aria-label":`Previous day`,children:`‹`}),(0,$.jsx)(`input`,{type:`date`,className:`dt`,value:E,max:w(),onChange:e=>D(e.target.value)}),(0,$.jsx)(`button`,{className:`lb-step`,onClick:N,disabled:O,"aria-label":`Next day`,children:`›`}),(0,$.jsx)(`button`,{onClick:P,disabled:O,children:`Now`})]})}),(0,$.jsx)(Ze,{groups:R,family:r,setFamily:i}),(0,$.jsxs)(`div`,{className:`lb-acts`,children:[(0,$.jsx)(pt,{shown:H.shown,chosen:H.chosen,kept:H.kept,offered:H.offered,open:m,onOpen:()=>h(!m)}),(0,$.jsx)(mt,{open:v,onOpen:()=>y(!v)})]})]}),(0,$.jsx)(Be,{open:m,style:U,cls:W,children:(0,$.jsx)(Se,{cols:V,applied:p,onApply:g,onCancel:()=>h(!1)})}),(0,$.jsx)(Be,{open:v,style:U,cls:W,children:(0,$.jsx)(ze,{initial:b??void 0,onView:x,onSave:S})}),C&&(0,$.jsx)(`div`,{className:`lb-err`,children:C}),T&&(0,$.jsx)(`div`,{className:`lb-note`,children:T}),(0,$.jsxs)(`div`,{className:`lb-frame${L?` dated`:``}${I.mixed?` mixed`:``}${W}${o?` leaving`:``}`,style:U,children:[(0,$.jsx)(xt,{book:e,window:G,interval:we[`1h`],times:I}),(0,$.jsxs)(`div`,{className:`lb-day`,style:lt(B),children:[(0,$.jsx)(`span`,{children:G}),(0,$.jsx)(`b`,{children:k.length})]}),(0,$.jsx)(ht,{cols:B,group:z,times:I,toggleWind:f}),A&&(0,$.jsx)(`div`,{className:`lb-err`,children:A}),!j&&k.length===0?(0,$.jsx)(rt,{what:`No telemetry was logged for this day.`}):(0,$.jsx)(Et,{snaps:k,cols:B,group:z,times:I,footer:null,lined:L}),(0,$.jsx)(St,{})]})]})}function yt(){let e=new Date,t=e.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`,timeZone:`UTC`}),n=e=>String(e).padStart(2,`0`);return`${t.toUpperCase()} · ${n(e.getUTCHours())}:${n(e.getUTCMinutes())} UTC`}var bt={bridge:`CHIEF OFFICER`,engine:`CHIEF ENGINEER`};function xt({book:e,window:t,interval:n,times:r}){let i=r.mixed?`SHIP'S TIME · OFFSET ON EACH DATED LINE`:r.head===`UTC`?`UTC`:`SHIP'S TIME · ${r.head}`;return(0,$.jsxs)(`div`,{className:`lb-print-hd`,children:[(0,$.jsxs)(`div`,{className:`ph-id`,children:[(0,$.jsxs)(`span`,{className:`sp-lockup`,children:[(0,$.jsx)(C,{className:`sp-glyph`}),(0,$.jsx)(`span`,{className:`ph-wm`,children:`Siparu`})]}),(0,$.jsxs)(`span`,{className:`ph-book`,children:[`LOGBOOK · `,(0,$.jsx)(`b`,{children:e.toUpperCase()}),` · `,bt[e]]})]}),(0,$.jsxs)(`div`,{className:`ph-meta`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`l`,children:`GENERATED`}),(0,$.jsx)(`b`,{children:yt()})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`l`,children:`WINDOW`}),(0,$.jsx)(`b`,{children:`${t} · ${n}`.toUpperCase()})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`l`,children:`CLOCK`}),(0,$.jsx)(`b`,{children:i})]})]})]})}function St(){return(0,$.jsx)(`div`,{className:`lb-print-ft`,children:(0,$.jsx)(`span`,{children:`siparu.app`})})}function Ct(e,t){let n=(e,t)=>new Date(e).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,...t?{year:`numeric`}:{},timeZone:`UTC`});return e===t?`${n(t,!0)} · UTC day`:`${n(e,!1)} - ${n(t,!0)} · UTC days`}function wt({book:e,req:t,setMode:n,family:r,setFamily:i,shownFamily:a,leaving:o,modeLeaving:s,lanesHold:c,groupsHold:l,chosenHold:u,windUnit:d,toggleWind:f,selection:p,picking:m,setPicking:h,applySelection:g,width:_,exporting:v,setExporting:y,request:b,onView:x,onSave:S,saveErr:C,saveNote:T,printing:D,donePrinting:k}){let A={from:w(),to:w(),gran:`1h`,format:`csv`,stats:[`last`],distance:!1,samples:!1,style:`screen`},j=t??A,M=j.stats[0]??`last`,{snaps:N,err:P,busy:I,truncated:L,loaded:R,minutesFrom:z,plain:B}=je(j.from,j.to,j.gran,M),V=(0,F.useMemo)(()=>et([...N].sort((e,t)=>e.ts-t.ts),B),[N,B]),H=ue(V),{groups:U,group:ee,drawn:K,pick:te,btn:ne,block:q,cls:J}=at(V,e,d,p,_,a,c,l,u,!1),re=(0,F.useCallback)(()=>k(),[k]);(0,F.useEffect)(()=>{!D||!R||I||(re(),O(E(`Siparu-Logbook`,Date.now()),j.style))},[D,R,I,re,j.style]);let Y=Ct(j.from,j.to),X=dt(j.gran,M),Z=(0,F.useMemo)(()=>{if(B.length===0)return[];let t=t=>me(G(W(t,d),e),p).map(e=>e.head),n=new Set(t(N));return t(B).filter(e=>!n.has(e))},[B,N,d,e,p]);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`lb-ctrl${J}`,style:q,children:[(0,$.jsx)(Ye,{mode:`range`,setMode:n}),(0,$.jsx)(Xe,{leaving:s,children:(0,$.jsxs)(`button`,{className:`lb-colbtn on`,onClick:()=>y(!v),children:[Y,` · `,(0,$.jsx)(`b`,{children:X})]})}),(0,$.jsx)(Ze,{groups:U,family:r,setFamily:i}),(0,$.jsx)(`div`,{className:`lb-acts`,children:(0,$.jsx)(pt,{shown:ne.shown,chosen:ne.chosen,kept:ne.kept,offered:ne.offered,open:m,onOpen:()=>h(!m)})})]}),(0,$.jsx)(Be,{open:m,style:q,cls:J,children:(0,$.jsx)(Se,{cols:te,applied:p,onApply:g,onCancel:()=>h(!1)})}),(0,$.jsx)(Be,{open:v,style:q,cls:J,children:(0,$.jsx)(ze,{initial:b??void 0,onView:x,onSave:S})}),C&&(0,$.jsx)(`div`,{className:`lb-err`,children:C}),T&&(0,$.jsx)(`div`,{className:`lb-note`,children:T}),(0,$.jsxs)(`div`,{className:`lb-frame dated${H.mixed?` mixed`:``}${J}${o?` leaving`:``}`,style:q,children:[(0,$.jsx)(xt,{book:e,window:Y,interval:X,times:H}),(0,$.jsxs)(`div`,{className:`lb-day`,style:lt(K),children:[(0,$.jsxs)(`span`,{children:[Y,` · `,X]}),(0,$.jsx)(`b`,{children:L?`${N.length} of more`:N.length})]}),(0,$.jsx)(ht,{cols:K,group:ee,times:H,toggleWind:f}),P&&(0,$.jsx)(`div`,{className:`lb-err`,children:P}),Z.length>0&&(0,$.jsx)(`div`,{className:`lb-note`,children:$e(M,Z,N)}),L&&(0,$.jsxs)(`div`,{className:`lb-note`,children:[`This window holds more than `,5e3,` rows. The most recent `,5e3,` are here; a longer interval covers the same days in fewer.`]}),Qe(z,j,N)&&(0,$.jsx)(`div`,{className:`lb-note`,children:Qe(z,j,N)}),!I&&V.length===0?(0,$.jsx)(rt,{what:tt(j)}):(0,$.jsx)(Et,{snaps:V,cols:K,group:ee,times:H,footer:null,lined:!0}),(0,$.jsx)(St,{})]})]})}function Tt(e,t,n){return n===!0?!0:n===!1&&!t.mixed?!1:new Set(e.map(e=>t.dayLine(e.ts))).size>1}function Et({snaps:e,cols:t,group:n,times:r,footer:i,lined:a}){let o=[],s=null;for(let i of e){if(a){let e=r.dayLine(i.ts);e!==s&&(o.push((0,$.jsx)(Dt,{day:r.day(i.ts),offset:r.offset(i.ts),cols:t,group:n},`sep-${i.ts}`)),s=e)}o.push(n?(0,$.jsx)(Ot,{s:i,group:n,times:r},i.ts):(0,$.jsx)(kt,{s:i,cols:t,times:r},i.ts))}return(0,$.jsxs)(`div`,{className:`lb-rows`,style:n?ct(n):lt(t),children:[o,i]})}function Dt({day:e,offset:t,cols:n,group:r}){let i=r!==null&&r.units.length>1,a=r?r.metrics.map(e=>({key:e.key,head:e.head,unit:e.unit,cls:``})):n.slice(1).map(e=>({key:e.key,head:e.head,unit:e.unit,cls:ut(e).trim()}));return(0,$.jsxs)(`div`,{className:`lb-sep${i?` u`:``}`,children:[(0,$.jsxs)(`span`,{className:`sd`,children:[e,t&&(0,$.jsxs)(`span`,{className:`so`,children:[` · `,t]})]}),i&&(0,$.jsx)(`span`,{className:`sh`}),a.map(e=>(0,$.jsxs)(`span`,{className:e.cls?`sh ${e.cls}`:`sh`,children:[e.head,(0,$.jsx)(gt,{of:e.unit})]},e.key))]})}function Ot({s:e,group:t,times:n}){let r=t.units.length>1;return(0,$.jsx)($.Fragment,{children:t.units.map((i,a)=>(0,$.jsxs)(`div`,{className:`lb-row${r?` u`:``}${a>0?` cont`:``}`,children:[(0,$.jsx)(`span`,{className:`tm`,children:n.clock(e.ts)}),r&&(0,$.jsx)(`span`,{className:`un`,children:i.head}),t.metrics.map(t=>(0,$.jsx)(`span`,{className:`v`,children:te(e,i,t)},t.key))]},i.key))})}function kt({s:e,cols:t,times:n}){return(0,$.jsx)(`div`,{className:`lb-row`,children:t.map((t,r)=>(0,$.jsx)(`span`,{className:r===0?`tm`:`${t.dim?`v dim`:`v`}${ut(t)}`,children:t.key===`ts`?n.clock(e.ts):t.cell(e)},t.key))})}var At=[{to:`/logbook/bridge`,name:`Bridge`,keeper:`Chief officer`,holds:`Position, course and speed, the weather she ran in and the water under her.`,Icon:g},{to:`/logbook/engine`,name:`Engine`,keeper:`Chief engineer`,holds:`Engines, generators and tanks, as she reported them.`,Icon:b}];function jt(){let e=v();return(0,$.jsx)(`div`,{className:`lb-door`,children:(0,$.jsx)(`div`,{className:`lbd-cards`,children:At.map(({to:t,name:n,keeper:r,holds:i,Icon:a})=>(0,$.jsxs)(d,{to:e(t),replace:!0,className:`lbd-card`,children:[(0,$.jsx)(a,{size:42}),(0,$.jsx)(`span`,{className:`lbd-n`,children:n}),(0,$.jsx)(`span`,{className:`lbd-k`,children:r}),(0,$.jsx)(`span`,{className:`lbd-h`,children:i}),(0,$.jsxs)(`span`,{className:`lbd-go`,children:[`Open `,(0,$.jsx)(x,{size:15})]})]},t))})})}function Mt({book:e}){return e?(0,$.jsx)(Je,{book:e}):(0,$.jsx)(jt,{})}export{Mt as default};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{t as r}from"./visibleInterval-CFxPzgzx.js";import{D as i,E as a,N as o,b as s,r as c,x as l,y as u}from"./index-gLen3lD8.js";import{a as d,i as f,n as p,o as m,r as h,s as g,t as _}from"./style-D1uNa2dX.js";var v=e(t(),1),y={fill:`#ffb938`,stroke:`#b38326`,glow:`rgba(255,185,56,0.65)`,dot:`#050706`};function b(e,t=y){let n=t.fill,r=t.stroke;return e===null||Number.isNaN(e)?`
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{t as r}from"./visibleInterval-CFxPzgzx.js";import{D as i,E as a,N as o,b as s,r as c,x as l,y as u}from"./index-BeY0LLy7.js";import{a as d,i as f,n as p,o as m,r as h,s as g,t as _}from"./style-D1uNa2dX.js";var v=e(t(),1),y={fill:`#ffb938`,stroke:`#b38326`,glow:`rgba(255,185,56,0.65)`,dot:`#050706`};function b(e,t=y){let n=t.fill,r=t.stroke;return e===null||Number.isNaN(e)?`
2
2
  <div style="
3
3
  width: 14px; height: 14px;
4
4
  background: ${n};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{M as r,N as i,i as a,m as o,n as s,r as c,t as l,u}from"./index-gLen3lD8.js";var d=e(t(),1),f=n(),p=`siparu.app/app`;function m(e){return Math.max(0,Math.round((new Date(e).getTime()-Date.now())/6e4))}function h(e){let{value:t,unit:n}=c((Date.now()-e)/1e3);return`${t}${n===`s`?`s`:` ${n}`} ago`}function g(e){return e?e.unentitled?e.lastError??`Remote watching is not active on this account.`:e.rejected||e.failures>0?e.lastError??`Not reaching Siparu.`:e.lastSentTs?`Sending · last frame ${h(e.lastSentTs)}`:`Waiting to send the first frame.`:`Checking the link…`}function _({sealing:e}){let t=i().pair??r.pair,[n,c]=(0,d.useState)(!1),[u,h]=(0,d.useState)(!1),[_,v]=(0,d.useState)(!1),{data:y,refresh:b}=o(()=>t.status(),n?5e3:3e4,[]);(0,d.useEffect)(()=>{let e=y?.state;c(e===`showing_code`||e===`awaiting_approval`)},[y?.state]);async function x(e){h(!0);try{await e()}catch{}finally{h(!1),v(!1),b()}}let S=s(e),C=S?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:S.title}),(0,f.jsx)(`div`,{className:`s`,children:S.detail})]})}):null,w=e?.screens??[],T=w.length>0?(0,f.jsx)(`div`,{className:`pair`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`fps`,children:w.map((e,t)=>(0,f.jsx)(`span`,{className:`fp`,children:e},`${e}-${t}`))}),(0,f.jsx)(`div`,{className:`s`,children:`Every screen that can open her reports has a line here. If the line on your phone is missing, she is not sealing to it; if a line here is not one of yours, it can read her.`})]})}):null,E=l(e),D=E?(0,f.jsxs)(f.Fragment,{children:[E.unapproved.length>0?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`She will not seal to these screens`}),(0,f.jsx)(`div`,{className:`s`,children:`Nothing she trusts has vouched for them, so they receive nothing at all. A line here you did not add is somebody else's key on your list: remove it from the boat's page ashore, and if you cannot account for it, pair her again from this screen.`}),(0,f.jsx)(`div`,{className:`fps`,children:E.unapproved.map(e=>(0,f.jsxs)(`span`,{className:`fp`,children:[e.kid,` · `,e.reason]},e.kid))})]})}):null,E.unwrapped.length>0?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Authorised, and still receiving nothing`}),(0,f.jsx)(`div`,{className:`s`,children:`These screens are on her list and she could not wrap her last report to them. From ashore that looks exactly like a boat gone quiet, which is why it is named here.`}),(0,f.jsx)(`div`,{className:`fps`,children:E.unwrapped.map(e=>(0,f.jsxs)(`span`,{className:`fp`,children:[e.kid,` · `,e.reason]},e.kid))})]})}):null,E.unpinned?(0,f.jsx)(`div`,{className:`pair`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Her screens are not pinned`}),(0,f.jsx)(`div`,{className:`s`,children:`She was paired before screens could vouch for one another, so she checks that a key is well formed and nothing about who put it on her list. She still seals every report. Pair her again from this screen to pin the first one, and every later screen will have to chain to it.`})]})}):null]}):null,O=(E?.unapproved.length??0)+(E?.unwrapped.length??0),k=T||D?(0,f.jsxs)(`section`,{className:`sp-sec`,children:[(0,f.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,f.jsx)(`span`,{className:`sp-sec-n`,children:`Screens`}),(0,f.jsx)(`span`,{className:`sp-sec-badge${O>0?` quiet`:``}`,children:O>0?`${O} refused`:`${w.length} sealed`})]}),(0,f.jsxs)(`div`,{className:`sp-glass`,children:[T,D]})]}):null,A=(e,t)=>(0,f.jsxs)(`section`,{className:`sp-sec`,children:[(0,f.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,f.jsx)(`span`,{className:`sp-sec-n`,children:`Link ashore`}),e?(0,f.jsxs)(`span`,{className:`sp-sec-badge${e.quiet?` quiet`:``}`,children:[e.live?(0,f.jsx)(`span`,{className:`rm-dot`,"aria-hidden":`true`}):null,e.text]}):null]}),(0,f.jsx)(`div`,{className:`sp-glass`,children:t})]});if(!y)return(0,f.jsxs)(f.Fragment,{children:[A(null,C??(0,f.jsx)(`div`,{className:`pair`,children:(0,f.jsx)(`div`,{className:`pl`,children:(0,f.jsx)(`div`,{className:`s`,children:`Checking the link…`})})})),k]});let j=(e,t,n)=>(0,f.jsx)(`button`,{className:`pbtn${n?` ${n}`:``}`,disabled:u,onClick:t,children:e}),M=y.pairing_locked===!0,N=(0,f.jsx)(a,{on:y.security_off,locked:M}),P=y.revoke_pending?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Still revoking the old key`}),(0,f.jsx)(`div`,{className:`s`,children:`Remote watching is off on this boat, but Siparu could not be reached to revoke its copy of the key. It will keep trying whenever the boat is online.`})]})}):null,F=(()=>{switch(y.state){case`idle`:case`expired`:return(0,f.jsxs)(`div`,{className:`pair`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`s`,children:y.state===`expired`?`The code expired. Nothing was linked.`:`Off - this boat is not linked to an account.`})]}),!M&&j(y.state===`expired`?`New code`:`Turn on`,()=>x(t.start))]});case`showing_code`:return(0,f.jsxs)(`div`,{className:`pair`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`code`,children:y.userCode}),(0,f.jsxs)(`div`,{className:`s`,children:[`Enter this at `,(0,f.jsx)(`b`,{children:p}),` · `,m(y.expiresAt),` min left`]})]}),j(`Cancel`,()=>x(t.deny),`ghost`)]});case`awaiting_approval`:return(0,f.jsxs)(`div`,{className:`pair asking`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Someone wants to pair`}),(0,f.jsx)(`div`,{className:`who`,children:y.email??`an account we cannot name`}),y.device?(0,f.jsx)(`div`,{className:`fps`,children:(0,f.jsx)(`span`,{className:`fp`,children:y.device.fingerprint})}):null,(0,f.jsx)(`div`,{className:`s`,children:y.device?`Approve only if this is you, and only if that line matches the one on your phone. They will see where this boat is.`:`Approve only if this is you. They will see where this boat is.`})]}),(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Deny`,()=>x(t.deny),`ghost`),!M&&j(`Approve`,()=>x(t.approve),`accent`)]})]});case`paired`:return(0,f.jsxs)(`div`,{className:`pair${y.uplink?.rejected?` err`:``}`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`who`,children:y.email??`linked account`}),!_&&!S&&(0,f.jsx)(`div`,{className:`s`,children:g(y.uplink)})]}),M?null:_?(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Keep`,()=>v(!1),`ghost`),j(`Unlink`,()=>x(t.reset),`accent`)]}):(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Pair again`,()=>x(t.start),`ghost`),j(`Turn off`,()=>v(!0),`ghost`)]})]});case`error`:return(0,f.jsxs)(`div`,{className:`pair err`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`s`,children:y.message})]}),!M&&(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Dismiss`,()=>x(t.reset),`ghost`),j(`Retry`,()=>x(t.start))]})]})}})();return(0,f.jsxs)(f.Fragment,{children:[A((()=>{switch(y.state){case`paired`:{let e=y.uplink;return e?.unentitled?{text:`inactive`}:e?.rejected||S?{text:`not sending`,quiet:!0}:!e||e.failures>0?{text:`not reaching`,quiet:!0}:e.lastSentTs?{text:`on`,live:!0}:{text:`on`}}case`showing_code`:return{text:`waiting`};case`awaiting_approval`:return{text:`asking`,quiet:!0};case`error`:return{text:`error`,quiet:!0};default:return{text:`off`}}})(),(0,f.jsxs)(f.Fragment,{children:[C,N,P,F]})),k]})}var v=3e4;function y(){let{data:e}=o(u.health,v,[]);return(0,f.jsx)(`div`,{className:`sp-remote`,children:(0,f.jsx)(_,{sealing:e?.sealing??null})})}export{y as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{M as r,N as i,i as a,m as o,n as s,r as c,t as l,u}from"./index-BeY0LLy7.js";var d=e(t(),1),f=n(),p=`siparu.app/app`;function m(e){return Math.max(0,Math.round((new Date(e).getTime()-Date.now())/6e4))}function h(e){let{value:t,unit:n}=c((Date.now()-e)/1e3);return`${t}${n===`s`?`s`:` ${n}`} ago`}function g(e){return e?e.unentitled?e.lastError??`Remote watching is not active on this account.`:e.rejected||e.failures>0?e.lastError??`Not reaching Siparu.`:e.lastSentTs?`Sending · last frame ${h(e.lastSentTs)}`:`Waiting to send the first frame.`:`Checking the link…`}function _({sealing:e}){let t=i().pair??r.pair,[n,c]=(0,d.useState)(!1),[u,h]=(0,d.useState)(!1),[_,v]=(0,d.useState)(!1),{data:y,refresh:b}=o(()=>t.status(),n?5e3:3e4,[]);(0,d.useEffect)(()=>{let e=y?.state;c(e===`showing_code`||e===`awaiting_approval`)},[y?.state]);async function x(e){h(!0);try{await e()}catch{}finally{h(!1),v(!1),b()}}let S=s(e),C=S?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:S.title}),(0,f.jsx)(`div`,{className:`s`,children:S.detail})]})}):null,w=e?.screens??[],T=w.length>0?(0,f.jsx)(`div`,{className:`pair`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`fps`,children:w.map((e,t)=>(0,f.jsx)(`span`,{className:`fp`,children:e},`${e}-${t}`))}),(0,f.jsx)(`div`,{className:`s`,children:`Every screen that can open her reports has a line here. If the line on your phone is missing, she is not sealing to it; if a line here is not one of yours, it can read her.`})]})}):null,E=l(e),D=E?(0,f.jsxs)(f.Fragment,{children:[E.unapproved.length>0?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`She will not seal to these screens`}),(0,f.jsx)(`div`,{className:`s`,children:`Nothing she trusts has vouched for them, so they receive nothing at all. A line here you did not add is somebody else's key on your list: remove it from the boat's page ashore, and if you cannot account for it, pair her again from this screen.`}),(0,f.jsx)(`div`,{className:`fps`,children:E.unapproved.map(e=>(0,f.jsxs)(`span`,{className:`fp`,children:[e.kid,` · `,e.reason]},e.kid))})]})}):null,E.unwrapped.length>0?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Authorised, and still receiving nothing`}),(0,f.jsx)(`div`,{className:`s`,children:`These screens are on her list and she could not wrap her last report to them. From ashore that looks exactly like a boat gone quiet, which is why it is named here.`}),(0,f.jsx)(`div`,{className:`fps`,children:E.unwrapped.map(e=>(0,f.jsxs)(`span`,{className:`fp`,children:[e.kid,` · `,e.reason]},e.kid))})]})}):null,E.unpinned?(0,f.jsx)(`div`,{className:`pair`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Her screens are not pinned`}),(0,f.jsx)(`div`,{className:`s`,children:`She was paired before screens could vouch for one another, so she checks that a key is well formed and nothing about who put it on her list. She still seals every report. Pair her again from this screen to pin the first one, and every later screen will have to chain to it.`})]})}):null]}):null,O=(E?.unapproved.length??0)+(E?.unwrapped.length??0),k=T||D?(0,f.jsxs)(`section`,{className:`sp-sec`,children:[(0,f.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,f.jsx)(`span`,{className:`sp-sec-n`,children:`Screens`}),(0,f.jsx)(`span`,{className:`sp-sec-badge${O>0?` quiet`:``}`,children:O>0?`${O} refused`:`${w.length} sealed`})]}),(0,f.jsxs)(`div`,{className:`sp-glass`,children:[T,D]})]}):null,A=(e,t)=>(0,f.jsxs)(`section`,{className:`sp-sec`,children:[(0,f.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,f.jsx)(`span`,{className:`sp-sec-n`,children:`Link ashore`}),e?(0,f.jsxs)(`span`,{className:`sp-sec-badge${e.quiet?` quiet`:``}`,children:[e.live?(0,f.jsx)(`span`,{className:`rm-dot`,"aria-hidden":`true`}):null,e.text]}):null]}),(0,f.jsx)(`div`,{className:`sp-glass`,children:t})]});if(!y)return(0,f.jsxs)(f.Fragment,{children:[A(null,C??(0,f.jsx)(`div`,{className:`pair`,children:(0,f.jsx)(`div`,{className:`pl`,children:(0,f.jsx)(`div`,{className:`s`,children:`Checking the link…`})})})),k]});let j=(e,t,n)=>(0,f.jsx)(`button`,{className:`pbtn${n?` ${n}`:``}`,disabled:u,onClick:t,children:e}),M=y.pairing_locked===!0,N=(0,f.jsx)(a,{on:y.security_off,locked:M}),P=y.revoke_pending?(0,f.jsx)(`div`,{className:`pair warn`,children:(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Still revoking the old key`}),(0,f.jsx)(`div`,{className:`s`,children:`Remote watching is off on this boat, but Siparu could not be reached to revoke its copy of the key. It will keep trying whenever the boat is online.`})]})}):null,F=(()=>{switch(y.state){case`idle`:case`expired`:return(0,f.jsxs)(`div`,{className:`pair`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`s`,children:y.state===`expired`?`The code expired. Nothing was linked.`:`Off - this boat is not linked to an account.`})]}),!M&&j(y.state===`expired`?`New code`:`Turn on`,()=>x(t.start))]});case`showing_code`:return(0,f.jsxs)(`div`,{className:`pair`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`code`,children:y.userCode??`····`}),(0,f.jsx)(`div`,{className:`s`,children:y.userCode?(0,f.jsxs)(f.Fragment,{children:[`Enter this at `,(0,f.jsx)(`b`,{children:p}),` · `,m(y.expiresAt),` min left`]}):(0,f.jsxs)(f.Fragment,{children:[`The code shows on an administrator's screen · `,m(y.expiresAt),` min left`]})})]}),j(`Cancel`,()=>x(t.deny),`ghost`)]});case`awaiting_approval`:return(0,f.jsxs)(`div`,{className:`pair asking`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Someone wants to pair`}),(0,f.jsx)(`div`,{className:`who`,children:y.email??`an account we cannot name`}),y.device?(0,f.jsx)(`div`,{className:`fps`,children:(0,f.jsx)(`span`,{className:`fp`,children:y.device.fingerprint})}):null,(0,f.jsx)(`div`,{className:`s`,children:y.device?`Approve only if this is you, and only if that line matches the one on your phone. They will see where this boat is.`:`Approve only if this is you. They will see where this boat is.`})]}),(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Deny`,()=>x(t.deny),`ghost`),!M&&j(`Approve`,()=>x(t.approve),`accent`)]})]});case`paired`:return(0,f.jsxs)(`div`,{className:`pair${y.uplink?.rejected?` err`:``}`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`who`,children:y.email??`linked account`}),!_&&!S&&(0,f.jsx)(`div`,{className:`s`,children:g(y.uplink)})]}),M?null:_?(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Keep`,()=>v(!1),`ghost`),j(`Unlink`,()=>x(t.reset),`accent`)]}):(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Pair again`,()=>x(t.start),`ghost`),j(`Turn off`,()=>v(!0),`ghost`)]})]});case`error`:return(0,f.jsxs)(`div`,{className:`pair err`,children:[(0,f.jsxs)(`div`,{className:`pl`,children:[(0,f.jsx)(`div`,{className:`t`,children:`Remote watching`}),(0,f.jsx)(`div`,{className:`s`,children:y.message})]}),!M&&(0,f.jsxs)(`div`,{className:`acts`,children:[j(`Dismiss`,()=>x(t.reset),`ghost`),j(`Retry`,()=>x(t.start))]})]})}})();return(0,f.jsxs)(f.Fragment,{children:[A((()=>{switch(y.state){case`paired`:{let e=y.uplink;return e?.unentitled?{text:`inactive`}:e?.rejected||S?{text:`not sending`,quiet:!0}:!e||e.failures>0?{text:`not reaching`,quiet:!0}:e.lastSentTs?{text:`on`,live:!0}:{text:`on`}}case`showing_code`:return{text:`waiting`};case`awaiting_approval`:return{text:`asking`,quiet:!0};case`error`:return{text:`error`,quiet:!0};default:return{text:`off`}}})(),(0,f.jsxs)(f.Fragment,{children:[C,N,P,F]})),k]})}var v=3e4;function y(){let{data:e}=o(u.health,v,[]);return(0,f.jsx)(`div`,{className:`sp-remote`,children:(0,f.jsx)(_,{sealing:e?.sealing??null})})}export{y as default};
@@ -1 +1 @@
1
- import{t as e}from"./jsx-runtime-CaR_m4Xc.js";import{P as t,g as n,o as r}from"./index-gLen3lD8.js";var i=e(),a=`/admin/#/security/users`;function o({admin:e}){let a=n();return(0,i.jsx)(`div`,{className:`doc`,children:(0,i.jsxs)(`div`,{className:`doc-in`,children:[(0,i.jsx)(`div`,{className:`doc-eyebrow`,children:`Signal K`}),(0,i.jsx)(`h1`,{className:`doc-h`,children:`Turning on security`}),(0,i.jsx)(`p`,{className:`doc-lead`,children:`Signal K is running without an account on it. Anyone who can reach this network can read the boat, and can use this plugin's own controls to link her to another account or cut her loose. Until there is an account, Siparu refuses those writes: pairing, unpairing and log edits stay locked.`}),(0,i.jsx)(`h2`,{className:`doc-h2`,children:`What to do`}),(0,i.jsxs)(`ol`,{className:`doc-steps`,children:[(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Open Signal K's admin pages.`}),` `,e?(0,i.jsxs)(i.Fragment,{children:[`They are on this same server, at`,` `,(0,i.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,children:`/admin`}),`.`]}):(0,i.jsxs)(i.Fragment,{children:[`They are on the boat's own server, under `,(0,i.jsx)(`b`,{children:`/admin`}),`: open them from a device on her network, the way you open her dashboard aboard.`]}),` `,`Nothing here is a Siparu account: this is the boat's own server, and the account you are about to make lives on board.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Go to Security, then Users.`}),` With no account yet, that page offers to make the first one.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Pick a username and a password.`}),` Write them down somewhere that is not the boat. There is no reset from ashore.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Press Enable, then Restart.`}),` Signal K writes the account down but keeps running open until it is restarted; it says so in red under the form. The Restart button is at the top of its admin pages. Log in when it comes back.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Decide about "Allow Readonly Access".`}),` It is under Security, then Settings, and newer servers also ask on the form you just filled in. Ticked, anyone on the network can still read the boat and use this app without logging in, and only the controls that change something ask for the password. Unticked, everything asks. Signal K's own note is that readonly access exposes your data on the local network and potentially the public internet, so leave it off on a shared crew or marina network and on only where you know who is on the wire.`]})]}),(0,i.jsx)(`h2`,{className:`doc-h2`,children:`After that`}),(0,i.jsx)(`p`,{className:`doc-p`,children:`This notice stops once the server is back up and asking for an account. It follows whether the server asks at all, not who is allowed in, so it clears whichever way you answer the readonly question. Siparu's locked writes unlock for anyone logged in with admin rights.`}),(0,i.jsx)(`h2`,{className:`doc-h2`,children:`If the network really is yours`}),(0,i.jsx)(`p`,{className:`doc-p`,children:`On a boat with nothing else on her wire, you can leave the server open and tell the plugin you have decided so: the setting is in Signal K under Apps & Plugins, in Siparu's own configuration. The writes unlock. The notice stays, because it reports the door and not the decision: the server is still open. It is the weaker answer of the two, and it is not the one to pick because the password is a nuisance. An open server also lets anything on that network install code, which no setting of ours can hold shut.`}),(0,i.jsx)(`div`,{className:`doc-back`,children:(0,i.jsxs)(t,{to:a(`/`),className:`doc-go`,children:[`Back to the boat `,(0,i.jsx)(r,{size:15})]})})]})})}function s(){return(0,i.jsx)(o,{admin:a})}export{s as default};
1
+ import{t as e}from"./jsx-runtime-CaR_m4Xc.js";import{P as t,g as n,o as r}from"./index-BeY0LLy7.js";var i=e(),a=`/admin/#/security/users`;function o({admin:e}){let a=n();return(0,i.jsx)(`div`,{className:`doc`,children:(0,i.jsxs)(`div`,{className:`doc-in`,children:[(0,i.jsx)(`div`,{className:`doc-eyebrow`,children:`Signal K`}),(0,i.jsx)(`h1`,{className:`doc-h`,children:`Turning on security`}),(0,i.jsx)(`p`,{className:`doc-lead`,children:`Signal K is running without an account on it. Anyone who can reach this network can read the boat, and can use this plugin's own controls to link her to another account or cut her loose. Until there is an account, Siparu refuses those writes: pairing, unpairing and log edits stay locked.`}),(0,i.jsx)(`h2`,{className:`doc-h2`,children:`What to do`}),(0,i.jsxs)(`ol`,{className:`doc-steps`,children:[(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Open Signal K's admin pages.`}),` `,e?(0,i.jsxs)(i.Fragment,{children:[`They are on this same server, at`,` `,(0,i.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,children:`/admin`}),`.`]}):(0,i.jsxs)(i.Fragment,{children:[`They are on the boat's own server, under `,(0,i.jsx)(`b`,{children:`/admin`}),`: open them from a device on her network, the way you open her dashboard aboard.`]}),` `,`Nothing here is a Siparu account: this is the boat's own server, and the account you are about to make lives on board.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Go to Security, then Users.`}),` With no account yet, that page offers to make the first one.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Pick a username and a password.`}),` Write them down somewhere that is not the boat. There is no reset from ashore.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Press Enable, then Restart.`}),` Signal K writes the account down but keeps running open until it is restarted; it says so in red under the form. The Restart button is at the top of its admin pages. Log in when it comes back.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`b`,{children:`Decide about "Allow Readonly Access".`}),` It is under Security, then Settings, and newer servers also ask on the form you just filled in. Ticked, anyone on the network can still read the boat and use this app without logging in, and only the controls that change something ask for the password. Unticked, everything asks. Signal K's own note is that readonly access exposes your data on the local network and potentially the public internet, so leave it off on a shared crew or marina network and on only where you know who is on the wire.`]})]}),(0,i.jsx)(`h2`,{className:`doc-h2`,children:`After that`}),(0,i.jsx)(`p`,{className:`doc-p`,children:`This notice stops once the server is back up and asking for an account. It follows whether the server asks at all, not who is allowed in, so it clears whichever way you answer the readonly question. Siparu's locked writes unlock for anyone logged in with admin rights.`}),(0,i.jsx)(`h2`,{className:`doc-h2`,children:`If the network really is yours`}),(0,i.jsx)(`p`,{className:`doc-p`,children:`On a boat with nothing else on her wire, you can leave the server open and tell the plugin you have decided so: the setting is in Signal K under Apps & Plugins, in Siparu's own configuration. The writes unlock. The notice stays, because it reports the door and not the decision: the server is still open. It is the weaker answer of the two, and it is not the one to pick because the password is a nuisance. An open server also lets anything on that network install code, which no setting of ours can hold shut.`}),(0,i.jsx)(`div`,{className:`doc-back`,children:(0,i.jsxs)(t,{to:a(`/`),className:`doc-go`,children:[`Back to the boat `,(0,i.jsx)(r,{size:15})]})})]})})}function s(){return(0,i.jsx)(o,{admin:a})}export{s as default};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{I as r,N as i,a,b as o,f as s,h as c,j as l,m as u,r as d,y as f}from"./index-gLen3lD8.js";import{a as p,c as m,i as h,n as g,r as _,s as v}from"./export-CGdOfqNp.js";import{a as y,i as b,n as x,o as S,s as C,t as w}from"./style-D1uNa2dX.js";var T=e(t(),1),E=[{mode:`total_l`,label:`Litres`},{mode:`total_usgal`,label:`US gallons`},{mode:`total_impgal`,label:`Imp gallons`},{mode:`per_nm`,label:`Litres / nm`},{mode:`nm_per_l`,label:`nm / L`},{mode:`per_hour`,label:`Litres / hour`}],D=.26417205,O=.21996923,k=1e-6;function A(e,t,n){return`${e.toFixed(n)} ${t}`}function j(e,t,n,r){if(e===null||!Number.isFinite(e))return null;switch(r){case`total_l`:return A(e,`L`,+(e<100));case`total_usgal`:return A(e*D,`US gal`,1);case`total_impgal`:return A(e*O,`Imp gal`,1);case`per_nm`:return t>k?A(e/t,`L/nm`,2):null;case`nm_per_l`:return e>k?A(t/e,`nm/L`,2):null;case`per_hour`:return n>k?A(e/n,`L/h`,1):null}}var M=`Could not load voyage data`;function N(e){return e instanceof l?e.detail||M:e instanceof DOMException&&e.name===`TimeoutError`?`She did not answer in time`:M}function ee(e=0){let t=i(),{data:n,error:r}=u(t.voyage.current,6e4,[e],`voyage:current`),[a,o]=(0,T.useState)(null),[s,l]=(0,T.useState)([]),[d,f]=(0,T.useState)(!0),[p,m]=(0,T.useState)(null);return(0,T.useEffect)(()=>{let e=!1;return(async()=>{try{let[n,r]=await Promise.all([t.voyage.stats(),t.voyage.list(50)]);e||(o(n),l(r),m(null))}catch(t){e||m(N(t))}finally{e||f(!1)}})(),()=>{e=!0}},[e]),{current:n??null,currentStale:r!==null,currentSeenTs:c(`voyage:current`),stats:a,list:s,loading:d,err:p}}var P=e(C(),1),F=new Set;function I(e){return F.add(e),()=>{F.delete(e)}}async function te(){await Promise.all([...F].map(e=>e().catch(()=>void 0)))}var L=n();function R(e,t){let n=(t.querySelector(`.maplibregl-ctrl-attrib-inner`)?.textContent??``).replace(w,``).replace(/^\s*\|\s*/,``).trim();return(e.loaded()?Promise.resolve():new Promise(t=>{let n=setTimeout(t,1500);e.once(`idle`,()=>{clearTimeout(n),t()})})).then(()=>new Promise((t,r)=>{let i=setTimeout(()=>r(Error(`the map did not draw`)),2e3);e.once(`render`,()=>{clearTimeout(i);try{t({url:e.getCanvas().toDataURL(`image/png`),credit:n})}catch(e){r(e)}}),e.triggerRepaint()}))}function z(){return document.documentElement.dataset.theme===`day`?`day`:`night`}function B(e,t){let n=document.createElement(`div`);return n.style.cssText=`width:10px;height:10px;border-radius:50%;border:2px solid ${e};background:${t?e:`transparent`};`,n}function V({track:e}){let t=i(),n=(0,T.useRef)(null),r=(0,T.useRef)(null),[a,o]=(0,T.useState)(null);return(0,T.useEffect)(()=>{if(!n.current||r.current)return;let i=n.current,a=document.documentElement,s=getComputedStyle(a).getPropertyValue(`--accent`).trim()||`#e5484d`,c=!1,l=null,u=null,d=null;return(async()=>{y();let n=await S(t);if(c)return;let f=()=>b(z(),n,{track:{color:s,width:3}}),p=e.filter(e=>e.lat!==null&&e.lon!==null).map(e=>[e.lon,e.lat]);l=new P.default.Map({container:i,style:f(),center:[7.42,43.7],zoom:9,attributionControl:{compact:!1,customAttribution:w},dragRotate:!1,pitchWithRotate:!1}),l.touchZoomRotate.disableRotation(),r.current=l;let m=l;d=I(async()=>{let e=await R(m,i);c||o(e)});let h=()=>{if(!l)return;let e=l.getSource(x);e&&p.length>=2&&e.setData({type:`FeatureCollection`,features:[{type:`Feature`,properties:{},geometry:{type:`LineString`,coordinates:p}}]})};if(l.on(`style.load`,h),h(),p.length>=2){new P.default.Marker({element:B(s,!1),anchor:`center`}).setLngLat(p[0]).addTo(l),new P.default.Marker({element:B(s,!0),anchor:`center`}).setLngLat(p[p.length-1]).addTo(l);let e=new P.default.LngLatBounds;for(let t of p)e.extend(t);l.fitBounds(e,{padding:22,maxZoom:15,animate:!1})}u=new MutationObserver(()=>{l?.setStyle(f()),h()}),u.observe(a,{attributes:!0,attributeFilter:[`data-theme`]})})(),()=>{c=!0,d?.(),u?.disconnect(),l?.remove(),r.current=null}},[e]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{ref:n,className:`vy-map`}),a&&(0,L.jsxs)(`figure`,{className:`vy-map-print`,"aria-hidden":`true`,children:[(0,L.jsx)(`img`,{src:a.url,alt:``}),(0,L.jsx)(`figcaption`,{children:a.credit})]})]})}function H(e,t,n=3){if(e.includes(t))return e.filter(e=>e!==t);let r=[...e,t];return r.length>n?r.slice(r.length-n):r}var U=e(r(),1);function W(e){let t=e.match(/^propulsion\.([^.]+)\.fuel\.rate$/),n=t?t[1]:e;return n.charAt(0).toUpperCase()+n.slice(1)}function G(e){let t=new Set(e.available);return e.selected.filter(e=>!t.has(e))}function ne(e){return e.available.length>1||e.selected.length>0}function K(e){return[...e.available.map(e=>({path:e,reporting:!0})),...G(e).map(e=>({path:e,reporting:!1}))]}function q(e){let t=G(e);return t.length===0||t.length<e.selected.length?null:`No fuel counted: ${t.map(W).join(`, `)} is selected but not reporting a rate.`}function re(e){let t=G(e);return t.length>0&&t.length===e.selected.length?`${t.length===1?W(t[0]):`${t.length} engines`} · not reporting`:e.selected.length===0?`All`:e.selected.length===1?W(e.selected[0]):`${e.selected.length} engines`}function ie({view:e,onClose:t,onApplied:n}){let r=i(),[o,s]=(0,T.useState)(()=>new Set(e.selected)),[c,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(null),p=(0,T.useRef)(null),m=e=>{f(null),s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=async()=>{let e=[...o].sort();u(!0),f(null);try{if(!r.config.setFuelPaths)throw Error(`this setting is written aboard`);await r.config.setFuelPaths(e);let t=e.join(`,`);for(let e=0;e<12;e++){await new Promise(e=>setTimeout(e,700));try{if([...(await r.config.fuelPaths()).selected].sort().join(`,`)===t)break}catch{}}n(),p.current?.()}catch(e){e instanceof l?f(e.code===`security_off`?`Signal K security is off, so the fuel source is locked. Add an admin user in Signal K.`:e.detail||`Could not apply the change`):f(e instanceof Error?e.message:`Could not apply the change`),u(!1)}},g=q(e),_=document.querySelector(`.swiss.sp-screen`)??document.body;return(0,U.createPortal)((0,L.jsxs)(a,{title:`Fuel source`,eyebrow:`voyage fuel`,onClose:t,closeRef:p,footer:(0,L.jsx)(`button`,{type:`button`,className:`fs-apply`,onClick:h,disabled:c,children:c?`Applying…`:`Apply`}),children:[(0,L.jsx)(`p`,{className:`fs-note`,children:`Which engines count toward voyage fuel. With none selected, every reporting engine is summed.`}),g&&(0,L.jsx)(`div`,{className:`fs-quiet`,children:g}),(0,L.jsx)(`div`,{className:`fs-list`,role:`group`,"aria-label":`Fuel-rate sources`,children:K(e).map(({path:e,reporting:t})=>{let n=o.has(e);return(0,L.jsxs)(`button`,{type:`button`,className:`fs-row${n?` on`:``}${t?``:` off-air`}`,role:`checkbox`,"aria-checked":n,onClick:()=>m(e),disabled:c,children:[(0,L.jsxs)(`span`,{className:`fs-name`,children:[W(e),!t&&(0,L.jsx)(`span`,{className:`fs-tag`,children:` not reporting`})]}),(0,L.jsx)(`span`,{className:`fs-path`,children:e})]},e)})}),d&&(0,L.jsx)(`div`,{className:`fs-err`,children:d})]}),_)}var J=`siparu.fuelMode`;function ae(){let e=localStorage.getItem(J);return E.some(t=>t.mode===e)?e:`total_l`}var oe=`(min-width: 1000px)`,Y=[{k:`today`,label:`Today`},{k:`yesterday`,label:`Yesterday`},{k:`rolling_7d`,label:`7 days`},{k:`season`,label:`Season`}],X={not_found:`That passage is no longer in the log.`,no_previous:`There is no earlier passage to join this one to.`,voyage_open:`This passage is still being recorded. It can be edited once it ends.`,nothing_to_undo:`This passage was not joined by hand.`,admin_required:`Sign in to Signal K as an administrator to edit the log.`,security_off:`Signal K security is off, so the log is locked. Add an admin user in Signal K.`};function Z(e){if(e===null||e<=0)return`·`;let t=Math.round(e*60),n=Math.floor(t/60),r=t%60;return n>0?`${n}h ${r}m`:`${r}m`}function Q(e){return new Date(e).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`})}function se(e){let{value:t,unit:n}=d((Date.now()-e)/1e3);return`${t}${n===`s`?`s`:` ${n}`} ago`}function ce(){return new Promise(e=>{let t=setTimeout(e,300);requestAnimationFrame(()=>setTimeout(()=>{clearTimeout(t),e()},0))})}function $(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}`}function le(e){return!e.start_port&&!e.end_port?null:e.end_ts===null?e.start_port?`${e.start_port} →`:null:`${e.start_port??`·`} → ${e.end_port??`·`}`}function ue(){let e=i(),[t,n]=(0,T.useState)(0),r=ee(t),a=s(oe),[o,c]=(0,T.useState)(`today`),[u,d]=(0,T.useState)([]),[f,v]=(0,T.useState)(null),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)({}),[C,w]=(0,T.useState)(ae),[E,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(!1),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)([]),[P,F]=(0,T.useState)(null);(0,T.useEffect)(()=>{localStorage.setItem(J,C)},[C]),(0,T.useEffect)(()=>{let t=!0;return e.health().then(e=>{t&&j(e.boat_name)}).catch(()=>{}),()=>{t=!1}},[]);let I=e.voyage.edits,R=e.voyage.mergePrevious,z=e.voyage.undoMerge;(0,T.useEffect)(()=>{if(!I)return;let e=!0;return I().then(t=>{e&&N(t.merged)}).catch(()=>{}),()=>{e=!1}},[t,I]),(0,T.useEffect)(()=>{let t=!1;return e.config.fuelPaths().then(e=>!t&&D(e)).catch(()=>{}),()=>{t=!0}},[t]);let B=!!E&&ne(E)&&e.config.setFuelPaths!==void 0,V=E?q(E):null,U=r.current&&r.current.end_ts===null?r.current:null,W=async t=>{let n=u.includes(t);if(d(e=>H(e,t)),!n&&!x[t])try{let n=await e.voyage.track(t);S(e=>({...e,[t]:n}))}catch{}},G=r.stats?.[o]??null,K=async e=>{b(!1),await te(),await ce(),h(p(`Siparu-Voyage`,Date.now()),e)},Z=async(e,t)=>{F(null),v(e);try{let e=await t();if(!e.ok){F(X[e.error??``]??`That edit could not be made.`);return}d([]),S({}),n(e=>e+1)}catch(e){e instanceof l?F(X[e.code??``]??(e.detail||`That edit could not be made.`)):F(`The boat did not answer.`)}};return(0,L.jsxs)(`div`,{className:`vy`,children:[(0,L.jsxs)(`div`,{className:`vy-print-hd`,"aria-hidden":`true`,children:[(0,L.jsx)(`span`,{className:`b`,children:A??`Passage record`}),(0,L.jsx)(`span`,{className:`d`,children:new Date().toISOString().slice(0,10)})]}),U&&(0,L.jsxs)(`section`,{className:`sp-sec vy-sec-active`,children:[(0,L.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,L.jsx)(`span`,{className:`sp-sec-n`,children:`Under way`}),U.start_port?(0,L.jsxs)(`span`,{className:`sp-sec-note`,children:[`from `,U.start_port]}):null,r.currentStale?(0,L.jsxs)(`span`,{className:`sp-sec-badge quiet`,children:[`since `,$(U.start_ts),r.currentSeenTs===null?` · unreachable`:` · last seen ${se(r.currentSeenTs)}`]}):(0,L.jsxs)(`span`,{className:`sp-sec-badge`,children:[(0,L.jsx)(`span`,{className:`vy-pulse`,"aria-hidden":`true`}),`since `,$(U.start_ts)]})]}),(0,L.jsx)(`div`,{className:`sp-glass`,children:(0,L.jsx)(de,{v:U})})]}),(0,L.jsxs)(`section`,{className:`sp-sec vy-sec-totals`,children:[(0,L.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,L.jsx)(`span`,{className:`sp-sec-n`,children:`Totals`}),!a&&(0,L.jsx)(`span`,{className:`sp-sec-note`,children:Y.find(e=>e.k===o)?.label.toLowerCase()}),r.err?(0,L.jsx)(`span`,{className:`sp-sec-badge quiet`,children:`unreachable`}):null]}),(0,L.jsx)(`div`,{className:`sp-glass`,children:a?(0,L.jsx)(fe,{stats:r.stats,loading:r.loading}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`vy-seg seg`,role:`group`,"aria-label":`Stats window`,children:Y.map(e=>(0,L.jsx)(`button`,{className:o===e.k?`on`:``,onClick:()=>c(e.k),children:e.label},e.k))}),(0,L.jsx)(pe,{roll:G,loading:r.loading})]})})]}),(0,L.jsxs)(`section`,{className:`sp-sec vy-sec-voyages`,children:[(0,L.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,L.jsx)(`span`,{className:`sp-sec-n`,children:`Voyages`}),r.err?(0,L.jsx)(`span`,{className:`sp-sec-badge quiet`,children:`unreachable`}):r.loading&&r.list.length===0?null:(0,L.jsx)(`span`,{className:`sp-sec-badge`,children:r.list.length===50?`50 shown`:r.list.length})]}),(0,L.jsxs)(`div`,{className:`sp-glass`,children:[(B||r.list.length>0)&&(0,L.jsx)(`div`,{className:`vy-hd`,children:(0,L.jsxs)(`span`,{className:`vy-hd-acts`,children:[B&&(0,L.jsxs)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:()=>k(!0),children:[`Fuel · `,re(E)]}),r.list.length>0&&(0,L.jsx)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:()=>g(_(`siparu-voyages`,Date.now(),`csv`),`text/csv`,m(r.list)),children:`CSV`}),r.list.length>0&&y&&(0,L.jsxs)(`span`,{className:`vy-print-pick`,role:`group`,"aria-label":`Page style`,children:[(0,L.jsx)(`button`,{type:`button`,className:`lbp-c`,onClick:()=>K(`paper`),children:`Paper`}),(0,L.jsx)(`button`,{type:`button`,className:`lbp-c`,onClick:()=>K(`screen`),children:`Screen`})]}),r.list.length>0&&(0,L.jsx)(`button`,{type:`button`,className:`vy-fuelsrc${y?` on`:``}`,"aria-expanded":y,onClick:()=>b(e=>!e),children:`Print`})]})}),r.err?(0,L.jsx)(`div`,{className:`vy-err`,children:r.err}):!r.loading&&r.list.length===0?(0,L.jsxs)(`div`,{className:`sp-empty`,children:[(0,L.jsx)(`div`,{className:`em-t`,children:`No voyages yet`}),(0,L.jsx)(`div`,{className:`em-s`,children:`Passages appear here once the boat gets under way.`})]}):(0,L.jsx)(`div`,{className:`vy-list`,children:r.list.map((e,t)=>(0,L.jsx)(me,{v:e,prev:r.list[t+1],wasJoined:M.includes(e.id),open:u.includes(e.id),track:x[e.id],fuelNotice:V,fuelMode:C,onFuelMode:w,onToggle:()=>W(e.id),onMerge:R?()=>Z(e.id,()=>R(e.id)):void 0,onUndoMerge:z?()=>Z(e.id,()=>z(e.id)):void 0,editErr:f===e.id?P:null},e.id))})]})]}),O&&E&&(0,L.jsx)(ie,{view:E,onClose:()=>k(!1),onApplied:()=>n(e=>e+1)})]})}function de({v:e}){return(0,L.jsx)(`div`,{className:`vy-active`,children:(0,L.jsxs)(`div`,{className:`vy-active-grid`,children:[(0,L.jsxs)(`div`,{className:`vy-a-hero`,children:[(0,L.jsxs)(`div`,{className:`t`,children:[`Distance · `,(0,L.jsx)(`span`,{className:`sub`,children:`nm`})]}),(0,L.jsx)(`div`,{className:`n`,children:o(e.distance_nm,1)})]}),(0,L.jsxs)(`div`,{className:`vy-a-cell`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Underway`}),(0,L.jsx)(`div`,{className:`v`,children:Z(e.hours_underway)})]}),(0,L.jsxs)(`div`,{className:`vy-a-cell`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Avg SOG`}),(0,L.jsx)(`div`,{className:`v`,children:e.avg_sog_kn===null?`·`:(0,L.jsxs)(L.Fragment,{children:[e.avg_sog_kn.toFixed(1),(0,L.jsx)(`span`,{className:`u`,children:`kn`})]})})]})]})})}function fe({stats:e,loading:t}){let n=(t,n)=>e?n(e[t]):`·`,r=(e,r,i,a=!1)=>(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:`mx-r${a?` mx-hero-r`:``}`,children:[e,r?(0,L.jsxs)(`span`,{className:`mx-u`,children:[`· `,r]}):null]}),Y.map(e=>(0,L.jsx)(`span`,{className:`mx-v${a?` mx-hero`:``}`,children:(0,L.jsx)(`span`,{className:t?`skel`:void 0,children:t?`128.4`:n(e.k,i)})},e.k))]});return(0,L.jsxs)(`div`,{className:`vy-matrix`,children:[(0,L.jsx)(`span`,{className:`mx-corner`,"aria-hidden":`true`}),Y.map(e=>(0,L.jsx)(`span`,{className:`mx-h`,children:e.label},e.k)),r(`Distance`,`nm`,e=>o(e.distance_nm,1),!0),r(`Underway`,null,e=>Z(e.hours_underway)),r(`Avg SOG`,`kn`,e=>e.avg_sog_kn==null?`·`:e.avg_sog_kn.toFixed(1)),r(`Max SOG`,`kn`,e=>e.max_sog_kn==null?`·`:e.max_sog_kn.toFixed(1))]})}function pe({roll:e,loading:t}){let n=t?``:`·`;return(0,L.jsxs)(`div`,{className:`vy-cards`,children:[(0,L.jsxs)(`div`,{className:`c vy-hero`,children:[(0,L.jsxs)(`div`,{className:`t`,children:[`Distance · `,(0,L.jsx)(`span`,{className:`sub`,children:`nm`})]}),(0,L.jsx)(`div`,{className:`n${t?` skel`:``}`,children:t?`128.4`:e?o(e.distance_nm,1):n})]}),(0,L.jsxs)(`div`,{className:`c`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Underway`}),(0,L.jsx)(`div`,{className:`v`,children:e?Z(e.hours_underway):n})]}),(0,L.jsxs)(`div`,{className:`c`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Avg SOG`}),(0,L.jsx)(`div`,{className:`v`,children:e?.avg_sog_kn==null?n:(0,L.jsxs)(L.Fragment,{children:[e.avg_sog_kn.toFixed(1),(0,L.jsx)(`span`,{className:`u`,children:`kn`})]})})]}),(0,L.jsxs)(`div`,{className:`c`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Max SOG`}),(0,L.jsx)(`div`,{className:`v`,children:e?.max_sog_kn==null?n:(0,L.jsxs)(L.Fragment,{children:[e.max_sog_kn.toFixed(1),(0,L.jsx)(`span`,{className:`u`,children:`kn`})]})})]})]})}function me({v:e,prev:t,wasJoined:n,open:r,track:i,fuelNotice:a,fuelMode:s,onFuelMode:c,onToggle:l,onMerge:u,onUndoMerge:d,editErr:p}){let m=e.end_ts===null,h=j(e.fuel_used_l,e.distance_nm,e.hours_underway,s),y=m?`${$(e.start_ts)} →`:`${$(e.start_ts)}-${$(e.end_ts)}`,b=e.avg_sog_kn===null?`·`:`${e.avg_sog_kn.toFixed(1)} kn`,x=le(e);return(0,L.jsxs)(`div`,{className:`vy-rowwrap${r?` open`:``}`,children:[(0,L.jsxs)(`button`,{className:`vy-row`,onClick:l,"aria-expanded":r,children:[(0,L.jsxs)(`div`,{className:`vy-row-top`,children:[(0,L.jsx)(`span`,{className:`vy-date`,children:Q(e.start_ts)}),m&&(0,L.jsx)(`span`,{className:`vy-badge`,children:`Under way`}),(0,L.jsxs)(`span`,{className:`vy-dist`,children:[o(e.distance_nm,1),(0,L.jsx)(`span`,{className:`vy-unit`,children:`nm`})]})]}),x&&(0,L.jsx)(`div`,{className:`vy-route`,children:x}),(0,L.jsxs)(`div`,{className:`vy-row-sub`,children:[y,` · `,Z(e.hours_underway),` · `,b]})]}),r&&(0,L.jsxs)(`div`,{className:`vy-detail`,children:[i&&i.length>=2?(0,L.jsx)(V,{track:i}):(0,L.jsx)(`div`,{className:`vy-track-empty`,children:i?`Track too short to plot`:`Loading track…`}),(0,L.jsxs)(`div`,{className:`vy-meta`,children:[(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`From`}),e.start_port&&(0,L.jsx)(`span`,{className:`val`,children:e.start_port}),(0,L.jsxs)(`span`,{className:e.start_port?`coord`:`val`,children:[f(e.start_lat,[`N`,`S`],2),` · `,f(e.start_lon,[`E`,`W`],2)]})]}),(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`To`}),m?(0,L.jsx)(`span`,{className:`val`,children:`-`}):(0,L.jsxs)(L.Fragment,{children:[e.end_port&&(0,L.jsx)(`span`,{className:`val`,children:e.end_port}),(0,L.jsxs)(`span`,{className:e.end_port?`coord`:`val`,children:[f(e.end_lat,[`N`,`S`],2),` · `,f(e.end_lon,[`E`,`W`],2)]})]})]}),(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Avg SOG`}),(0,L.jsx)(`span`,{className:`val`,children:e.avg_sog_kn===null?`·`:`${e.avg_sog_kn.toFixed(1)} kn`})]}),(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Max SOG`}),(0,L.jsx)(`span`,{className:`val`,children:e.max_sog_kn===null?`·`:`${e.max_sog_kn.toFixed(1)} kn`})]}),e.fuel_used_l===null&&a&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-fuel`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Fuel`}),(0,L.jsx)(`span`,{className:`val vy-fuel-quiet`,children:a})]}),e.fuel_used_l!==null&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-fuel`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Fuel`}),(0,L.jsx)(`span`,{className:`val`,children:h??`·`}),(0,L.jsx)(`select`,{className:`vy-fuel-sel`,value:s,"aria-label":`Fuel unit`,onChange:e=>c(e.target.value),children:E.map(e=>(0,L.jsx)(`option`,{value:e.mode,children:e.label},e.mode))})]}),i&&i.length>0&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-track`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Track`}),(0,L.jsxs)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:()=>g(_(`siparu-voyage-${e.id}`,e.start_ts,`gpx`),`application/gpx+xml`,v(e,i)),children:[`GPX · `,i.length,` fixes`]})]}),!m&&u&&d&&(n||t)&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-edit`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Passage`}),n?(0,L.jsx)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:d,children:`Separate again`}):(0,L.jsxs)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:u,children:[`Join to `,$(t.start_ts),t.end_ts===null?``:`-${$(t.end_ts)}`,` · `,Q(t.start_ts)]})]}),p&&(0,L.jsx)(`div`,{className:`vy-m vy-m-editerr`,children:p})]})]})]})}function he(){return(0,L.jsx)(ue,{})}export{he as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-CaR_m4Xc.js";import{I as r,N as i,a,b as o,f as s,h as c,j as l,m as u,r as d,y as f}from"./index-BeY0LLy7.js";import{a as p,c as m,i as h,n as g,r as _,s as v}from"./export-CGdOfqNp.js";import{a as y,i as b,n as x,o as S,s as C,t as w}from"./style-D1uNa2dX.js";var T=e(t(),1),E=[{mode:`total_l`,label:`Litres`},{mode:`total_usgal`,label:`US gallons`},{mode:`total_impgal`,label:`Imp gallons`},{mode:`per_nm`,label:`Litres / nm`},{mode:`nm_per_l`,label:`nm / L`},{mode:`per_hour`,label:`Litres / hour`}],D=.26417205,O=.21996923,k=1e-6;function A(e,t,n){return`${e.toFixed(n)} ${t}`}function j(e,t,n,r){if(e===null||!Number.isFinite(e))return null;switch(r){case`total_l`:return A(e,`L`,+(e<100));case`total_usgal`:return A(e*D,`US gal`,1);case`total_impgal`:return A(e*O,`Imp gal`,1);case`per_nm`:return t>k?A(e/t,`L/nm`,2):null;case`nm_per_l`:return e>k?A(t/e,`nm/L`,2):null;case`per_hour`:return n>k?A(e/n,`L/h`,1):null}}var M=`Could not load voyage data`;function N(e){return e instanceof l?e.detail||M:e instanceof DOMException&&e.name===`TimeoutError`?`She did not answer in time`:M}function ee(e=0){let t=i(),{data:n,error:r}=u(t.voyage.current,6e4,[e],`voyage:current`),[a,o]=(0,T.useState)(null),[s,l]=(0,T.useState)([]),[d,f]=(0,T.useState)(!0),[p,m]=(0,T.useState)(null);return(0,T.useEffect)(()=>{let e=!1;return(async()=>{try{let[n,r]=await Promise.all([t.voyage.stats(),t.voyage.list(50)]);e||(o(n),l(r),m(null))}catch(t){e||m(N(t))}finally{e||f(!1)}})(),()=>{e=!0}},[e]),{current:n??null,currentStale:r!==null,currentSeenTs:c(`voyage:current`),stats:a,list:s,loading:d,err:p}}var P=e(C(),1),F=new Set;function I(e){return F.add(e),()=>{F.delete(e)}}async function te(){await Promise.all([...F].map(e=>e().catch(()=>void 0)))}var L=n();function R(e,t){let n=(t.querySelector(`.maplibregl-ctrl-attrib-inner`)?.textContent??``).replace(w,``).replace(/^\s*\|\s*/,``).trim();return(e.loaded()?Promise.resolve():new Promise(t=>{let n=setTimeout(t,1500);e.once(`idle`,()=>{clearTimeout(n),t()})})).then(()=>new Promise((t,r)=>{let i=setTimeout(()=>r(Error(`the map did not draw`)),2e3);e.once(`render`,()=>{clearTimeout(i);try{t({url:e.getCanvas().toDataURL(`image/png`),credit:n})}catch(e){r(e)}}),e.triggerRepaint()}))}function z(){return document.documentElement.dataset.theme===`day`?`day`:`night`}function B(e,t){let n=document.createElement(`div`);return n.style.cssText=`width:10px;height:10px;border-radius:50%;border:2px solid ${e};background:${t?e:`transparent`};`,n}function V({track:e}){let t=i(),n=(0,T.useRef)(null),r=(0,T.useRef)(null),[a,o]=(0,T.useState)(null);return(0,T.useEffect)(()=>{if(!n.current||r.current)return;let i=n.current,a=document.documentElement,s=getComputedStyle(a).getPropertyValue(`--accent`).trim()||`#e5484d`,c=!1,l=null,u=null,d=null;return(async()=>{y();let n=await S(t);if(c)return;let f=()=>b(z(),n,{track:{color:s,width:3}}),p=e.filter(e=>e.lat!==null&&e.lon!==null).map(e=>[e.lon,e.lat]);l=new P.default.Map({container:i,style:f(),center:[7.42,43.7],zoom:9,attributionControl:{compact:!1,customAttribution:w},dragRotate:!1,pitchWithRotate:!1}),l.touchZoomRotate.disableRotation(),r.current=l;let m=l;d=I(async()=>{let e=await R(m,i);c||o(e)});let h=()=>{if(!l)return;let e=l.getSource(x);e&&p.length>=2&&e.setData({type:`FeatureCollection`,features:[{type:`Feature`,properties:{},geometry:{type:`LineString`,coordinates:p}}]})};if(l.on(`style.load`,h),h(),p.length>=2){new P.default.Marker({element:B(s,!1),anchor:`center`}).setLngLat(p[0]).addTo(l),new P.default.Marker({element:B(s,!0),anchor:`center`}).setLngLat(p[p.length-1]).addTo(l);let e=new P.default.LngLatBounds;for(let t of p)e.extend(t);l.fitBounds(e,{padding:22,maxZoom:15,animate:!1})}u=new MutationObserver(()=>{l?.setStyle(f()),h()}),u.observe(a,{attributes:!0,attributeFilter:[`data-theme`]})})(),()=>{c=!0,d?.(),u?.disconnect(),l?.remove(),r.current=null}},[e]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{ref:n,className:`vy-map`}),a&&(0,L.jsxs)(`figure`,{className:`vy-map-print`,"aria-hidden":`true`,children:[(0,L.jsx)(`img`,{src:a.url,alt:``}),(0,L.jsx)(`figcaption`,{children:a.credit})]})]})}function H(e,t,n=3){if(e.includes(t))return e.filter(e=>e!==t);let r=[...e,t];return r.length>n?r.slice(r.length-n):r}var U=e(r(),1);function W(e){let t=e.match(/^propulsion\.([^.]+)\.fuel\.rate$/),n=t?t[1]:e;return n.charAt(0).toUpperCase()+n.slice(1)}function G(e){let t=new Set(e.available);return e.selected.filter(e=>!t.has(e))}function ne(e){return e.available.length>1||e.selected.length>0}function K(e){return[...e.available.map(e=>({path:e,reporting:!0})),...G(e).map(e=>({path:e,reporting:!1}))]}function q(e){let t=G(e);return t.length===0||t.length<e.selected.length?null:`No fuel counted: ${t.map(W).join(`, `)} is selected but not reporting a rate.`}function re(e){let t=G(e);return t.length>0&&t.length===e.selected.length?`${t.length===1?W(t[0]):`${t.length} engines`} · not reporting`:e.selected.length===0?`All`:e.selected.length===1?W(e.selected[0]):`${e.selected.length} engines`}function ie({view:e,onClose:t,onApplied:n}){let r=i(),[o,s]=(0,T.useState)(()=>new Set(e.selected)),[c,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(null),p=(0,T.useRef)(null),m=e=>{f(null),s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=async()=>{let e=[...o].sort();u(!0),f(null);try{if(!r.config.setFuelPaths)throw Error(`this setting is written aboard`);await r.config.setFuelPaths(e);let t=e.join(`,`);for(let e=0;e<12;e++){await new Promise(e=>setTimeout(e,700));try{if([...(await r.config.fuelPaths()).selected].sort().join(`,`)===t)break}catch{}}n(),p.current?.()}catch(e){e instanceof l?f(e.code===`security_off`?`Signal K security is off, so the fuel source is locked. Add an admin user in Signal K.`:e.detail||`Could not apply the change`):f(e instanceof Error?e.message:`Could not apply the change`),u(!1)}},g=q(e),_=document.querySelector(`.swiss.sp-screen`)??document.body;return(0,U.createPortal)((0,L.jsxs)(a,{title:`Fuel source`,eyebrow:`voyage fuel`,onClose:t,closeRef:p,footer:(0,L.jsx)(`button`,{type:`button`,className:`fs-apply`,onClick:h,disabled:c,children:c?`Applying…`:`Apply`}),children:[(0,L.jsx)(`p`,{className:`fs-note`,children:`Which engines count toward voyage fuel. With none selected, every reporting engine is summed.`}),g&&(0,L.jsx)(`div`,{className:`fs-quiet`,children:g}),(0,L.jsx)(`div`,{className:`fs-list`,role:`group`,"aria-label":`Fuel-rate sources`,children:K(e).map(({path:e,reporting:t})=>{let n=o.has(e);return(0,L.jsxs)(`button`,{type:`button`,className:`fs-row${n?` on`:``}${t?``:` off-air`}`,role:`checkbox`,"aria-checked":n,onClick:()=>m(e),disabled:c,children:[(0,L.jsxs)(`span`,{className:`fs-name`,children:[W(e),!t&&(0,L.jsx)(`span`,{className:`fs-tag`,children:` not reporting`})]}),(0,L.jsx)(`span`,{className:`fs-path`,children:e})]},e)})}),d&&(0,L.jsx)(`div`,{className:`fs-err`,children:d})]}),_)}var J=`siparu.fuelMode`;function ae(){let e=localStorage.getItem(J);return E.some(t=>t.mode===e)?e:`total_l`}var oe=`(min-width: 1000px)`,Y=[{k:`today`,label:`Today`},{k:`yesterday`,label:`Yesterday`},{k:`rolling_7d`,label:`7 days`},{k:`season`,label:`Season`}],X={not_found:`That passage is no longer in the log.`,no_previous:`There is no earlier passage to join this one to.`,voyage_open:`This passage is still being recorded. It can be edited once it ends.`,nothing_to_undo:`This passage was not joined by hand.`,admin_required:`Sign in to Signal K as an administrator to edit the log.`,security_off:`Signal K security is off, so the log is locked. Add an admin user in Signal K.`};function Z(e){if(e===null||e<=0)return`·`;let t=Math.round(e*60),n=Math.floor(t/60),r=t%60;return n>0?`${n}h ${r}m`:`${r}m`}function Q(e){return new Date(e).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`})}function se(e){let{value:t,unit:n}=d((Date.now()-e)/1e3);return`${t}${n===`s`?`s`:` ${n}`} ago`}function ce(){return new Promise(e=>{let t=setTimeout(e,300);requestAnimationFrame(()=>setTimeout(()=>{clearTimeout(t),e()},0))})}function $(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}`}function le(e){return!e.start_port&&!e.end_port?null:e.end_ts===null?e.start_port?`${e.start_port} →`:null:`${e.start_port??`·`} → ${e.end_port??`·`}`}function ue(){let e=i(),[t,n]=(0,T.useState)(0),r=ee(t),a=s(oe),[o,c]=(0,T.useState)(`today`),[u,d]=(0,T.useState)([]),[f,v]=(0,T.useState)(null),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)({}),[C,w]=(0,T.useState)(ae),[E,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(!1),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)([]),[P,F]=(0,T.useState)(null);(0,T.useEffect)(()=>{localStorage.setItem(J,C)},[C]),(0,T.useEffect)(()=>{let t=!0;return e.health().then(e=>{t&&j(e.boat_name)}).catch(()=>{}),()=>{t=!1}},[]);let I=e.voyage.edits,R=e.voyage.mergePrevious,z=e.voyage.undoMerge;(0,T.useEffect)(()=>{if(!I)return;let e=!0;return I().then(t=>{e&&N(t.merged)}).catch(()=>{}),()=>{e=!1}},[t,I]),(0,T.useEffect)(()=>{let t=!1;return e.config.fuelPaths().then(e=>!t&&D(e)).catch(()=>{}),()=>{t=!0}},[t]);let B=!!E&&ne(E)&&e.config.setFuelPaths!==void 0,V=E?q(E):null,U=r.current&&r.current.end_ts===null?r.current:null,W=async t=>{let n=u.includes(t);if(d(e=>H(e,t)),!n&&!x[t])try{let n=await e.voyage.track(t);S(e=>({...e,[t]:n}))}catch{}},G=r.stats?.[o]??null,K=async e=>{b(!1),await te(),await ce(),h(p(`Siparu-Voyage`,Date.now()),e)},Z=async(e,t)=>{F(null),v(e);try{let e=await t();if(!e.ok){F(X[e.error??``]??`That edit could not be made.`);return}d([]),S({}),n(e=>e+1)}catch(e){e instanceof l?F(X[e.code??``]??(e.detail||`That edit could not be made.`)):F(`The boat did not answer.`)}};return(0,L.jsxs)(`div`,{className:`vy`,children:[(0,L.jsxs)(`div`,{className:`vy-print-hd`,"aria-hidden":`true`,children:[(0,L.jsx)(`span`,{className:`b`,children:A??`Passage record`}),(0,L.jsx)(`span`,{className:`d`,children:new Date().toISOString().slice(0,10)})]}),U&&(0,L.jsxs)(`section`,{className:`sp-sec vy-sec-active`,children:[(0,L.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,L.jsx)(`span`,{className:`sp-sec-n`,children:`Under way`}),U.start_port?(0,L.jsxs)(`span`,{className:`sp-sec-note`,children:[`from `,U.start_port]}):null,r.currentStale?(0,L.jsxs)(`span`,{className:`sp-sec-badge quiet`,children:[`since `,$(U.start_ts),r.currentSeenTs===null?` · unreachable`:` · last seen ${se(r.currentSeenTs)}`]}):(0,L.jsxs)(`span`,{className:`sp-sec-badge`,children:[(0,L.jsx)(`span`,{className:`vy-pulse`,"aria-hidden":`true`}),`since `,$(U.start_ts)]})]}),(0,L.jsx)(`div`,{className:`sp-glass`,children:(0,L.jsx)(de,{v:U})})]}),(0,L.jsxs)(`section`,{className:`sp-sec vy-sec-totals`,children:[(0,L.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,L.jsx)(`span`,{className:`sp-sec-n`,children:`Totals`}),!a&&(0,L.jsx)(`span`,{className:`sp-sec-note`,children:Y.find(e=>e.k===o)?.label.toLowerCase()}),r.err?(0,L.jsx)(`span`,{className:`sp-sec-badge quiet`,children:`unreachable`}):null]}),(0,L.jsx)(`div`,{className:`sp-glass`,children:a?(0,L.jsx)(fe,{stats:r.stats,loading:r.loading}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`vy-seg seg`,role:`group`,"aria-label":`Stats window`,children:Y.map(e=>(0,L.jsx)(`button`,{className:o===e.k?`on`:``,onClick:()=>c(e.k),children:e.label},e.k))}),(0,L.jsx)(pe,{roll:G,loading:r.loading})]})})]}),(0,L.jsxs)(`section`,{className:`sp-sec vy-sec-voyages`,children:[(0,L.jsxs)(`h2`,{className:`sp-sec-h`,children:[(0,L.jsx)(`span`,{className:`sp-sec-n`,children:`Voyages`}),r.err?(0,L.jsx)(`span`,{className:`sp-sec-badge quiet`,children:`unreachable`}):r.loading&&r.list.length===0?null:(0,L.jsx)(`span`,{className:`sp-sec-badge`,children:r.list.length===50?`50 shown`:r.list.length})]}),(0,L.jsxs)(`div`,{className:`sp-glass`,children:[(B||r.list.length>0)&&(0,L.jsx)(`div`,{className:`vy-hd`,children:(0,L.jsxs)(`span`,{className:`vy-hd-acts`,children:[B&&(0,L.jsxs)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:()=>k(!0),children:[`Fuel · `,re(E)]}),r.list.length>0&&(0,L.jsx)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:()=>g(_(`siparu-voyages`,Date.now(),`csv`),`text/csv`,m(r.list)),children:`CSV`}),r.list.length>0&&y&&(0,L.jsxs)(`span`,{className:`vy-print-pick`,role:`group`,"aria-label":`Page style`,children:[(0,L.jsx)(`button`,{type:`button`,className:`lbp-c`,onClick:()=>K(`paper`),children:`Paper`}),(0,L.jsx)(`button`,{type:`button`,className:`lbp-c`,onClick:()=>K(`screen`),children:`Screen`})]}),r.list.length>0&&(0,L.jsx)(`button`,{type:`button`,className:`vy-fuelsrc${y?` on`:``}`,"aria-expanded":y,onClick:()=>b(e=>!e),children:`Print`})]})}),r.err?(0,L.jsx)(`div`,{className:`vy-err`,children:r.err}):!r.loading&&r.list.length===0?(0,L.jsxs)(`div`,{className:`sp-empty`,children:[(0,L.jsx)(`div`,{className:`em-t`,children:`No voyages yet`}),(0,L.jsx)(`div`,{className:`em-s`,children:`Passages appear here once the boat gets under way.`})]}):(0,L.jsx)(`div`,{className:`vy-list`,children:r.list.map((e,t)=>(0,L.jsx)(me,{v:e,prev:r.list[t+1],wasJoined:M.includes(e.id),open:u.includes(e.id),track:x[e.id],fuelNotice:V,fuelMode:C,onFuelMode:w,onToggle:()=>W(e.id),onMerge:R?()=>Z(e.id,()=>R(e.id)):void 0,onUndoMerge:z?()=>Z(e.id,()=>z(e.id)):void 0,editErr:f===e.id?P:null},e.id))})]})]}),O&&E&&(0,L.jsx)(ie,{view:E,onClose:()=>k(!1),onApplied:()=>n(e=>e+1)})]})}function de({v:e}){return(0,L.jsx)(`div`,{className:`vy-active`,children:(0,L.jsxs)(`div`,{className:`vy-active-grid`,children:[(0,L.jsxs)(`div`,{className:`vy-a-hero`,children:[(0,L.jsxs)(`div`,{className:`t`,children:[`Distance · `,(0,L.jsx)(`span`,{className:`sub`,children:`nm`})]}),(0,L.jsx)(`div`,{className:`n`,children:o(e.distance_nm,1)})]}),(0,L.jsxs)(`div`,{className:`vy-a-cell`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Underway`}),(0,L.jsx)(`div`,{className:`v`,children:Z(e.hours_underway)})]}),(0,L.jsxs)(`div`,{className:`vy-a-cell`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Avg SOG`}),(0,L.jsx)(`div`,{className:`v`,children:e.avg_sog_kn===null?`·`:(0,L.jsxs)(L.Fragment,{children:[e.avg_sog_kn.toFixed(1),(0,L.jsx)(`span`,{className:`u`,children:`kn`})]})})]})]})})}function fe({stats:e,loading:t}){let n=(t,n)=>e?n(e[t]):`·`,r=(e,r,i,a=!1)=>(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`span`,{className:`mx-r${a?` mx-hero-r`:``}`,children:[e,r?(0,L.jsxs)(`span`,{className:`mx-u`,children:[`· `,r]}):null]}),Y.map(e=>(0,L.jsx)(`span`,{className:`mx-v${a?` mx-hero`:``}`,children:(0,L.jsx)(`span`,{className:t?`skel`:void 0,children:t?`128.4`:n(e.k,i)})},e.k))]});return(0,L.jsxs)(`div`,{className:`vy-matrix`,children:[(0,L.jsx)(`span`,{className:`mx-corner`,"aria-hidden":`true`}),Y.map(e=>(0,L.jsx)(`span`,{className:`mx-h`,children:e.label},e.k)),r(`Distance`,`nm`,e=>o(e.distance_nm,1),!0),r(`Underway`,null,e=>Z(e.hours_underway)),r(`Avg SOG`,`kn`,e=>e.avg_sog_kn==null?`·`:e.avg_sog_kn.toFixed(1)),r(`Max SOG`,`kn`,e=>e.max_sog_kn==null?`·`:e.max_sog_kn.toFixed(1))]})}function pe({roll:e,loading:t}){let n=t?``:`·`;return(0,L.jsxs)(`div`,{className:`vy-cards`,children:[(0,L.jsxs)(`div`,{className:`c vy-hero`,children:[(0,L.jsxs)(`div`,{className:`t`,children:[`Distance · `,(0,L.jsx)(`span`,{className:`sub`,children:`nm`})]}),(0,L.jsx)(`div`,{className:`n${t?` skel`:``}`,children:t?`128.4`:e?o(e.distance_nm,1):n})]}),(0,L.jsxs)(`div`,{className:`c`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Underway`}),(0,L.jsx)(`div`,{className:`v`,children:e?Z(e.hours_underway):n})]}),(0,L.jsxs)(`div`,{className:`c`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Avg SOG`}),(0,L.jsx)(`div`,{className:`v`,children:e?.avg_sog_kn==null?n:(0,L.jsxs)(L.Fragment,{children:[e.avg_sog_kn.toFixed(1),(0,L.jsx)(`span`,{className:`u`,children:`kn`})]})})]}),(0,L.jsxs)(`div`,{className:`c`,children:[(0,L.jsx)(`div`,{className:`t`,children:`Max SOG`}),(0,L.jsx)(`div`,{className:`v`,children:e?.max_sog_kn==null?n:(0,L.jsxs)(L.Fragment,{children:[e.max_sog_kn.toFixed(1),(0,L.jsx)(`span`,{className:`u`,children:`kn`})]})})]})]})}function me({v:e,prev:t,wasJoined:n,open:r,track:i,fuelNotice:a,fuelMode:s,onFuelMode:c,onToggle:l,onMerge:u,onUndoMerge:d,editErr:p}){let m=e.end_ts===null,h=j(e.fuel_used_l,e.distance_nm,e.hours_underway,s),y=m?`${$(e.start_ts)} →`:`${$(e.start_ts)}-${$(e.end_ts)}`,b=e.avg_sog_kn===null?`·`:`${e.avg_sog_kn.toFixed(1)} kn`,x=le(e);return(0,L.jsxs)(`div`,{className:`vy-rowwrap${r?` open`:``}`,children:[(0,L.jsxs)(`button`,{className:`vy-row`,onClick:l,"aria-expanded":r,children:[(0,L.jsxs)(`div`,{className:`vy-row-top`,children:[(0,L.jsx)(`span`,{className:`vy-date`,children:Q(e.start_ts)}),m&&(0,L.jsx)(`span`,{className:`vy-badge`,children:`Under way`}),(0,L.jsxs)(`span`,{className:`vy-dist`,children:[o(e.distance_nm,1),(0,L.jsx)(`span`,{className:`vy-unit`,children:`nm`})]})]}),x&&(0,L.jsx)(`div`,{className:`vy-route`,children:x}),(0,L.jsxs)(`div`,{className:`vy-row-sub`,children:[y,` · `,Z(e.hours_underway),` · `,b]})]}),r&&(0,L.jsxs)(`div`,{className:`vy-detail`,children:[i&&i.length>=2?(0,L.jsx)(V,{track:i}):(0,L.jsx)(`div`,{className:`vy-track-empty`,children:i?`Track too short to plot`:`Loading track…`}),(0,L.jsxs)(`div`,{className:`vy-meta`,children:[(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`From`}),e.start_port&&(0,L.jsx)(`span`,{className:`val`,children:e.start_port}),(0,L.jsxs)(`span`,{className:e.start_port?`coord`:`val`,children:[f(e.start_lat,[`N`,`S`],2),` · `,f(e.start_lon,[`E`,`W`],2)]})]}),(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`To`}),m?(0,L.jsx)(`span`,{className:`val`,children:`-`}):(0,L.jsxs)(L.Fragment,{children:[e.end_port&&(0,L.jsx)(`span`,{className:`val`,children:e.end_port}),(0,L.jsxs)(`span`,{className:e.end_port?`coord`:`val`,children:[f(e.end_lat,[`N`,`S`],2),` · `,f(e.end_lon,[`E`,`W`],2)]})]})]}),(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Avg SOG`}),(0,L.jsx)(`span`,{className:`val`,children:e.avg_sog_kn===null?`·`:`${e.avg_sog_kn.toFixed(1)} kn`})]}),(0,L.jsxs)(`div`,{className:`vy-m`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Max SOG`}),(0,L.jsx)(`span`,{className:`val`,children:e.max_sog_kn===null?`·`:`${e.max_sog_kn.toFixed(1)} kn`})]}),e.fuel_used_l===null&&a&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-fuel`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Fuel`}),(0,L.jsx)(`span`,{className:`val vy-fuel-quiet`,children:a})]}),e.fuel_used_l!==null&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-fuel`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Fuel`}),(0,L.jsx)(`span`,{className:`val`,children:h??`·`}),(0,L.jsx)(`select`,{className:`vy-fuel-sel`,value:s,"aria-label":`Fuel unit`,onChange:e=>c(e.target.value),children:E.map(e=>(0,L.jsx)(`option`,{value:e.mode,children:e.label},e.mode))})]}),i&&i.length>0&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-track`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Track`}),(0,L.jsxs)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:()=>g(_(`siparu-voyage-${e.id}`,e.start_ts,`gpx`),`application/gpx+xml`,v(e,i)),children:[`GPX · `,i.length,` fixes`]})]}),!m&&u&&d&&(n||t)&&(0,L.jsxs)(`div`,{className:`vy-m vy-m-edit`,children:[(0,L.jsx)(`span`,{className:`k`,children:`Passage`}),n?(0,L.jsx)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:d,children:`Separate again`}):(0,L.jsxs)(`button`,{type:`button`,className:`vy-fuelsrc`,onClick:u,children:[`Join to `,$(t.start_ts),t.end_ts===null?``:`-${$(t.end_ts)}`,` · `,Q(t.start_ts)]})]}),p&&(0,L.jsx)(`div`,{className:`vy-m vy-m-editerr`,children:p})]})]})]})}function he(){return(0,L.jsx)(ue,{})}export{he as default};