1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
|
<script lang="ts">
const API = 'http://localhost:8080/api';
let { data } = $props();
let initialized = $state(false);
let token = $state('');
let services = $state<any[]>([]);
let showForm = $state(false);
$effect(() => {
if (!initialized && data) {
token = data.token;
services = data.services ?? [];
initialized = true;
fetchMaintenances();
fetchServerStats();
}
});
let editingSvc: any = $state(null);
let saving = $state(false);
let formError = $state('');
let testing = $state<Record<number, boolean>>({});
let toggling = $state<Record<number, boolean>>({});
// maintenance state
let maintenances = $state<any[]>([]);
let showMtnForm = $state(false);
let editingMtn: any = $state(null);
let mtnSaving = $state(false);
let mtnFormError = $state('');
// server health state
let serverStats: { cpu_percent: number; memory_percent: number; disk_percent: number } | null = $state(null);
let serverStatsLoading = $state(true);
let serverStatsError = $state('');
async function fetchServerStats() {
serverStatsLoading = true;
serverStatsError = '';
try {
const res = await fetch(`${API}/admin/server-stats`, { headers: { Authorization: `Bearer ${token}` } });
if (await handleUnauthorized(res)) return;
if (!res.ok) throw new Error('Erro ao carregar');
serverStats = await res.json();
} catch {
serverStatsError = 'Falha ao carregar métricas do servidor';
} finally {
serverStatsLoading = false;
}
}
function apiHeaders() {
return { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` };
}
async function fetchMaintenances() {
try {
const res = await fetch(`${API}/maintenances`, { headers: { Authorization: `Bearer ${token}` } });
if (await handleUnauthorized(res)) return;
if (res.ok) maintenances = await res.json();
} catch {}
}
async function handleUnauthorized(res: Response) {
if (res.status === 401) {
window.location.href = '/login';
return true;
}
return false;
}
function openCreate() {
editingSvc = null;
formError = '';
showForm = true;
}
function openEdit(svc: any) {
editingSvc = { ...svc };
formError = '';
showForm = true;
}
function closeForm() {
showForm = false;
editingSvc = null;
formError = '';
}
async function reFetch() {
try {
const res = await fetch(`${API}/services`, { headers: { Authorization: `Bearer ${token}` } });
if (await handleUnauthorized(res)) return;
if (res.ok) {
const list = await res.json();
const withStats = await Promise.all(
list.map(async (svc: any) => {
try {
const sr = await fetch(`${API}/services/${svc.id}/stats`, {
headers: { Authorization: `Bearer ${token}` }
});
if (sr.ok) svc.stats = await sr.json();
} catch {}
return svc;
})
);
services = withStats;
}
} catch {}
}
async function handleSubmit(e: Event) {
e.preventDefault();
saving = true;
formError = '';
const form = e.target as HTMLFormElement;
const fd = new FormData(form);
const body: Record<string, any> = {
name: fd.get('name'),
url: fd.get('url'),
group_name: (fd.get('group_name') as string) || 'Geral',
interval_seconds: parseInt((fd.get('interval_seconds') as string) || '60', 10),
};
const keyword = fd.get('keyword_to_find') as string;
if (keyword) body.keyword_to_find = keyword;
const discord = fd.get('discord_webhook_url') as string;
if (discord) body.discord_webhook_url = discord;
const email = fd.get('alert_email') as string;
if (email) body.alert_email = email;
try {
const id = fd.get('id');
const method = id ? 'PUT' : 'POST';
const url = id ? `${API}/services/${id}` : `${API}/services`;
const res = await fetch(url, {
method,
headers: apiHeaders(),
body: JSON.stringify(body),
});
if (await handleUnauthorized(res)) return;
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(err.error || 'Erro ao salvar');
}
await reFetch();
closeForm();
} catch (e: any) {
formError = e.message;
} finally {
saving = false;
}
}
async function handleDelete(id: number) {
try {
const res = await fetch(`${API}/services/${id}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` }
});
if (await handleUnauthorized(res)) return;
if (res.ok) await reFetch();
} catch {}
}
async function handleToggle(id: number) {
toggling = { ...toggling, [id]: true };
try {
const res = await fetch(`${API}/services/${id}/toggle`, {
method: 'PATCH',
headers: { Authorization: `Bearer ${token}` }
});
if (await handleUnauthorized(res)) return;
if (res.ok) {
const updated = await res.json();
services = services.map((s) => (s.id === id ? { ...s, ...updated } : s));
}
} catch { /* ignore */ }
toggling = { ...toggling, [id]: false };
}
function openMtnCreate() {
editingMtn = null;
mtnFormError = '';
showMtnForm = true;
}
function openMtnEdit(m: any) {
editingMtn = { ...m };
mtnFormError = '';
showMtnForm = true;
}
function closeMtnForm() {
showMtnForm = false;
editingMtn = null;
mtnFormError = '';
}
async function handleMtnSubmit(e: Event) {
e.preventDefault();
mtnSaving = true;
mtnFormError = '';
const form = e.target as HTMLFormElement;
const fd = new FormData(form);
const body: Record<string, any> = {
title: fd.get('title'),
start_time: fd.get('start_time'),
end_time: fd.get('end_time'),
is_active: fd.get('is_active') === 'on',
};
try {
const id = fd.get('id');
if (id) {
const res = await fetch(`${API}/maintenances/${id}`, {
method: 'PUT',
headers: apiHeaders(),
body: JSON.stringify(body),
});
if (await handleUnauthorized(res)) return;
if (!res.ok) throw new Error((await res.json().catch(() => ({}))).error || 'Erro ao salvar');
} else {
const res = await fetch(`${API}/maintenances`, {
method: 'POST',
headers: apiHeaders(),
body: JSON.stringify({ title: body.title, start_time: body.start_time, end_time: body.end_time }),
});
if (await handleUnauthorized(res)) return;
if (!res.ok) throw new Error((await res.json().catch(() => ({}))).error || 'Erro ao salvar');
}
await fetchMaintenances();
closeMtnForm();
} catch (e: any) {
mtnFormError = e.message;
} finally {
mtnSaving = false;
}
}
async function handleMtnDelete(id: number) {
try {
const res = await fetch(`${API}/maintenances/${id}`, {
method: 'DELETE',
headers: apiHeaders()
});
if (await handleUnauthorized(res)) return;
if (res.ok) await fetchMaintenances();
} catch {}
}
async function handleTest(id: number) {
testing = { ...testing, [id]: true };
try {
const res = await fetch(`${API}/services/${id}/test`, {
method: 'POST',
headers: { Authorization: `Bearer ${token}` }
});
if (await handleUnauthorized(res)) return;
if (res.ok) {
const hb = await res.json();
services = services.map((s) =>
s.id === id ? { ...s, last_heartbeat: hb } : s
);
}
} catch { /* ignore */ }
testing = { ...testing, [id]: false };
}
</script>
<svelte:head>
<title>Admin — YAUM</title>
</svelte:head>
<div class="mb-8 flex items-center justify-between">
<div>
<h1 class="text-2xl font-semibold tracking-tight text-white">Painel de Controle</h1>
<p class="mt-1 text-sm text-[var(--text-muted)]">Gerenciamento de serviços monitorados</p>
</div>
<a
href="/"
class="text-xs text-[var(--text-muted)] underline transition-colors hover:text-white"
>
← Dashboard
</a>
</div>
<!-- Saúde do Sistema -->
<div class="mb-8">
<h2 class="mb-4 text-xs font-semibold uppercase tracking-wider text-[var(--text-secondary)]">
Saúde do Sistema
</h2>
{#if serverStatsLoading}
<div class="grid grid-cols-3 gap-4">
{#each ['CPU', 'RAM', 'Disco'] as label}
<div class="rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] p-4">
<p class="text-[10px] font-medium uppercase tracking-wider text-[var(--text-muted)]">{label}</p>
<div class="mt-3 h-2 rounded-full bg-[var(--border-color)]"><div class="h-full w-1/3 rounded-full bg-[var(--border-color)]"></div></div>
<p class="mt-2 text-right font-mono text-xs text-[var(--text-muted)]">…</p>
</div>
{/each}
</div>
{:else if serverStats}
<div class="grid grid-cols-3 gap-4">
{#each [
{ label: 'CPU', pct: serverStats.cpu_percent },
{ label: 'RAM', pct: serverStats.memory_percent },
{ label: 'Disco', pct: serverStats.disk_percent },
] as item}
{@const color = item.pct >= 90 ? 'var(--red)' : item.pct >= 70 ? 'var(--amber)' : 'var(--green)'}
<div class="rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] p-4">
<div class="flex items-center justify-between">
<p class="text-[10px] font-medium uppercase tracking-wider text-[var(--text-muted)]">{item.label}</p>
<span class="font-mono text-lg font-bold tabular-nums" style="color: {color}">
{item.pct.toFixed(1)}<span class="text-xs font-normal text-[var(--text-muted)]">%</span>
</span>
</div>
<div class="mt-3 h-2 overflow-hidden rounded-full bg-[var(--border-color)]">
<div
class="h-full rounded-full transition-all duration-500"
style="width: {Math.min(item.pct, 100)}%; background-color: {color};"
></div>
</div>
</div>
{/each}
</div>
{:else if serverStatsError}
<div class="rounded-xl border border-[var(--red)]/20 bg-[var(--red)]/5 p-4 text-center">
<p class="text-xs text-[var(--text-muted)]">{serverStatsError}</p>
</div>
{/if}
</div>
<div class="mb-8">
<button
onclick={openCreate}
class="flex items-center gap-2 rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-4 py-2.5 text-sm font-medium text-[var(--text-primary)] transition-all hover:border-[var(--green)]/50 hover:text-[var(--green)] hover:shadow-[0_0_20px_rgba(34,240,106,0.08)]"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4" />
</svg>
Novo Serviço
</button>
</div>
{#if data.error}
<div class="rounded-xl border border-[var(--red)]/20 bg-[var(--red)]/5 p-6 text-center">
<p class="text-sm text-[var(--red)]">{data.error}</p>
</div>
{:else if services.length === 0}
<div class="rounded-xl border border-dashed border-[var(--border-color)] p-12 text-center">
<p class="text-sm text-[var(--text-muted)]">Nenhum serviço cadastrado</p>
</div>
{:else}
{#each [...new Set(services.map((s) => s.group_name || 'Geral'))].sort() as group}
<div class="mb-6">
<h2 class="mb-3 text-xs font-semibold uppercase tracking-wider text-[var(--text-secondary)]">{group}</h2>
<div class="overflow-hidden rounded-xl border border-[var(--border-color)]">
<table class="w-full text-left text-sm">
<thead>
<tr class="border-b border-[var(--border-color)] bg-[var(--bg-secondary)]/30">
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">ID</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Nome</th>
<th class="hidden px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)] md:table-cell">URL</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Status</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">SLA 30d</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Ações</th>
</tr>
</thead>
<tbody>
{#each services.filter((s) => (s.group_name || 'Geral') === group) as svc (svc.id)}
<tr class="border-b border-[var(--border-color)] transition-colors hover:bg-[var(--bg-secondary)]/20">
<td class="px-4 py-3 font-mono text-xs text-[var(--text-muted)]">{svc.id}</td>
<td class="px-4 py-3 font-medium text-white">{svc.name}</td>
<td class="hidden max-w-[200px] truncate px-4 py-3 font-mono text-xs text-[var(--text-muted)] md:table-cell">{svc.url}</td>
<td class="px-4 py-3">
<span
class="inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[10px] font-semibold"
style="background-color: {svc.last_heartbeat?.is_up ?? true ? 'rgba(34,240,106,0.1)' : 'rgba(255,64,96,0.1)'}; color: {svc.last_heartbeat?.is_up ?? true ? 'var(--green)' : 'var(--red)'}"
>
{svc.last_heartbeat?.is_up ?? true ? 'UP' : 'DOWN'}
</span>
</td>
<td class="px-4 py-3 font-mono text-xs tabular-nums">
{svc.stats ? svc.stats.uptime_30d.toFixed(2) + '%' : '—'}
</td>
<td class="px-4 py-3">
<div class="flex flex-wrap gap-1.5">
<button
onclick={() => openEdit(svc)}
class="rounded-lg px-2.5 py-1 text-[10px] font-medium text-[var(--text-secondary)] transition-colors hover:bg-[var(--border-color)] hover:text-white"
>
Editar
</button>
<button
onclick={() => handleToggle(svc.id)}
disabled={toggling[svc.id] ?? false}
class="rounded-lg px-2.5 py-1 text-[10px] font-medium transition-colors"
style="color: {svc.is_active ?? true ? 'var(--green)' : 'var(--red)'}; {(svc.is_active ?? true) ? 'border:1px solid rgba(34,240,106,0.3)' : 'border:1px solid rgba(255,64,96,0.3)'}; {toggling[svc.id] ? 'opacity:0.5' : ''}"
>
{svc.is_active ?? true ? 'Ativo' : 'Pausado'}
</button>
<button
onclick={() => handleTest(svc.id)}
disabled={testing[svc.id] ?? false}
class="rounded-lg px-2.5 py-1 text-[10px] font-medium text-[var(--text-secondary)] transition-colors hover:bg-[var(--border-color)] hover:text-white"
style={testing[svc.id] ? 'opacity:0.5' : ''}
>
{testing[svc.id] ? '...' : 'Testar'}
</button>
<button
onclick={() => handleDelete(svc.id)}
class="rounded-lg px-2.5 py-1 text-[10px] font-medium text-[var(--red)] transition-colors hover:bg-[var(--red)]/10"
>
Excluir
</button>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
{/each}
{/if}
<div class="mb-8 mt-12 border-t border-[var(--border-color)] pt-8">
<div class="mb-6 flex items-center justify-between">
<div>
<h2 class="text-sm font-semibold uppercase tracking-wider text-[var(--text-secondary)]">Manutenções Programadas</h2>
<p class="mt-0.5 text-xs text-[var(--text-muted)]">Janelas de manutenção exibem um aviso no topo do site</p>
</div>
<button
onclick={openMtnCreate}
class="flex items-center gap-2 rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-4 py-2 text-sm font-medium text-[var(--text-primary)] transition-all hover:border-[var(--green)]/50 hover:text-[var(--green)]"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4" />
</svg>
Nova Manutenção
</button>
</div>
{#if maintenances.length === 0}
<div class="rounded-xl border border-dashed border-[var(--border-color)] p-8 text-center">
<p class="text-xs text-[var(--text-muted)]">Nenhuma manutenção agendada</p>
</div>
{:else}
<div class="overflow-hidden rounded-xl border border-[var(--border-color)]">
<table class="w-full text-left text-sm">
<thead>
<tr class="border-b border-[var(--border-color)] bg-[var(--bg-secondary)]/30">
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Título</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Início</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Fim</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Ativa</th>
<th class="px-4 py-3 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">Ações</th>
</tr>
</thead>
<tbody>
{#each maintenances as mtn (mtn.id)}
<tr class="border-b border-[var(--border-color)] transition-colors hover:bg-[var(--bg-secondary)]/20">
<td class="px-4 py-3 font-medium text-white">{mtn.title}</td>
<td class="px-4 py-3 font-mono text-xs text-[var(--text-muted)]">{new Date(mtn.start_time).toLocaleString('pt-BR')}</td>
<td class="px-4 py-3 font-mono text-xs text-[var(--text-muted)]">{new Date(mtn.end_time).toLocaleString('pt-BR')}</td>
<td class="px-4 py-3">
<span
class="inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[10px] font-semibold"
style="background-color: {mtn.is_active ? 'rgba(34,240,106,0.1)' : 'rgba(255,64,96,0.1)'}; color: {mtn.is_active ? 'var(--green)' : 'var(--red)'}"
>
{mtn.is_active ? 'Sim' : 'Não'}
</span>
</td>
<td class="px-4 py-3">
<div class="flex gap-1.5">
<button
onclick={() => openMtnEdit(mtn)}
class="rounded-lg px-2.5 py-1 text-[10px] font-medium text-[var(--text-secondary)] transition-colors hover:bg-[var(--border-color)] hover:text-white"
>
Editar
</button>
<button
onclick={() => handleMtnDelete(mtn.id)}
class="rounded-lg px-2.5 py-1 text-[10px] font-medium text-[var(--red)] transition-colors hover:bg-[var(--red)]/10"
>
Excluir
</button>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
{/if}
</div>
<!-- Modal create / edit service -->
{#if showForm}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
role="button"
tabindex="-1"
aria-label="Fechar"
class="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm"
onclick={closeForm}
>
<div
class="w-full max-w-md animate-[modalIn_0.2s_ease-out] rounded-2xl border border-[var(--border-color)] bg-[var(--bg-secondary)] p-6 shadow-2xl"
onclick={(e) => e.stopPropagation()}
>
<div class="mb-5 flex items-center justify-between">
<h2 class="text-sm font-semibold uppercase tracking-wider text-[var(--text-secondary)]">
{editingSvc ? 'Editar Serviço' : 'Novo Serviço'}
</h2>
<button
onclick={closeForm}
class="rounded-lg p-1.5 text-[var(--text-muted)] transition-colors hover:bg-[var(--border-color)] hover:text-white"
aria-label="Fechar"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<form onsubmit={handleSubmit} class="space-y-4">
{#if editingSvc}
<input type="hidden" name="id" value={editingSvc.id} />
{/if}
<div>
<label for="admin-name" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Nome do Serviço</label>
<input
id="admin-name"
name="name"
type="text"
value={editingSvc?.name ?? ''}
required
placeholder="Meu Site"
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div>
<label for="admin-url" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">URL</label>
<input
id="admin-url"
name="url"
type="url"
value={editingSvc?.url ?? ''}
required
placeholder="https://exemplo.com"
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div>
<label for="admin-group" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Grupo / Categoria</label>
<input
id="admin-group"
name="group_name"
type="text"
value={editingSvc?.group_name ?? 'Geral'}
placeholder="APIs, Websites, Servidores..."
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div>
<label for="admin-interval" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Intervalo (segundos)</label>
<input
id="admin-interval"
name="interval_seconds"
type="number"
value={editingSvc?.interval_seconds ?? 60}
min="10"
max="3600"
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div class="border-t border-[var(--border-color)] pt-4">
<p class="mb-3 text-xs font-semibold uppercase tracking-wider text-[var(--text-muted)]">Opcionais</p>
<div>
<label for="admin-keyword" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Palavra-chave</label>
<input
id="admin-keyword"
name="keyword_to_find"
type="text"
value={editingSvc?.keyword_to_find ?? ''}
placeholder="Bem-vindo, Login..."
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div class="mt-3">
<label for="admin-webhook" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Webhook Discord</label>
<input
id="admin-webhook"
name="discord_webhook_url"
type="url"
value={editingSvc?.discord_webhook_url ?? ''}
placeholder="https://discord.com/api/webhooks/..."
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div class="mt-3">
<label for="admin-email" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">E-mail de Alerta</label>
<input
id="admin-email"
name="alert_email"
type="email"
value={editingSvc?.alert_email ?? ''}
placeholder="admin@exemplo.com"
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
</div>
{#if formError}
<p class="rounded-lg bg-[var(--red)]/5 px-3 py-2 text-xs text-[var(--red)]">{formError}</p>
{/if}
<div class="flex gap-3 pt-1">
<button
type="button"
onclick={closeForm}
class="flex-1 rounded-xl border border-[var(--border-color)] px-4 py-2.5 text-sm font-medium text-[var(--text-muted)] transition-colors hover:border-[var(--text-muted)]/30 hover:text-white"
>
Cancelar
</button>
<button
type="submit"
disabled={saving}
class="flex-1 rounded-xl border border-[var(--green)] bg-[var(--green)]/10 px-4 py-2.5 text-sm font-medium text-[var(--green)] transition-all hover:bg-[var(--green)]/20 disabled:cursor-not-allowed disabled:opacity-40"
>
{saving ? 'Salvando…' : editingSvc ? 'Salvar' : 'Adicionar'}
</button>
</div>
</form>
</div>
</div>
{/if}
<!-- Modal create / edit maintenance -->
{#if showMtnForm}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
role="button"
tabindex="-1"
aria-label="Fechar"
class="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm"
onclick={closeMtnForm}
>
<div
class="w-full max-w-md animate-[modalIn_0.2s_ease-out] rounded-2xl border border-[var(--border-color)] bg-[var(--bg-secondary)] p-6 shadow-2xl"
onclick={(e) => e.stopPropagation()}
>
<div class="mb-5 flex items-center justify-between">
<h2 class="text-sm font-semibold uppercase tracking-wider text-[var(--text-secondary)]">
{editingMtn ? 'Editar Manutenção' : 'Nova Manutenção'}
</h2>
<button
onclick={closeMtnForm}
class="rounded-lg p-1.5 text-[var(--text-muted)] transition-colors hover:bg-[var(--border-color)] hover:text-white"
aria-label="Fechar"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<form onsubmit={handleMtnSubmit} class="space-y-4">
{#if editingMtn}
<input type="hidden" name="id" value={editingMtn.id} />
{/if}
<div>
<label for="mtn-title" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Título</label>
<input
id="mtn-title"
name="title"
type="text"
value={editingMtn?.title ?? ''}
required
placeholder="Manutenção nos servidores"
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all placeholder:text-[var(--text-muted)] focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div>
<label for="mtn-start" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Início</label>
<input
id="mtn-start"
name="start_time"
type="datetime-local"
value={editingMtn ? editingMtn.start_time.slice(0, 16) : ''}
required
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div>
<label for="mtn-end" class="mb-1.5 block text-xs font-medium text-[var(--text-secondary)]">Fim</label>
<input
id="mtn-end"
name="end_time"
type="datetime-local"
value={editingMtn ? editingMtn.end_time.slice(0, 16) : ''}
required
class="w-full rounded-xl border border-[var(--border-color)] bg-[var(--bg-card)] px-3.5 py-2.5 text-sm text-white outline-none transition-all focus:border-[var(--green)]/50 focus:ring-1 focus:ring-[var(--green)]/20"
/>
</div>
<div>
<label class="flex items-center gap-3">
<input
type="checkbox"
name="is_active"
checked={editingMtn?.is_active ?? true}
class="h-4 w-4 rounded border-[var(--border-color)] bg-[var(--bg-card)] text-[var(--green)] focus:ring-[var(--green)]/30"
/>
<span class="text-xs font-medium text-[var(--text-secondary)]">Ativa</span>
</label>
</div>
{#if mtnFormError}
<p class="rounded-lg bg-[var(--red)]/5 px-3 py-2 text-xs text-[var(--red)]">{mtnFormError}</p>
{/if}
<div class="flex gap-3 pt-1">
<button
type="button"
onclick={closeMtnForm}
class="flex-1 rounded-xl border border-[var(--border-color)] px-4 py-2.5 text-sm font-medium text-[var(--text-muted)] transition-colors hover:border-[var(--text-muted)]/30 hover:text-white"
>
Cancelar
</button>
<button
type="submit"
disabled={mtnSaving}
class="flex-1 rounded-xl border border-[var(--green)] bg-[var(--green)]/10 px-4 py-2.5 text-sm font-medium text-[var(--green)] transition-all hover:bg-[var(--green)]/20 disabled:cursor-not-allowed disabled:opacity-40"
>
{mtnSaving ? 'Salvando…' : editingMtn ? 'Salvar' : 'Adicionar'}
</button>
</div>
</form>
</div>
</div>
{/if}
<style>
@keyframes modalIn {
from { opacity: 0; transform: scale(0.95) translateY(-8px); }
to { opacity: 1; transform: scale(1) translateY(0); }
}
</style>
|