-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathponche-gestion-admin2.html
More file actions
712 lines (648 loc) · 50.7 KB
/
ponche-gestion-admin2.html
File metadata and controls
712 lines (648 loc) · 50.7 KB
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes, viewport-fit=cover">
<title>Vizo Access - Admin Premium</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/@vladmandic/face-api@1/dist/face-api.js"></script>
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
-webkit-tap-highlight-color: transparent;
}
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');
:root {
--primary: #00ff9d;
--primary-dark: #00cc7a;
--primary-glow: rgba(0, 255, 157, 0.4);
--secondary: #2e4a55;
--dark: #0a0f12;
--darker: #050708;
--danger: #ff4757;
--warning: #ffa502;
--info: #00d2ff;
--success: #00ff9d;
--whatsapp: #25D366;
--text-secondary: rgba(255,255,255,0.7);
--bg-dark: #0a0f12;
--bg-light: #141a1f;
--glass-bg: rgba(20, 26, 31, 0.85);
}
body {
background: radial-gradient(circle at 10% 20%, var(--bg-dark), var(--darker));
min-height: 100vh;
color: white;
overflow-x: hidden;
}
.container {
max-width: 100%;
margin: 0 auto;
padding: 12px;
padding-bottom: 80px;
position: relative;
z-index: 1;
}
@keyframes fadeSlideIn {
from { opacity: 0; transform: translateX(30px); }
to { opacity: 1; transform: translateX(0); }
}
.loading-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(5, 7, 8, 0.95);
backdrop-filter: blur(10px);
z-index: 3000;
display: none;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 20px;
}
.loading-overlay.active { display: flex; }
.loading-spinner { width: 60px; height: 60px; border: 3px solid rgba(0,255,157,0.2); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--primary); font-size: 14px; letter-spacing: 2px; }
.success-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
backdrop-filter: blur(8px);
display: none;
justify-content: center;
align-items: center;
z-index: 3500;
}
.success-modal.active { display: flex; }
.success-content {
background: linear-gradient(135deg, var(--bg-light), var(--dark));
border-radius: 40px;
padding: 35px 40px;
text-align: center;
border: 1px solid var(--primary);
animation: fadeSlideIn 0.4s ease;
max-width: 300px;
}
.success-content i { font-size: 60px; color: var(--primary); margin-bottom: 15px; }
.success-content h3 { color: var(--primary); margin-bottom: 10px; }
.success-content p { color: var(--text-secondary); margin-bottom: 20px; }
.login-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: radial-gradient(circle at 30% 20%, #0a0f12, #050708);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.login-box { width: 90%; max-width: 340px; display: flex; flex-direction: column; align-items: center; }
.login-logo img { width: 100px; height: 100px; object-fit: contain; filter: drop-shadow(0 0 15px var(--primary-glow)); }
.login-title { color: var(--primary); font-size: 28px; font-weight: 800; margin: 20px 0; }
.login-input { width: 100%; padding: 12px 20px; margin-bottom: 12px; background: rgba(0,0,0,0.5); border: 1px solid rgba(0,255,157,0.3); border-radius: 50px; color: white; }
.login-btn { width: 100%; padding: 12px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #000; border: none; border-radius: 50px; font-weight: bold; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; background: var(--glass-bg); backdrop-filter: blur(12px); padding: 10px 15px; border-radius: 25px; border: 1px solid rgba(0,255,157,0.2); }
.header-logo { display: flex; align-items: center; gap: 10px; }
.header-logo img { width: 35px; height: 35px; }
.header-logo span { font-size: 16px; font-weight: bold; background: linear-gradient(135deg, var(--primary), #fff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn { padding: 8px 15px; border: none; border-radius: 50px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.3s; font-size: 12px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #000; }
.btn-secondary { background: rgba(255,255,255,0.1); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-whatsapp { background: var(--whatsapp); color: white; }
.search-section { margin-bottom: 20px; position: sticky; top: 0; z-index: 100; background: rgba(5,7,8,0.9); backdrop-filter: blur(10px); padding: 8px 0; border-radius: 50px; }
.search-container { position: relative; width: 100%; }
.search-input { width: 100%; padding: 12px 20px 12px 45px; background: var(--glass-bg); border: 1px solid rgba(0,255,157,0.3); border-radius: 50px; color: white; }
.search-icon { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--primary); }
.carousel-section { margin-bottom: 20px; }
.section-title { color: white; font-size: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.carousel-container { position: relative; width: 100%; overflow: hidden; border-radius: 30px; }
.carousel-track { display: flex; gap: 15px; overflow-x: auto; scroll-behavior: smooth; scroll-snap-type: x mandatory; padding: 12px 8px; scrollbar-width: none; transition: all 0.3s ease; justify-content: flex-start; }
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-item { flex: 0 0 auto; scroll-snap-align: start; text-align: center; cursor: pointer; transition: transform 0.3s, filter 0.3s; display: flex; flex-direction: column; align-items: center; }
.carousel-item:hover { transform: scale(1.05); }
.carousel-item img { width: 80px; height: 80px; object-fit: cover; transition: all 0.3s; display: block; margin: 0 auto; border-radius: 50%; border: 2px solid var(--primary); }
.carousel-item span { display: block; font-size: 12px; color: white; margin-top: 6px; font-weight: 500; width: 100%; text-align: center; }
.carousel-controls { display: flex; justify-content: center; gap: 12px; margin-top: 10px; }
.carousel-control-btn { background: rgba(0,255,157,0.2); border: none; color: var(--primary); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; transition: all 0.3s; font-size: 18px; }
.carousel-control-btn:hover { background: var(--primary); color: #000; transform: scale(1.1); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--glass-bg); backdrop-filter: blur(12px); border-radius: 20px; padding: 15px 10px; text-align: center; border: 1px solid rgba(0,255,157,0.2); }
.stat-card i { font-size: 28px; color: var(--primary); margin-bottom: 8px; display: block; }
.stat-number { font-size: 24px; font-weight: 700; color: white; }
.stat-label { font-size: 10px; color: var(--text-secondary); }
.recent-list { background: var(--glass-bg); border-radius: 20px; padding: 12px; margin-top: 20px; }
.recent-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.1); cursor: pointer; }
.recent-item img { width: 35px; height: 35px; border-radius: 50%; object-fit: cover; }
.card { background: var(--glass-bg); backdrop-filter: blur(12px); border-radius: 25px; padding: 18px; border: 1px solid rgba(0,255,157,0.2); margin-bottom: 15px; }
.search-results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 15px; max-height: 350px; overflow-y: auto; }
.employees-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; max-height: 55vh; overflow-y: auto; padding: 5px; }
.employee-card { background: rgba(255,255,255,0.03); border-radius: 20px; padding: 12px; text-align: center; cursor: pointer; transition: all 0.3s; border: 1px solid rgba(0,255,157,0.1); }
.employee-card:hover { transform: translateY(-5px); border-color: var(--primary); }
.employee-card img { width: 70px; height: 70px; object-fit: cover; border: 2px solid var(--primary); margin-bottom: 10px; border-radius: 50%; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-group { margin-bottom: 8px; }
.form-group label { display: block; margin-bottom: 5px; color: var(--primary); font-weight: 600; font-size: 11px; }
.form-control { width: 100%; padding: 10px 12px; background: rgba(0,0,0,0.4); border: 1px solid rgba(0,255,157,0.2); border-radius: 15px; color: white; font-size: 13px; }
.form-control:disabled { opacity: 0.5; cursor: not-allowed; background: rgba(0,0,0,0.6); }
.code-status.available { color: var(--success); }
.code-status.taken { color: var(--danger); }
.config-section { background: var(--glass-bg); backdrop-filter: blur(12px); border-radius: 25px; padding: 20px; margin-bottom: 20px; }
.config-group { margin-bottom: 20px; }
.config-group label { display: block; color: var(--primary); font-weight: 600; margin-bottom: 8px; }
.config-select, .config-input { width: 100%; padding: 10px; background: rgba(0,0,0,0.4); border: 1px solid rgba(0,255,157,0.3); border-radius: 15px; color: white; }
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(5,7,8,0.95); backdrop-filter: blur(20px); display: none; justify-content: space-around; padding: 8px 0 12px; border-top: 1px solid var(--primary); z-index: 1000; }
.bottom-nav.visible { display: flex; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; color: var(--text-secondary); font-size: 10px; padding: 5px 0; cursor: pointer; background: none; border: none; transition: all 0.3s; }
.nav-item i { font-size: 22px; margin-bottom: 3px; transition: transform 0.3s; }
.nav-item.active { color: var(--primary); text-shadow: 0 0 10px var(--primary-glow); }
.nav-item.active i { transform: translateY(-3px); }
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); display: none; justify-content: center; align-items: center; z-index: 2000; }
.modal.active { display: flex; }
.modal-content { background: var(--bg-light); border-radius: 30px; padding: 25px; max-width: 280px; width: 90%; border: 1px solid var(--primary); text-align: center; }
.welcome-section { background: linear-gradient(135deg, rgba(0,255,157,0.1), rgba(0,0,0,0.3)); border-radius: 20px; padding: 15px; margin-bottom: 20px; }
.detail-page { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-dark); z-index: 1100; overflow-y: auto; padding: 20px; display: none; }
.detail-header { display: flex; align-items: center; gap: 15px; margin-bottom: 25px; }
.detail-header button { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.1); border: none; color: white; cursor: pointer; }
.detail-avatar { text-align: center; margin-bottom: 25px; }
.detail-avatar img { width: 120px; height: 120px; object-fit: cover; border: 3px solid var(--primary); border-radius: 50%; margin-bottom: 10px; }
.detail-name { font-size: 22px; font-weight: 700; color: var(--primary); }
.detail-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 25px; }
.detail-info-item { background: rgba(255,255,255,0.08); padding: 12px; border-radius: 15px; border-left: 2px solid var(--primary); }
/* Cámara fullscreen */
.camera-fullscreen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
z-index: 4000;
display: none;
flex-direction: column;
}
.camera-fullscreen.active { display: flex; }
.camera-header {
padding: 15px;
display: flex;
justify-content: space-between;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 10;
background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
}
.camera-footer {
padding: 20px;
display: flex;
justify-content: center;
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
background: linear-gradient(to top, rgba(0,0,0,0.5), transparent);
}
.camera-preview-container {
flex: 1;
position: relative;
overflow: hidden;
}
#cameraVideo {
width: 100%;
height: 100%;
object-fit: cover;
}
.camera-overlay {
position: absolute;
bottom: 100px;
left: 0;
right: 0;
display: flex;
justify-content: center;
}
.face-message {
background: rgba(0,0,0,0.7);
color: white;
padding: 8px 16px;
border-radius: 50px;
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
}
.btn-camera-circle {
width: 70px;
height: 70px;
border-radius: 50%;
background: white;
border: 4px solid var(--primary);
cursor: pointer;
}
.btn-camera-icon {
width: 45px;
height: 45px;
border-radius: 50%;
background: rgba(0,0,0,0.6);
border: 1px solid white;
color: white;
cursor: pointer;
}
.preview-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
z-index: 4000;
display: none;
flex-direction: column;
}
.preview-screen.active { display: flex; }
.preview-image {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
.preview-image img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
.preview-footer {
padding: 20px;
display: flex;
justify-content: center;
gap: 20px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(to top, rgba(0,0,0,0.5), transparent);
}
.foto-thumbnail {
display: flex;
align-items: center;
gap: 8px;
background: rgba(0,0,0,0.3);
padding: 5px 10px;
border-radius: 50px;
}
.foto-thumbnail img {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
border: 2px solid var(--primary);
}
.btn-icon-camera {
background: var(--primary);
color: #000;
width: 45px;
height: 45px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
cursor: pointer;
border: none;
}
</style>
</head>
<body>
<div id="loadingOverlay" class="loading-overlay"><div class="loading-spinner"></div><div class="loading-text">PROCESANDO...</div></div>
<div id="successModal" class="success-modal"><div class="success-content"><i class="fas fa-check-circle"></i><h3>¡Éxito!</h3><p id="successMessage">Operación completada</p><button class="btn btn-primary" onclick="document.getElementById('successModal').classList.remove('active')">Aceptar</button></div></div>
<div id="loginScreen" class="login-container">
<div class="login-box">
<div class="login-logo"><img src="https://firebasestorage.googleapis.com/v0/b/formulario-2-8929a.appspot.com/o/Vizo%20Access.png?alt=media&token=2e31c49c-ca38-4b5e-b35e-43dee12c16da"></div>
<div class="login-title">VIZO ACCESS</div>
<input type="text" id="loginUsername" class="login-input" placeholder="Usuario">
<input type="text" id="loginPassword" class="login-input" placeholder="PIN">
<div id="loginAlert" style="color: var(--danger); font-size: 12px; display: none;"></div>
<button id="loginBtn" class="login-btn"><i class="fas fa-sign-in-alt"></i> INGRESAR</button>
</div>
</div>
<div id="appScreen" style="display: none;">
<div class="container">
<div class="header">
<div class="header-logo"><img src="https://firebasestorage.googleapis.com/v0/b/formulario-2-8929a.appspot.com/o/Vizo%20Access.png?alt=media&token=2e31c49c-ca38-4b5e-b35e-43dee12c16da"><span>Vizo Access</span></div>
<div class="user-info"><span id="companyDisplay"></span><button id="logoutBtn" class="btn btn-secondary"><i class="fas fa-sign-out-alt"></i></button></div>
</div>
<div class="search-section">
<div class="search-container"><i class="fas fa-search search-icon"></i><input type="text" id="globalSearchInput" class="search-input" placeholder="Buscar por código, nombre, RTM ID o área..."></div>
<div id="globalSearchResults" class="search-results-grid"></div>
</div>
<div id="homeSection" class="session-content">
<div class="welcome-section"><div style="font-size: 18px; font-weight: 600;">¡Bienvenido!</div><div id="welcomeUserName" style="color: var(--primary);"></div></div>
<div class="stats-grid" id="statsGrid">
<div class="stat-card"><i class="fas fa-users"></i><div class="stat-number" id="statTotal">0</div><div class="stat-label">Total Colaboradores</div></div>
<div class="stat-card"><i class="fas fa-calendar-plus"></i><div class="stat-number" id="statRecent">0</div><div class="stat-label">Últimos 7 días</div></div>
<div class="stat-card"><i class="fas fa-chart-line"></i><div class="stat-number" id="statAreas">0</div><div class="stat-label">Áreas distintas</div></div>
</div>
<div class="carousel-section">
<div class="section-title"><i class="fas fa-star"></i> Colaboradores Destacados</div>
<div class="carousel-container"><div class="carousel-track" id="carouselTrack"></div></div>
<div class="carousel-controls" id="carouselControls"></div>
</div>
<div class="recent-list"><div class="section-title"><i class="fas fa-clock"></i> Últimos incorporados</div><div id="recentEmployees"></div></div>
</div>
<div id="pageRegistro" class="session-content" style="display: none;">
<div class="card">
<form id="registroForm">
<input type="hidden" id="editId">
<div class="form-row">
<div class="form-group"><label>Código Nómina</label><input type="number" id="username" class="form-control" required><div id="codeStatus" class="code-status"></div></div>
<div class="form-group"><label>RTM ID</label><div style="display: flex; gap: 8px;"><input type="text" id="rtmId" class="form-control" maxlength="9" style="flex:1;"><button type="button" id="btnGenerarRtmId" class="btn btn-primary"><i class="fas fa-sync-alt"></i></button></div><div id="rtmStatus" class="code-status"></div></div>
</div>
<div class="form-row">
<div class="form-group"><label>Nombre</label><input type="text" id="firstName" class="form-control" required></div>
<div class="form-group"><label>Apellido</label><input type="text" id="lastName" class="form-control" required></div>
</div>
<div class="form-row">
<div class="form-group"><label>Posición</label><select id="posicionLaboral" class="form-control"><option value="">Seleccionar</option><option value="DIRECTOR">DIRECTOR</option><option value="GERENTE">GERENTE</option><option value="SUPERVISOR">SUPERVISOR</option><option value="MANDO MEDIO">MANDO MEDIO</option><option value="DE LINEA">DE LINEA</option></select></div>
<div class="form-group"><label>Turno</label><select id="turnoHoras" class="form-control"><option value="8">8 horas</option><option value="12">12 horas</option></select></div>
</div>
<div class="form-row">
<div class="form-group"><label>Fecha Ingreso</label><input type="date" id="fechaIngreso" class="form-control"></div>
<div class="form-group"><label>Departamento</label><input type="text" id="departamento" class="form-control"></div>
</div>
<div class="form-row">
<div class="form-group"><label>Área Trabajo</label><input type="text" id="areaTrabajo" class="form-control"></div>
<div class="form-group"><label>Jefe Inmediato</label><input type="text" id="jefeCargo" class="form-control"></div>
</div>
<div class="form-group"><label>Foto</label><button type="button" id="btnAbrirCamara" class="btn-icon-camera"><i class="fas fa-camera"></i></button><input type="hidden" id="fotoBase64"><div id="fotoPreview" style="margin-top: 10px;"></div></div>
<div style="display: flex; gap: 10px;"><button type="submit" class="btn btn-primary" style="flex:1;"><i class="fas fa-save"></i> <span id="btnSubmitText">GUARDAR</span></button><button type="button" id="btnCancelarEdit" class="btn btn-secondary" style="display: none;">CANCELAR</button></div>
</form>
</div>
</div>
<div id="pageLista" class="session-content" style="display: none;">
<div class="card"><input type="text" id="listaSearchInput" class="search-input" placeholder="Filtrar colaboradores..." style="margin-bottom: 15px;"><div id="employeesGrid" class="employees-grid"></div></div>
</div>
<div id="pageConfiguracion" class="session-content" style="display: none;">
<div class="config-section">
<h3 style="color: var(--primary); margin-bottom: 20px;"><i class="fas fa-sliders-h"></i> Configuración del Carrusel</h3>
<div class="config-group"><label>Forma de imagen</label><select id="configImgShape" class="config-select"><option value="circle">Redondo</option><option value="square">Cuadrado</option><option value="rounded">Esquinas redondeadas</option></select></div>
<div class="config-group"><label>Número de items visibles</label><select id="configRows" class="config-select"><option value="2">2 items</option><option value="3">3 items</option><option value="4">4 items</option><option value="6">6 items</option><option value="1">1 item centrado (más grande)</option></select></div>
<div class="config-group"><label>Posición del nombre</label><select id="configNamePosition" class="config-select"><option value="bottom">Debajo de la foto</option><option value="top">Encima de la foto</option></select></div>
<div class="config-group"><label>Modo de navegación</label><select id="configNavMode" class="config-select"><option value="auto">Automático</option><option value="manual">Solo manual</option><option value="both">Ambos</option></select></div>
<div class="config-group"><label>Comportamiento al final</label><select id="configLoopMode" class="config-select"><option value="loop">Loop infinito</option><option value="stop">Detener al final</option><option value="back">Regresar al inicio</option></select></div>
<div class="config-group"><label>Velocidad automática (ms)</label><input type="number" id="configAutoSpeed" class="config-input" value="3000" step="500"></div>
<button id="saveConfigBtn" class="btn btn-primary"><i class="fas fa-save"></i> Guardar Configuración</button>
</div>
</div>
</div>
</div>
<nav class="bottom-nav" id="bottomNav">
<button class="nav-item active" id="navHome"><i class="fas fa-home"></i><span>Home</span></button>
<button class="nav-item" id="navRegistro"><i class="fas fa-user-plus"></i><span>Registro</span></button>
<button class="nav-item" id="navLista"><i class="fas fa-list"></i><span>Lista</span></button>
<button class="nav-item" id="navConfig"><i class="fas fa-cog"></i><span>Config</span></button>
</nav>
<div id="detailPage" class="detail-page"><div class="detail-header"><button id="backFromDetail"><i class="fas fa-arrow-left"></i></button><h3>Detalle</h3></div><div class="detail-avatar"><img id="detailImg"><div class="detail-name" id="detailName"></div></div><div class="detail-info-grid" id="detailInfoGrid"></div><div class="detail-actions"><button id="sendToWhatsAppBtn" class="btn-whatsapp" style="background:#25D366; padding:10px 20px; border-radius:50px;"><i class="fab fa-whatsapp"></i> WhatsApp</button><button id="editFromDetailBtn" class="btn btn-primary">Editar</button></div></div>
<div id="deleteModal" class="modal"><div class="modal-content"><h3>Confirmar</h3><p>¿Eliminar este colaborador?</p><div style="display:flex; gap:10px;"><button id="confirmDeleteBtn" class="btn btn-danger">Eliminar</button><button id="cancelDeleteBtn" class="btn btn-secondary">Cancelar</button></div></div></div>
<!-- Elementos de cámara -->
<div id="cameraFullscreen" class="camera-fullscreen">
<div class="camera-header">
<button class="btn-camera-icon" id="btnCerrarCamara"><i class="fas fa-times"></i></button>
<button class="btn-camera-icon" id="btnSwitchCamara"><i class="fas fa-sync-alt"></i></button>
</div>
<div class="camera-preview-container">
<video id="cameraVideo" autoplay playsinline></video>
<div class="camera-overlay">
<div class="face-message" id="faceMessage">
<i class="fas fa-info-circle"></i>
<span>Alinea el rostro</span>
</div>
</div>
</div>
<div class="camera-footer">
<button class="btn-camera-circle" id="btnCapturarFoto"></button>
</div>
</div>
<div id="previewScreen" class="preview-screen">
<div class="camera-header">
<button class="btn-camera-icon" id="btnCerrarPreview"><i class="fas fa-times"></i></button>
</div>
<div class="preview-image">
<img id="previewImage" src="" alt="Preview">
</div>
<div class="preview-footer">
<button class="btn btn-secondary" id="btnRepetirFoto"><i class="fas fa-redo-alt"></i> Repetir</button>
<button class="btn btn-primary" id="btnGuardarFoto"><i class="fas fa-check"></i> Guardar</button>
</div>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.3/firebase-app.js";
import { getFirestore, collection, query, where, getDocs, addDoc, updateDoc, deleteDoc, doc, Timestamp, onSnapshot, setDoc, getDoc } from "https://www.gstatic.com/firebasejs/10.12.3/firebase-firestore.js";
const firebaseConfig = { apiKey: "AIzaSyAMTWJr3mISmNiP-e_KjCO9BdBPi7Uuug4", authDomain: "formulario-2-8929a.firebaseapp.com", projectId: "formulario-2-8929a", storageBucket: "formulario-2-8929a.appspot.com", messagingSenderId: "136908102526", appId: "1:136908102526:web:d0a3bc1e3cb91a3fcab12f" };
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
let currentUser = null, empleados = [], empleadoAEliminar = null, carruselInterval = null;
let stream = null;
let currentFacingMode = 'environment'; // CAMBIADO: Ahora abre por defecto en cámara trasera
let modelosCargados = false;
const configDefaults = { imgShape: "circle", rows: "3", namePosition: "bottom", navMode: "both", loopMode: "loop", autoSpeed: 3000 };
let userConfig = { ...configDefaults };
const showLoading = (show) => document.getElementById('loadingOverlay').classList.toggle('active', show);
const showSuccess = (msg) => { document.getElementById('successMessage').innerText = msg; document.getElementById('successModal').classList.add('active'); };
function showAlert(message, type = 'success') {
const alertDiv = document.createElement('div');
alertDiv.style.cssText = `position:fixed;top:20px;right:20px;background:${type === 'success' ? '#00ff9d' : '#ff4757'};color:#000;padding:12px 20px;border-radius:50px;z-index:5000;font-size:14px;animation:slideIn 0.3s ease;`;
alertDiv.innerHTML = `<i class="fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'}"></i> ${msg}`;
document.body.appendChild(alertDiv);
setTimeout(() => alertDiv.remove(), 3000);
}
async function cargarConfiguracion() { if(!currentUser) return; const docRef = doc(db, 'UserConfig', currentUser.uid); const docSnap = await getDoc(docRef); if(docSnap.exists()) userConfig = { ...configDefaults, ...docSnap.data() }; else await setDoc(docRef, configDefaults); cargarValoresConfigUI(); aplicarConfigCarruselCompleto(); }
function cargarValoresConfigUI() { document.getElementById('configImgShape').value = userConfig.imgShape; document.getElementById('configRows').value = userConfig.rows; document.getElementById('configNamePosition').value = userConfig.namePosition; document.getElementById('configNavMode').value = userConfig.navMode; document.getElementById('configLoopMode').value = userConfig.loopMode; document.getElementById('configAutoSpeed').value = userConfig.autoSpeed; }
async function guardarConfiguracion() { if(!currentUser) return; const nuevaConfig = { imgShape: document.getElementById('configImgShape').value, rows: document.getElementById('configRows').value, namePosition: document.getElementById('configNamePosition').value, navMode: document.getElementById('configNavMode').value, loopMode: document.getElementById('configLoopMode').value, autoSpeed: parseInt(document.getElementById('configAutoSpeed').value) }; await setDoc(doc(db, 'UserConfig', currentUser.uid), nuevaConfig); userConfig = nuevaConfig; aplicarConfigCarruselCompleto(); showSuccess('Configuración guardada y aplicada'); }
function aplicarConfigCarruselCompleto() {
const items = document.querySelectorAll('#carouselTrack .carousel-item');
const rowsVal = parseInt(userConfig.rows);
let itemWidth;
if(rowsVal === 1) itemWidth = 220;
else if(rowsVal === 2) itemWidth = 140;
else if(rowsVal === 3) itemWidth = 105;
else if(rowsVal === 4) itemWidth = 85;
else itemWidth = 75;
const track = document.querySelector('#carouselTrack');
if(rowsVal === 1) { track.style.justifyContent = 'center'; track.style.gap = '0px'; }
else { track.style.justifyContent = 'flex-start'; track.style.gap = '15px'; }
items.forEach(item => {
item.style.flex = `0 0 ${itemWidth}px`;
const img = item.querySelector('img');
if(img) {
if(userConfig.imgShape === 'circle') img.style.borderRadius = '50%';
else if(userConfig.imgShape === 'square') img.style.borderRadius = '0%';
else if(userConfig.imgShape === 'rounded') img.style.borderRadius = '20px';
img.style.width = `${itemWidth}px`;
img.style.height = `${itemWidth}px`;
}
const span = item.querySelector('span');
if(span) span.style.order = userConfig.namePosition === 'top' ? '-1' : '0';
});
if(carruselInterval) { clearInterval(carruselInterval); carruselInterval = null; }
if(userConfig.navMode === 'auto' || userConfig.navMode === 'both') { carruselInterval = setInterval(() => moverCarrusel(1), userConfig.autoSpeed); }
crearBotonesCarrusel();
}
function crearBotonesCarrusel() {
const controlsDiv = document.getElementById('carouselControls');
controlsDiv.innerHTML = '<button class="carousel-control-btn" id="carouselPrev"><i class="fas fa-chevron-left"></i></button><button class="carousel-control-btn" id="carouselNext"><i class="fas fa-chevron-right"></i></button>';
document.getElementById('carouselPrev')?.addEventListener('click', () => moverCarrusel(-1));
document.getElementById('carouselNext')?.addEventListener('click', () => moverCarrusel(1));
}
function moverCarrusel(direccion) {
const track = document.getElementById('carouselTrack');
if(!track || !track.children.length) return;
const itemWidth = track.children[0].offsetWidth + (parseInt(getComputedStyle(track).gap) || 15);
let newScroll = track.scrollLeft + (direccion * itemWidth);
if(userConfig.loopMode === 'loop') {
if(newScroll < 0) newScroll = track.scrollWidth - track.clientWidth;
else if(newScroll > track.scrollWidth - track.clientWidth) newScroll = 0;
} else if(userConfig.loopMode === 'back') {
if(newScroll < 0) newScroll = 0;
else if(newScroll > track.scrollWidth - track.clientWidth) newScroll = track.scrollWidth - track.clientWidth;
} else {
if(newScroll < 0) newScroll = 0;
if(newScroll > track.scrollWidth - track.clientWidth) newScroll = track.scrollWidth - track.clientWidth;
}
track.scrollTo({ left: newScroll, behavior: 'smooth' });
}
function actualizarCarrusel() {
if(!empleados.length) { document.getElementById('carouselTrack').innerHTML = '<div style="text-align:center; padding:20px;">No hay colaboradores</div>'; return; }
const shuffled = [...empleados].sort(() => 0.5 - Math.random()).slice(0, 20);
document.getElementById('carouselTrack').innerHTML = shuffled.map(emp => `<div class="carousel-item" onclick="window.verDetalle('${emp.id}')"><img src="${emp.fotoBase64 || 'https://via.placeholder.com/80'}" onerror="this.src='https://via.placeholder.com/80'"><span>${emp.firstName || ''} ${emp.lastName || ''}</span></div>`).join('');
aplicarConfigCarruselCompleto();
}
function actualizarStats() {
document.getElementById('statTotal').innerText = empleados.length;
const sevenDaysAgo = new Date(); sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
const recent = empleados.filter(e => e.createdAt && e.createdAt.toDate && e.createdAt.toDate() > sevenDaysAgo).length;
document.getElementById('statRecent').innerText = recent;
const areas = new Set(empleados.map(e => e.areaTrabajo).filter(a => a));
document.getElementById('statAreas').innerText = areas.size;
const sorted = [...empleados].sort((a,b) => (b.createdAt?.toDate?.() || 0) - (a.createdAt?.toDate?.() || 0)).slice(0,5);
document.getElementById('recentEmployees').innerHTML = sorted.map(emp => `<div class="recent-item" onclick="window.verDetalle('${emp.id}')"><img src="${emp.fotoBase64 || 'https://via.placeholder.com/35'}"><span>${emp.firstName} ${emp.lastName}</span><span style="margin-left:auto; font-size:10px; color:var(--primary);">${emp.rtmId || ''}</span></div>`).join('');
}
async function verificarRtmGlobal(rtm, idExcluir=null) { const q = query(collection(db, 'Ponche'), where('rtmId', '==', rtm)); const snap = await getDocs(q); if(snap.empty) return true; if(idExcluir && snap.docs[0].id === idExcluir) return true; return false; }
async function verificarCodigoNomina(codigo, idExcluir=null) { if(!currentUser) return false; const q = query(collection(db, 'Ponche'), where('username', '==', codigo), where('collaboratorId', '==', currentUser.uid)); const snap = await getDocs(q); if(snap.empty) return true; if(idExcluir && snap.docs[0].id === idExcluir) return true; return false; }
function iniciarEscuchaEmpleados() { if(!currentUser) return; const q = query(collection(db, 'Ponche'), where('collaboratorId', '==', currentUser.uid)); onSnapshot(q, (snap) => { empleados = []; snap.forEach(doc => empleados.push({ id: doc.id, ...doc.data() })); mostrarListaEmpleados(); actualizarCarrusel(); actualizarBuscadorGlobal(); actualizarStats(); }); }
function mostrarListaEmpleados(filtro='') { let f = empleados.filter(e => !filtro || `${e.firstName || ''} ${e.lastName || ''}`.toLowerCase().includes(filtro.toLowerCase()) || (e.username||'').includes(filtro) || (e.rtmId||'').includes(filtro)); document.getElementById('employeesGrid').innerHTML = f.map(emp => `<div class="employee-card" onclick="window.verDetalle('${emp.id}')"><img src="${emp.fotoBase64||'https://via.placeholder.com/70'}" onerror="this.src='https://via.placeholder.com/70'"><div class="employee-name">${emp.firstName || ''} ${emp.lastName || ''}</div><div class="employee-code">${emp.rtmId||''}</div><div class="employee-actions"><button class="btn btn-primary" onclick="event.stopPropagation(); window.editarEmpleado('${emp.id}')"><i class="fas fa-edit"></i> Editar</button><button class="btn btn-danger" onclick="event.stopPropagation(); window.confirmarEliminar('${emp.id}')"><i class="fas fa-trash"></i></button></div></div>`).join(''); }
function actualizarBuscadorGlobal() { const term = document.getElementById('globalSearchInput').value.toLowerCase(); if(!term) { document.getElementById('globalSearchResults').innerHTML = ''; return; } const res = empleados.filter(e => `${e.firstName || ''} ${e.lastName || ''}`.toLowerCase().includes(term) || (e.username||'').includes(term) || (e.rtmId||'').includes(term)); document.getElementById('globalSearchResults').innerHTML = res.map(emp => `<div class="search-result-item" onclick="window.verDetalle('${emp.id}')" style="background:rgba(255,255,255,0.05);border-radius:15px;padding:10px;text-align:center;cursor:pointer;"><img src="${emp.fotoBase64||'https://via.placeholder.com/60'}" style="width:60px;height:60px;border-radius:50%;object-fit:cover;"><div>${emp.firstName || ''} ${emp.lastName || ''}</div><div style="font-size:10px; color:var(--primary);">${emp.rtmId||''}</div></div>`).join(''); }
window.verDetalle = (id) => { const emp = empleados.find(e=>e.id===id); if(!emp) return; document.getElementById('detailImg').src = emp.fotoBase64 || 'https://via.placeholder.com/120'; document.getElementById('detailName').innerText = `${emp.firstName || ''} ${emp.lastName || ''}`; document.getElementById('detailInfoGrid').innerHTML = `<div class="detail-info-item"><div class="detail-info-label">RTM ID</div><div>${emp.rtmId || 'N/A'}</div></div><div class="detail-info-item"><div class="detail-info-label">Código Nómina</div><div>${emp.username || 'N/A'}</div></div><div class="detail-info-item"><div class="detail-info-label">Posición</div><div>${emp.posicionLaboral || 'N/A'}</div></div><div class="detail-info-item"><div class="detail-info-label">Área</div><div>${emp.areaTrabajo || 'N/A'}</div></div><div class="detail-info-item"><div class="detail-info-label">Turno</div><div>${emp.turnoHoras || 'N/A'} horas</div></div>`; document.getElementById('detailPage').style.display = 'block'; empleadoAEliminar = emp.id; };
window.editarEmpleado = (id) => { const emp = empleados.find(e=>e.id===id); if(!emp) return; window.cambiarSession('pageRegistro'); document.getElementById('editId').value = emp.id; document.getElementById('username').value = emp.username || ''; document.getElementById('rtmId').value = emp.rtmId || ''; document.getElementById('rtmId').disabled = true; document.getElementById('firstName').value = emp.firstName || ''; document.getElementById('lastName').value = emp.lastName || ''; document.getElementById('posicionLaboral').value = emp.posicionLaboral || ''; document.getElementById('turnoHoras').value = emp.turnoHoras || '8'; document.getElementById('fechaIngreso').value = emp.fechaIngreso || ''; document.getElementById('departamento').value = emp.departamento || ''; document.getElementById('areaTrabajo').value = emp.areaTrabajo || ''; document.getElementById('jefeCargo').value = emp.jefeCargo || ''; document.getElementById('fotoBase64').value = emp.fotoBase64 || ''; document.getElementById('fotoPreview').innerHTML = emp.fotoBase64 ? `<img src="${emp.fotoBase64}" style="width:70px; height:70px; object-fit:cover; border-radius:50%; border:2px solid var(--primary);">` : ''; document.getElementById('btnSubmitText').innerText = 'ACTUALIZAR'; document.getElementById('btnCancelarEdit').style.display = 'block'; };
window.confirmarEliminar = (id) => { empleadoAEliminar = id; document.getElementById('deleteModal').classList.add('active'); };
window.cambiarSession = (sessionId) => { const sections = ['homeSection', 'pageRegistro', 'pageLista', 'pageConfiguracion']; sections.forEach(s => { const el = document.getElementById(s); if(el) el.style.display = s === sessionId ? 'block' : 'none'; }); document.querySelectorAll('.nav-item').forEach(i=>i.classList.remove('active')); if(sessionId === 'homeSection') document.getElementById('navHome').classList.add('active'); if(sessionId === 'pageRegistro') document.getElementById('navRegistro').classList.add('active'); if(sessionId === 'pageLista') document.getElementById('navLista').classList.add('active'); if(sessionId === 'pageConfiguracion') document.getElementById('navConfig').classList.add('active'); };
// Funciones de cámara - AHORA CON CÁMARA TRASERA POR DEFECTO
async function iniciarCamara() {
detenerCamara();
try {
const constraints = { video: { facingMode: currentFacingMode, width: { ideal: 1280 }, height: { ideal: 720 } } };
stream = await navigator.mediaDevices.getUserMedia(constraints);
const video = document.getElementById('cameraVideo');
video.srcObject = stream;
} catch (error) {
// Si falla la cámara trasera, intentar con la delantera
if (currentFacingMode === 'environment') {
currentFacingMode = 'user';
try {
const constraints = { video: { facingMode: 'user', width: { ideal: 1280 }, height: { ideal: 720 } } };
stream = await navigator.mediaDevices.getUserMedia(constraints);
const video = document.getElementById('cameraVideo');
video.srcObject = stream;
} catch (e) {
showAlert('Error al abrir cámara', 'error');
}
} else {
showAlert('Error al abrir cámara', 'error');
}
}
}
function detenerCamara() {
if (stream) { stream.getTracks().forEach(track => track.stop()); stream = null; }
const video = document.getElementById('cameraVideo');
if (video) video.srcObject = null;
}
async function capturarFoto() {
const video = document.getElementById('cameraVideo');
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
const ctx = canvas.getContext('2d');
if (currentFacingMode === 'user') {
ctx.translate(canvas.width, 0);
ctx.scale(-1, 1);
}
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const base64 = canvas.toDataURL('image/jpeg', 0.9);
document.getElementById('previewImage').src = base64;
document.getElementById('cameraFullscreen').classList.remove('active');
document.getElementById('previewScreen').classList.add('active');
}
function guardarFoto() {
const imgSrc = document.getElementById('previewImage').src;
document.getElementById('fotoBase64').value = imgSrc;
document.getElementById('fotoPreview').innerHTML = `<img src="${imgSrc}" style="width:70px; height:70px; object-fit:cover; border-radius:50%; border:2px solid var(--primary);">`;
document.getElementById('previewScreen').classList.remove('active');
showAlert('Foto guardada');
}
document.getElementById('btnAbrirCamara').addEventListener('click', () => {
document.getElementById('cameraFullscreen').classList.add('active');
iniciarCamara();
});
document.getElementById('btnCerrarCamara').addEventListener('click', () => {
detenerCamara();
document.getElementById('cameraFullscreen').classList.remove('active');
});
document.getElementById('btnSwitchCamara').addEventListener('click', () => {
currentFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
iniciarCamara();
});
document.getElementById('btnCapturarFoto').addEventListener('click', capturarFoto);
document.getElementById('btnCerrarPreview').addEventListener('click', () => {
document.getElementById('previewScreen').classList.remove('active');
document.getElementById('cameraFullscreen').classList.add('active');
iniciarCamara();
});
document.getElementById('btnRepetirFoto').addEventListener('click', () => {
document.getElementById('previewScreen').classList.remove('active');
document.getElementById('cameraFullscreen').classList.add('active');
iniciarCamara();
});
document.getElementById('btnGuardarFoto').addEventListener('click', guardarFoto);
document.getElementById('navHome').onclick = () => window.cambiarSession('homeSection');
document.getElementById('navRegistro').onclick = () => { window.cambiarSession('pageRegistro'); document.getElementById('rtmId').disabled = false; document.getElementById('btnCancelarEdit').click(); };
document.getElementById('navLista').onclick = () => window.cambiarSession('pageLista');
document.getElementById('navConfig').onclick = () => { window.cambiarSession('pageConfiguracion'); cargarConfiguracion(); };
document.getElementById('saveConfigBtn').onclick = guardarConfiguracion;
document.getElementById('btnGenerarRtmId').onclick = async () => { showLoading(true); try { for(let i=0;i<100;i++){ const r=`RTM${Math.floor(100000+Math.random()*900000)}`; if(await verificarRtmGlobal(r)){ document.getElementById('rtmId').value = r; document.getElementById('rtmStatus').innerHTML = '<i class="fas fa-check-circle"></i> RTM disponible'; document.getElementById('rtmStatus').className = 'code-status available'; break; } } } catch(e){ } finally { showLoading(false); } };
document.getElementById('btnCancelarEdit').onclick = () => { document.getElementById('registroForm').reset(); document.getElementById('editId').value = ''; document.getElementById('fotoPreview').innerHTML = ''; document.getElementById('fotoBase64').value = ''; document.getElementById('btnSubmitText').innerText = 'GUARDAR'; document.getElementById('btnCancelarEdit').style.display = 'none'; document.getElementById('rtmId').disabled = false; };
document.getElementById('backFromDetail').onclick = () => document.getElementById('detailPage').style.display = 'none';
document.getElementById('sendToWhatsAppBtn').onclick = () => { const emp = empleados.find(e=>e.id===empleadoAEliminar); if(emp) window.open(`https://wa.me/?text=${encodeURIComponent(`${emp.firstName} ${emp.lastName} - RTM: ${emp.rtmId}`)}`, '_blank'); };
document.getElementById('editFromDetailBtn').onclick = () => { const emp = empleados.find(e=>e.id===empleadoAEliminar); if(emp) { document.getElementById('detailPage').style.display = 'none'; window.editarEmpleado(emp.id); } };
document.getElementById('confirmDeleteBtn').onclick = async () => { if(empleadoAEliminar){ showLoading(true); await deleteDoc(doc(db,'Ponche',empleadoAEliminar)); showSuccess('Colaborador eliminado'); empleadoAEliminar=null; document.getElementById('deleteModal').classList.remove('active'); showLoading(false); } };
document.getElementById('cancelDeleteBtn').onclick = () => document.getElementById('deleteModal').classList.remove('active');
document.getElementById('registroForm').onsubmit = async (e) => { e.preventDefault(); if(!currentUser) return; const id = document.getElementById('editId').value; const data = { username: document.getElementById('username').value.trim(), rtmId: document.getElementById('rtmId').value.trim().toUpperCase(), firstName: document.getElementById('firstName').value.trim(), lastName: document.getElementById('lastName').value.trim(), posicionLaboral: document.getElementById('posicionLaboral').value, turnoHoras: parseInt(document.getElementById('turnoHoras').value), fechaIngreso: document.getElementById('fechaIngreso').value, departamento: document.getElementById('departamento').value, areaTrabajo: document.getElementById('areaTrabajo').value, jefeCargo: document.getElementById('jefeCargo').value, fotoBase64: document.getElementById('fotoBase64').value, collaboratorId: currentUser.uid, updatedAt: Timestamp.now() }; if(!data.username || !data.firstName || !data.lastName) return; if(!data.rtmId.startsWith('RTM') || data.rtmId.length!==9) return; if(!data.fotoBase64 && !id) return; if(!await verificarCodigoNomina(data.username, id)) return; if(!await verificarRtmGlobal(data.rtmId, id)) return; showLoading(true); try { if(id) await updateDoc(doc(db,'Ponche',id), data); else { data.createdAt = Timestamp.now(); await addDoc(collection(db,'Ponche'), data); } showSuccess(id ? 'Colaborador actualizado' : 'Colaborador registrado'); document.getElementById('btnCancelarEdit').click(); } catch(error) { } finally { showLoading(false); } };
document.getElementById('loginBtn').onclick = async () => { const user = document.getElementById('loginUsername').value.trim(), pass = document.getElementById('loginPassword').value.trim(); if(!user||!pass) return; showLoading(true); try { const q = query(collection(db,"Collaborators"), where("username","==",user), where("pin","==",pass)); const snap = await getDocs(q); if(snap.empty) throw new Error(); const userDoc = snap.docs[0]; currentUser = { uid: userDoc.id, name: userDoc.data().companyName || user }; localStorage.setItem('currentUserRegistro', JSON.stringify(currentUser)); document.getElementById('companyDisplay').innerText = currentUser.name; document.getElementById('welcomeUserName').innerText = currentUser.name; document.getElementById('loginScreen').style.display = 'none'; document.getElementById('appScreen').style.display = 'block'; document.getElementById('bottomNav').classList.add('visible'); iniciarEscuchaEmpleados(); window.cambiarSession('homeSection'); cargarConfiguracion(); } catch(e) { document.getElementById('loginAlert').innerText = 'Credenciales incorrectas'; document.getElementById('loginAlert').style.display = 'block'; } finally { showLoading(false); } };
document.getElementById('logoutBtn').onclick = () => { localStorage.removeItem('currentUserRegistro'); currentUser = null; if(carruselInterval) clearInterval(carruselInterval); document.getElementById('appScreen').style.display = 'none'; document.getElementById('loginScreen').style.display = 'flex'; document.getElementById('bottomNav').classList.remove('visible'); };
document.getElementById('globalSearchInput').addEventListener('input', actualizarBuscadorGlobal);
document.getElementById('listaSearchInput').addEventListener('input', (e) => mostrarListaEmpleados(e.target.value));
const saved = localStorage.getItem('currentUserRegistro'); if(saved) { try { currentUser = JSON.parse(saved); if(currentUser?.uid) { document.getElementById('loginScreen').style.display = 'none'; document.getElementById('appScreen').style.display = 'block'; document.getElementById('bottomNav').classList.add('visible'); document.getElementById('companyDisplay').innerText = currentUser.name; document.getElementById('welcomeUserName').innerText = currentUser.name; iniciarEscuchaEmpleados(); window.cambiarSession('homeSection'); cargarConfiguracion(); } } catch(e){} }
</script>
</body>
</html>