signalk-ais-navionics-converter 1.0.1 → 1.0.3

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.
@@ -0,0 +1,864 @@
1
+ import React, { useState, useEffect } from 'react';
2
+
3
+ const PluginConfigurationPanel = ({ configuration, save }) => {
4
+ const [config, setConfig] = useState(configuration || {});
5
+ const [initialConfig, setInitialConfig] = useState(configuration);
6
+ const [loading, setLoading] = useState(false);
7
+ const [status, setStatus] = useState('');
8
+ const [showDialog, setShowDialog] = useState(false);
9
+ const [dialogData, setDialogData] = useState({ title: '', message: '', callback: null });
10
+ const [ownMMSI, setOwnMMSI] = useState(null);
11
+ const [aisfleetEnabled, setAisfleetEnabled] = useState(false);
12
+ const [portError, setPortError] = useState('');
13
+
14
+ const translations = {
15
+ de: {
16
+ general: 'Allgemein',
17
+ tcpServer: 'TCP Server',
18
+ filtering: 'Filterung',
19
+ debugging: 'Debugging',
20
+ vesselFinder: 'VesselFinder',
21
+ cloudVessels: 'Cloud Vessels (AISFleet)',
22
+
23
+ tcpPort: 'TCP Port:',
24
+ wsPort: 'WebSocket Port:',
25
+ updateInterval: 'Update-Intervall für geänderte Schiffe (Sekunden):',
26
+ tcpResendInterval: 'Update-Intervall für unveränderte Schiffe (Sekunden):',
27
+
28
+ skipWithoutCallsign: 'Schiffe ohne Rufzeichen überspringen',
29
+ skipStaleData: 'Schiffe mit alten Daten überspringen',
30
+ staleDataThreshold: 'Schwellenwert für alte Daten (Minuten):',
31
+ staleDataShipname: 'Zeitstempel zum Schiffsnamen hinzufügen wenn die letzte Positionsmeldung älter ist als x Minuten (0=deaktiviert):',
32
+
33
+ minAlarmSOG: 'SOG (und COG) wird auf 0 gesetzt, wenn die Geschwindigkeit kleiner als x Knoten ist (0=deaktiviert):',
34
+ maxMinutesSOGToZero: 'SOG wird auf 0 gesetzt wenn die letzte Positionsmeldung älter ist als x Minuten (0=keine Korrektur):',
35
+
36
+ logDebugDetails: 'Debug Schiff-Details',
37
+ logMMSI: 'Filter Debug-Ausgabe nur für MMSI:',
38
+ logDebugStale: 'Debug alte Schiffe',
39
+ logDebugJSON: 'Debug JSON-Daten',
40
+ logDebugAIS: 'Debug AIS-Daten',
41
+ logDebugSOG: 'Debug Schiffe mit korrigierter SOG',
42
+
43
+ vesselFinderEnabled: 'VesselFinder-Weiterleitung aktivieren',
44
+ vesselFinderHost: 'VesselFinder Host:',
45
+ vesselFinderPort: 'VesselFinder UDP Port:',
46
+ vesselFinderUpdateRate: 'VesselFinder Update Rate (Sekunden):',
47
+
48
+ cloudVesselsEnabled: 'Schiffe von AISFleet.com einbeziehen',
49
+ cloudVesselsUpdateInterval: 'Cloud Vessels Update-Intervall (Sekunden):',
50
+ cloudVesselsRadius: 'Radius von eigenem Schiff (Seemeilen):',
51
+
52
+ portError: 'TCP Port und WebSocket Port müssen unterschiedlich sein',
53
+
54
+ save: 'Speichern',
55
+ cancel: 'Abbruch',
56
+ unsavedWarning: 'Es gibt ungespeicherte Änderungen. Wirklich abbrechen?',
57
+ unsavedTitle: 'Ungespeicherte Änderungen',
58
+ yes: 'Ja',
59
+ no: 'Nein'
60
+ },
61
+ en: {
62
+ general: 'General',
63
+ tcpServer: 'TCP Server',
64
+ filtering: 'Filtering',
65
+ debugging: 'Debugging',
66
+ vesselFinder: 'VesselFinder',
67
+ cloudVessels: 'Cloud Vessels (AISFleet)',
68
+
69
+ tcpPort: 'TCP Port:',
70
+ wsPort: 'WebSocket Port:',
71
+ updateInterval: 'Update interval for changed vessels (seconds):',
72
+ tcpResendInterval: 'Update interval for unchanged vessels (seconds):',
73
+
74
+ skipWithoutCallsign: 'Skip vessels without callsign',
75
+ skipStaleData: 'Skip vessels with stale data',
76
+ staleDataThreshold: 'Stale data threshold (minutes):',
77
+ staleDataShipname: 'Add timestamp to vessel name if the last position report is older than x minutes (0=disabled):',
78
+
79
+ minAlarmSOG: 'SOG (and COG) is set to 0 if the speed is less than x knots (0=disabled):',
80
+ maxMinutesSOGToZero: 'SOG is set to 0 if the last position report is older than x minutes (0=no correction):',
81
+
82
+ logDebugDetails: 'Debug vessel details',
83
+ logMMSI: 'Filter Debug only for MMSI:',
84
+ logDebugStale: 'Debug stale vessels',
85
+ logDebugJSON: 'Debug JSON data',
86
+ logDebugAIS: 'Debug AIS data',
87
+ logDebugSOG: 'Debug vessels with corrected SOG',
88
+
89
+ vesselFinderEnabled: 'Enable VesselFinder forwarding',
90
+ vesselFinderHost: 'VesselFinder Host:',
91
+ vesselFinderPort: 'VesselFinder UDP Port:',
92
+ vesselFinderUpdateRate: 'VesselFinder Update Rate (seconds):',
93
+
94
+ cloudVesselsEnabled: 'Include vessels from AISFleet.com',
95
+ cloudVesselsUpdateInterval: 'Cloud Vessels update interval (seconds):',
96
+ cloudVesselsRadius: 'Radius from own vessel (nautical miles):',
97
+
98
+ portError: 'TCP Port and WebSocket Port must be different',
99
+
100
+ save: 'Save',
101
+ cancel: 'Cancel',
102
+ unsavedWarning: 'There are unsaved changes. Really cancel?',
103
+ unsavedTitle: 'Unsaved changes',
104
+ yes: 'Yes',
105
+ no: 'No'
106
+ }
107
+ };
108
+
109
+ const [currentLang, setCurrentLang] = useState(config.language === 'de' ? 'de' : 'en');
110
+ const t = translations[currentLang];
111
+
112
+ // Hole eigene MMSI beim Laden
113
+ useEffect(() => {
114
+ const fetchOwnMMSI = async () => {
115
+ try {
116
+ const protocol = window.location.protocol;
117
+ const hostname = window.location.hostname;
118
+ const port = window.location.port;
119
+ const baseUrl = `${protocol}//${hostname}${port ? ':' + port : ''}`;
120
+ const aisfleetUrl = `${baseUrl}/plugins/aisfleet`;
121
+ const url = `${baseUrl}/signalk/v1/api/self`;
122
+
123
+ const response = await fetch(url);
124
+ if (response.ok) {
125
+ const data = await response.json();
126
+ let vesselKey = null;
127
+
128
+ if (typeof data === 'string') {
129
+ vesselKey = data.replace('vessels.', '');
130
+ } else if (data.vessels && typeof data.vessels === 'object') {
131
+ const mmsiMatch = Object.keys(data.vessels).find(key => key.includes('mmsi:'));
132
+ vesselKey = mmsiMatch;
133
+ }
134
+
135
+ if (vesselKey) {
136
+ const mmsi = vesselKey.match(/mmsi:(\d+)/)?.[1];
137
+ if (mmsi) setOwnMMSI(mmsi);
138
+ }
139
+ }
140
+
141
+ // AIS Fleet Plugin prüfen
142
+ try {
143
+ const aisResponse = await fetch(aisfleetUrl);
144
+ if (aisResponse.ok) {
145
+ const aisData = await aisResponse.json();
146
+ setAisfleetEnabled(!!aisData.enabled);
147
+ } else {
148
+ setAisfleetEnabled(false);
149
+ }
150
+ } catch (err) {
151
+ setAisfleetEnabled(false);
152
+ }
153
+ } catch (err) {
154
+ console.error('Failed to fetch own MMSI:', err);
155
+ }
156
+ };
157
+
158
+ setTimeout(fetchOwnMMSI, 500);
159
+ }, []);
160
+
161
+ const handleConfigChange = (key, value) => {
162
+ setConfig(prev => ({ ...prev, [key]: value }));
163
+
164
+ // Überprüfe Port-Nummern
165
+ if (key === 'tcpPort' || key === 'wsPort') {
166
+ const tcpPort = key === 'tcpPort' ? value : config.tcpPort;
167
+ const wsPort = key === 'wsPort' ? value : config.wsPort;
168
+
169
+ if (tcpPort && wsPort && tcpPort !== 0 && wsPort !== 0 && tcpPort === wsPort) {
170
+ setPortError(t.portError);
171
+ } else {
172
+ setPortError('');
173
+ }
174
+ }
175
+ };
176
+
177
+ const isMMSIInvalid = () => {
178
+ return ownMMSI && config.logMMSI && config.logMMSI === ownMMSI;
179
+ };
180
+
181
+ const isPortInvalid = () => {
182
+ const tcpPort = config.tcpPort || 10113;
183
+ const wsPort = config.wsPort || 10114;
184
+ return tcpPort !== 0 && wsPort !== 0 && tcpPort === wsPort;
185
+ };
186
+
187
+ const checkUnsavedChanges = () => {
188
+ return JSON.stringify(config) !== JSON.stringify(initialConfig);
189
+ };
190
+
191
+ const handleSave = () => {
192
+ // Validiere Debug MMSI
193
+ if (isMMSIInvalid()) {
194
+ setStatus('error');
195
+ const errorMsg = currentLang === 'de'
196
+ ? 'Fehler: Sie können nicht die eigene MMSI zum Filtern verwenden!'
197
+ : 'Error: You cannot use your own MMSI for filtering!';
198
+ alert(errorMsg);
199
+ return;
200
+ }
201
+
202
+ // Validiere Ports
203
+ if (isPortInvalid()) {
204
+ setStatus('error');
205
+ const errorMsg = currentLang === 'de'
206
+ ? 'Fehler: TCP Port und WebSocket Port müssen unterschiedlich sein!'
207
+ : 'Error: TCP Port and WebSocket Port must be different!';
208
+ alert(errorMsg);
209
+ return;
210
+ }
211
+
212
+ setLoading(true);
213
+ if (save) {
214
+ try {
215
+ const result = save(config);
216
+
217
+ if (result && typeof result.then === 'function') {
218
+ result
219
+ .then(() => {
220
+ setStatus('success');
221
+ setInitialConfig(config);
222
+ setTimeout(() => setStatus(''), 3000);
223
+ })
224
+ .catch(err => {
225
+ setStatus('error');
226
+ setTimeout(() => setStatus(''), 3000);
227
+ })
228
+ .finally(() => {
229
+ setLoading(false);
230
+ });
231
+ } else {
232
+ setStatus('success');
233
+ setInitialConfig(config);
234
+ setTimeout(() => setStatus(''), 3000);
235
+ setLoading(false);
236
+ }
237
+ } catch (err) {
238
+ console.error('Error in handleSave:', err);
239
+ setStatus('error');
240
+ setTimeout(() => setStatus(''), 3000);
241
+ setLoading(false);
242
+ }
243
+ }
244
+ };
245
+
246
+ const handleLanguageChange = (lang) => {
247
+ setCurrentLang(lang);
248
+ handleConfigChange('language', lang === 'de');
249
+ };
250
+
251
+ return (
252
+ <div style={styles.container}>
253
+ <div style={styles.header}>
254
+ <h2 style={styles.title}>AIS to NMEA 0183 Converter</h2>
255
+ <button
256
+ onClick={() => window.open('https://github.com/formifan2002/signalk-ais-navionics-converter', '_blank')}
257
+ style={styles.helpButton}
258
+ >
259
+ ℹ️ {currentLang === 'de' ? 'Hilfe' : 'Help'}
260
+ </button>
261
+ </div>
262
+
263
+ <div style={styles.languageSelector}>
264
+ <button
265
+ onClick={() => handleLanguageChange('de')}
266
+ style={{...styles.langButton, ...(currentLang === 'de' ? styles.langButtonActive : {})}}
267
+ >
268
+ Deutsch
269
+ </button>
270
+ <button
271
+ onClick={() => handleLanguageChange('en')}
272
+ style={{...styles.langButton, ...(currentLang === 'en' ? styles.langButtonActive : {})}}
273
+ >
274
+ English
275
+ </button>
276
+ </div>
277
+
278
+ {/* TCP Server */}
279
+ <div style={styles.section}>
280
+ <h3 style={styles.sectionTitle}>{t.tcpServer}</h3>
281
+
282
+ <div style={styles.formGroup}>
283
+ <label style={styles.label}>{t.tcpPort}</label>
284
+ <div style={{
285
+ display: 'block',
286
+ fontSize: '0.85em',
287
+ color: '#666',
288
+ marginTop: '8px',
289
+ marginBottom: '12px',
290
+ fontStyle: 'italic',
291
+ lineHeight: '1.4'
292
+ }}>
293
+ {currentLang === 'de'
294
+ ? 'Dieser Port ist später in der Navionics boating app im Menüpunkt \'Gekoppelte Geräte\' als TCP Port anzugeben.'
295
+ : 'This port must be specified later in the Navionics boating app under the menu item \'Paired Devices\' as TCP Port.'}
296
+ </div>
297
+ <input
298
+ type="number"
299
+ min="1"
300
+ max="65535"
301
+ value={config.tcpPort || 10113}
302
+ onChange={(e) => handleConfigChange('tcpPort', Number(e.target.value))}
303
+ style={{
304
+ ...styles.input,
305
+ ...(portError ? { borderColor: '#dc3545', backgroundColor: '#fff5f5' } : {})
306
+ }}
307
+ />
308
+ </div>
309
+
310
+ <div style={styles.formGroup}>
311
+ <label style={styles.label}>{t.wsPort}</label>
312
+ <div style={{
313
+ display: 'block',
314
+ fontSize: '0.85em',
315
+ color: '#666',
316
+ marginTop: '8px',
317
+ marginBottom: '12px',
318
+ fontStyle: 'italic',
319
+ lineHeight: '1.4'
320
+ }}>
321
+ {currentLang === 'de'
322
+ ? 'Über diesen Port werden alle AIS Daten als NMEA0183 und alle Schiffsdaten per JOSN als Websocket gesendet (nicht für Navionics relevant). 0=kein Websocket Server.'
323
+ : 'This port is used to send all AIS data as NMEA0183 and all vessel data as JSON via Websocket (not relevant for Navionics). 0=no Websocket server.'}
324
+ </div>
325
+ <input
326
+ type="number"
327
+ min="0"
328
+ max="65535"
329
+ value={config.wsPort || 10114}
330
+ onChange={(e) => handleConfigChange('wsPort', Number(e.target.value))}
331
+ style={{
332
+ ...styles.input,
333
+ ...(portError ? { borderColor: '#dc3545', backgroundColor: '#fff5f5' } : {})
334
+ }}
335
+ />
336
+ {portError && (
337
+ <div style={{
338
+ color: '#dc3545',
339
+ fontSize: '0.85em',
340
+ marginTop: '8px',
341
+ fontWeight: '500'
342
+ }}>
343
+ ⚠️ {portError}
344
+ </div>
345
+ )}
346
+ </div>
347
+
348
+ <div style={styles.formGroup}>
349
+ <label style={styles.label}>{t.updateInterval}</label>
350
+ <input
351
+ type="number"
352
+ min="1"
353
+ value={config.updateInterval || 15}
354
+ onChange={(e) => handleConfigChange('updateInterval', Number(e.target.value))}
355
+ style={styles.input}
356
+ />
357
+ </div>
358
+
359
+ <div style={styles.formGroup}>
360
+ <label style={styles.label}>{t.tcpResendInterval}</label>
361
+ <input
362
+ type="number"
363
+ min="0"
364
+ value={config.tcpResendInterval || 60}
365
+ onChange={(e) => handleConfigChange('tcpResendInterval', Number(e.target.value))}
366
+ style={styles.input}
367
+ />
368
+ </div>
369
+ </div>
370
+
371
+ {/* Filtering */}
372
+ <div style={styles.section}>
373
+ <h3 style={styles.sectionTitle}>{t.filtering}</h3>
374
+
375
+ <div style={styles.formGroup}>
376
+ <label style={styles.checkbox}>
377
+ <input
378
+ type="checkbox"
379
+ checked={config.skipWithoutCallsign || false}
380
+ onChange={(e) => handleConfigChange('skipWithoutCallsign', e.target.checked)}
381
+ />
382
+ {t.skipWithoutCallsign}
383
+ </label>
384
+ </div>
385
+
386
+ <div style={styles.formGroup}>
387
+ <label style={styles.checkbox}>
388
+ <input
389
+ type="checkbox"
390
+ checked={config.skipStaleData !== false}
391
+ onChange={(e) => handleConfigChange('skipStaleData', e.target.checked)}
392
+ />
393
+ {t.skipStaleData}
394
+ </label>
395
+ </div>
396
+
397
+ {config.skipStaleData !== false && (
398
+ <div style={styles.formGroup}>
399
+ <label style={styles.label}>{t.staleDataThreshold}</label>
400
+ <input
401
+ type="number"
402
+ min="1"
403
+ value={config.staleDataThresholdMinutes || 60}
404
+ onChange={(e) => handleConfigChange('staleDataThresholdMinutes', Number(e.target.value))}
405
+ style={styles.input}
406
+ />
407
+ </div>
408
+ )}
409
+
410
+ <div style={styles.formGroup}>
411
+ <label style={styles.label}>{t.staleDataShipname}</label>
412
+ <input
413
+ type="number"
414
+ min="0"
415
+ value={config.staleDataShipnameAddTime || 5}
416
+ onChange={(e) => handleConfigChange('staleDataShipnameAddTime', Number(e.target.value))}
417
+ style={styles.input}
418
+ />
419
+ </div>
420
+
421
+ <div style={styles.formGroup}>
422
+ <label style={styles.label}>{t.minAlarmSOG}</label>
423
+ <input
424
+ type="number"
425
+ min="0"
426
+ step="0.1"
427
+ value={config.minAlarmSOG || 0.2}
428
+ onChange={(e) => handleConfigChange('minAlarmSOG', Number(e.target.value))}
429
+ style={styles.input}
430
+ />
431
+ </div>
432
+
433
+ <div style={styles.formGroup}>
434
+ <label style={styles.label}>{t.maxMinutesSOGToZero}</label>
435
+ <input
436
+ type="number"
437
+ min="0"
438
+ value={config.maxMinutesSOGToZero || 0}
439
+ onChange={(e) => handleConfigChange('maxMinutesSOGToZero', Number(e.target.value))}
440
+ style={styles.input}
441
+ />
442
+ </div>
443
+ </div>
444
+
445
+ {/* Debugging */}
446
+ <div style={styles.section}>
447
+ <h3 style={styles.sectionTitle}>{t.debugging}</h3>
448
+
449
+ <div style={styles.formGroup}>
450
+ <label style={styles.checkbox}>
451
+ <input
452
+ type="checkbox"
453
+ checked={config.logDebugDetails || false}
454
+ onChange={(e) => handleConfigChange('logDebugDetails', e.target.checked)}
455
+ />
456
+ {t.logDebugDetails}
457
+ </label>
458
+ </div>
459
+
460
+ {config.logDebugDetails && (
461
+ <>
462
+ <div style={styles.formGroup}>
463
+ <label style={styles.label}>{t.logMMSI}</label>
464
+ <div style={{
465
+ display: 'block',
466
+ fontSize: '0.85em',
467
+ color: '#666',
468
+ marginTop: '8px',
469
+ marginBottom: '12px',
470
+ fontStyle: 'italic',
471
+ lineHeight: '1.4'
472
+ }}>
473
+ {currentLang === 'de'
474
+ ? 'Debug Ausgaben werden nur für das Schiff mit dieser MMSI erzeugt. Für das eigene Schiff / die eigene MMSI werden keine AIS Daten erzeugt. Wenn das Feld leer bleibt, werden Debug-Ausgaben für alle Schiffe (außer dem eigenen) erzeugt.'
475
+ : 'Debug output is only generated for the vessel with this MMSI. No AIS data is generated for your own vessel / own MMSI. If the field is left empty, debug output is generated for all vessels (except your own).'}
476
+ </div>
477
+ <input
478
+ type="text"
479
+ value={config.logMMSI || ''}
480
+ onChange={(e) => handleConfigChange('logMMSI', e.target.value)}
481
+ placeholder="e.g. 123456789"
482
+ style={{
483
+ ...styles.input,
484
+ ...(isMMSIInvalid() ? { borderColor: '#dc3545', backgroundColor: '#fff5f5' } : {})
485
+ }}
486
+ />
487
+ {isMMSIInvalid() && (
488
+ <div style={{
489
+ color: '#dc3545',
490
+ fontSize: '0.85em',
491
+ marginTop: '8px',
492
+ fontWeight: '500'
493
+ }}>
494
+ {currentLang === 'de'
495
+ ? '⚠️ Sie können nicht die eigene MMSI verwenden!'
496
+ : '⚠️ You cannot use your own MMSI!'}
497
+ </div>
498
+ )}
499
+ </div>
500
+
501
+ <div style={styles.formGroup}>
502
+ <label style={styles.checkbox}>
503
+ <input
504
+ type="checkbox"
505
+ checked={config.logDebugStale || false}
506
+ onChange={(e) => handleConfigChange('logDebugStale', e.target.checked)}
507
+ />
508
+ {t.logDebugStale}
509
+ </label>
510
+ </div>
511
+
512
+ <div style={styles.formGroup}>
513
+ <label style={styles.checkbox}>
514
+ <input
515
+ type="checkbox"
516
+ checked={config.logDebugJSON || false}
517
+ onChange={(e) => handleConfigChange('logDebugJSON', e.target.checked)}
518
+ />
519
+ {t.logDebugJSON}
520
+ </label>
521
+ </div>
522
+
523
+ <div style={styles.formGroup}>
524
+ <label style={styles.checkbox}>
525
+ <input
526
+ type="checkbox"
527
+ checked={config.logDebugAIS || false}
528
+ onChange={(e) => handleConfigChange('logDebugAIS', e.target.checked)}
529
+ />
530
+ {t.logDebugAIS}
531
+ </label>
532
+ </div>
533
+
534
+ <div style={styles.formGroup}>
535
+ <label style={styles.checkbox}>
536
+ <input
537
+ type="checkbox"
538
+ checked={config.logDebugSOG || false}
539
+ onChange={(e) => handleConfigChange('logDebugSOG', e.target.checked)}
540
+ />
541
+ {t.logDebugSOG}
542
+ </label>
543
+ </div>
544
+ </>
545
+ )}
546
+ </div>
547
+
548
+ {/* VesselFinder */}
549
+ <div style={styles.section}>
550
+ <h3 style={styles.sectionTitle}>{t.vesselFinder}</h3>
551
+
552
+ <div style={styles.formGroup}>
553
+ <label style={styles.checkbox}>
554
+ <input
555
+ type="checkbox"
556
+ checked={config.vesselFinderEnabled || false}
557
+ onChange={(e) => handleConfigChange('vesselFinderEnabled', e.target.checked)}
558
+ />
559
+ {t.vesselFinderEnabled}
560
+ </label>
561
+ </div>
562
+
563
+ {config.vesselFinderEnabled && (
564
+ <>
565
+ <div style={styles.formGroup}>
566
+ <label style={styles.label}>{t.vesselFinderHost}</label>
567
+ <input
568
+ type="text"
569
+ value={config.vesselFinderHost || 'ais.vesselfinder.com'}
570
+ onChange={(e) => handleConfigChange('vesselFinderHost', e.target.value)}
571
+ style={styles.input}
572
+ />
573
+ </div>
574
+
575
+ <div style={styles.formGroup}>
576
+ <label style={styles.label}>{t.vesselFinderPort}</label>
577
+ <input
578
+ type="number"
579
+ min="1"
580
+ max="65535"
581
+ value={config.vesselFinderPort || 5500}
582
+ onChange={(e) => handleConfigChange('vesselFinderPort', Number(e.target.value))}
583
+ style={styles.input}
584
+ />
585
+ </div>
586
+
587
+ <div style={styles.formGroup}>
588
+ <label style={styles.label}>{t.vesselFinderUpdateRate}</label>
589
+ <input
590
+ type="number"
591
+ min="1"
592
+ value={config.vesselFinderUpdateRate || 60}
593
+ onChange={(e) => handleConfigChange('vesselFinderUpdateRate', Number(e.target.value))}
594
+ style={styles.input}
595
+ />
596
+ </div>
597
+ </>
598
+ )}
599
+ </div>
600
+
601
+ {/* Cloud Vessels */}
602
+ {!aisfleetEnabled && (
603
+ <div style={styles.section}>
604
+ <h3 style={styles.sectionTitle}>{t.cloudVessels}</h3>
605
+
606
+ <div style={styles.formGroup}>
607
+ <label style={styles.checkbox}>
608
+ <input
609
+ type="checkbox"
610
+ checked={config.cloudVesselsEnabled !== false}
611
+ onChange={(e) => handleConfigChange('cloudVesselsEnabled', e.target.checked)}
612
+ />
613
+ {t.cloudVesselsEnabled}
614
+ </label>
615
+ </div>
616
+
617
+ {config.cloudVesselsEnabled !== false && (
618
+ <>
619
+ <div style={styles.formGroup}>
620
+ <label style={styles.label}>{t.cloudVesselsUpdateInterval}</label>
621
+ <input
622
+ type="number"
623
+ min="1"
624
+ value={config.cloudVesselsUpdateInterval || 60}
625
+ onChange={(e) => handleConfigChange('cloudVesselsUpdateInterval', Number(e.target.value))}
626
+ style={styles.input}
627
+ />
628
+ </div>
629
+
630
+ <div style={styles.formGroup}>
631
+ <label style={styles.label}>{t.cloudVesselsRadius}</label>
632
+ <input
633
+ type="number"
634
+ min="1"
635
+ value={config.cloudVesselsRadius || 10}
636
+ onChange={(e) => handleConfigChange('cloudVesselsRadius', Number(e.target.value))}
637
+ style={styles.input}
638
+ />
639
+ </div>
640
+ </>
641
+ )}
642
+ </div>
643
+ )}
644
+
645
+ {status && (
646
+ <div style={{...styles.statusMessage, ...(status === 'error' ? styles.error : styles.success)}}>
647
+ {status === 'success'
648
+ ? (currentLang === 'de' ? 'Konfiguration gespeichert' : 'Configuration saved')
649
+ : (currentLang === 'de' ? 'Fehler beim Speichern' : 'Error saving')}
650
+ </div>
651
+ )}
652
+
653
+ <div style={styles.buttonGroup}>
654
+ <button
655
+ onClick={handleSave}
656
+ disabled={loading || isMMSIInvalid() || isPortInvalid()}
657
+ style={{
658
+ ...styles.button,
659
+ ...styles.primaryButton,
660
+ ...((isMMSIInvalid() || isPortInvalid()) ? { opacity: 0.5, cursor: 'not-allowed' } : {})
661
+ }}
662
+ >
663
+ {t.save}
664
+ </button>
665
+ <button
666
+ onClick={() => {
667
+ if (checkUnsavedChanges()) {
668
+ setDialogData({
669
+ title: t.unsavedTitle,
670
+ message: t.unsavedWarning,
671
+ callback: () => setConfig(initialConfig)
672
+ });
673
+ setShowDialog(true);
674
+ } else {
675
+ setConfig(initialConfig);
676
+ }
677
+ }}
678
+ style={{...styles.button, ...styles.secondaryButton}}
679
+ >
680
+ {t.cancel}
681
+ </button>
682
+ </div>
683
+
684
+ {showDialog && (
685
+ <div style={styles.dialog}>
686
+ <div style={styles.dialogContent}>
687
+ <h4 style={styles.dialogTitle}>{dialogData.title}</h4>
688
+ <p>{dialogData.message}</p>
689
+ <div style={styles.dialogButtons}>
690
+ <button
691
+ onClick={() => setShowDialog(false)}
692
+ style={{...styles.button, ...styles.secondaryButton}}
693
+ >
694
+ {t.no}
695
+ </button>
696
+ <button
697
+ onClick={() => {
698
+ if (dialogData.callback) dialogData.callback();
699
+ setShowDialog(false);
700
+ }}
701
+ style={{...styles.button, ...styles.primaryButton}}
702
+ >
703
+ {t.yes}
704
+ </button>
705
+ </div>
706
+ </div>
707
+ </div>
708
+ )}
709
+ </div>
710
+ );
711
+ };
712
+
713
+ const styles = {
714
+ container: {
715
+ padding: '20px',
716
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto',
717
+ },
718
+ header: {
719
+ display: 'flex',
720
+ justifyContent: 'space-between',
721
+ alignItems: 'center',
722
+ marginBottom: '30px',
723
+ paddingBottom: '20px',
724
+ borderBottom: '2px solid #667eea',
725
+ },
726
+ title: {
727
+ margin: 0,
728
+ fontSize: '1.5em',
729
+ fontWeight: '600',
730
+ color: '#333',
731
+ },
732
+ helpButton: {
733
+ padding: '8px 16px',
734
+ backgroundColor: '#667eea',
735
+ color: 'white',
736
+ border: 'none',
737
+ borderRadius: '6px',
738
+ cursor: 'pointer',
739
+ fontWeight: '500',
740
+ fontSize: '0.95em',
741
+ transition: 'background 0.3s',
742
+ },
743
+ languageSelector: {
744
+ display: 'flex',
745
+ gap: '10px',
746
+ marginBottom: '30px',
747
+ },
748
+ langButton: {
749
+ padding: '8px 16px',
750
+ border: '1px solid #ddd',
751
+ borderRadius: '4px',
752
+ cursor: 'pointer',
753
+ fontWeight: '500',
754
+ backgroundColor: '#f5f5f5',
755
+ },
756
+ langButtonActive: {
757
+ backgroundColor: '#667eea',
758
+ color: 'white',
759
+ borderColor: '#667eea',
760
+ },
761
+ section: {
762
+ marginBottom: '30px',
763
+ },
764
+ sectionTitle: {
765
+ fontSize: '1.2em',
766
+ fontWeight: '600',
767
+ marginBottom: '15px',
768
+ color: '#333',
769
+ borderBottom: '2px solid #667eea',
770
+ paddingBottom: '10px',
771
+ },
772
+ formGroup: {
773
+ marginBottom: '15px',
774
+ },
775
+ label: {
776
+ display: 'block',
777
+ fontWeight: '500',
778
+ marginBottom: '5px',
779
+ color: '#333',
780
+ },
781
+ input: {
782
+ padding: '8px',
783
+ border: '1px solid #ddd',
784
+ borderRadius: '4px',
785
+ fontSize: '1em',
786
+ width: '200px',
787
+ },
788
+ checkbox: {
789
+ display: 'flex',
790
+ alignItems: 'center',
791
+ marginBottom: '8px',
792
+ cursor: 'pointer',
793
+ gap: '8px',
794
+ },
795
+ buttonGroup: {
796
+ display: 'flex',
797
+ gap: '10px',
798
+ marginTop: '30px',
799
+ paddingTop: '20px',
800
+ borderTop: '1px solid #ddd',
801
+ },
802
+ button: {
803
+ padding: '10px 20px',
804
+ border: 'none',
805
+ borderRadius: '4px',
806
+ cursor: 'pointer',
807
+ fontWeight: '500',
808
+ fontSize: '1em',
809
+ },
810
+ primaryButton: {
811
+ backgroundColor: '#667eea',
812
+ color: 'white',
813
+ },
814
+ secondaryButton: {
815
+ backgroundColor: '#6c757d',
816
+ color: 'white',
817
+ },
818
+ statusMessage: {
819
+ padding: '12px',
820
+ borderRadius: '4px',
821
+ marginBottom: '15px',
822
+ fontSize: '0.95em',
823
+ },
824
+ success: {
825
+ backgroundColor: '#d4edda',
826
+ color: '#155724',
827
+ },
828
+ error: {
829
+ backgroundColor: '#f8d7da',
830
+ color: '#721c24',
831
+ },
832
+ dialog: {
833
+ position: 'fixed',
834
+ top: 0,
835
+ left: 0,
836
+ right: 0,
837
+ bottom: 0,
838
+ backgroundColor: 'rgba(0,0,0,0.5)',
839
+ display: 'flex',
840
+ alignItems: 'center',
841
+ justifyContent: 'center',
842
+ zIndex: 1000,
843
+ },
844
+ dialogContent: {
845
+ backgroundColor: 'white',
846
+ padding: '30px',
847
+ borderRadius: '8px',
848
+ maxWidth: '400px',
849
+ boxShadow: '0 4px 6px rgba(0,0,0,0.1)',
850
+ },
851
+ dialogTitle: {
852
+ marginTop: 0,
853
+ marginBottom: '15px',
854
+ fontSize: '1.1em',
855
+ },
856
+ dialogButtons: {
857
+ display: 'flex',
858
+ gap: '10px',
859
+ justifyContent: 'flex-end',
860
+ marginTop: '20px',
861
+ }
862
+ };
863
+
864
+ export default PluginConfigurationPanel;