Spaces:
Running

File size: 33,526 Bytes
9522519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sistema de Notas - Concreteira</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .scrollbar-hide::-webkit-scrollbar {
            display: none;
        }
        
        .scrollbar-hide {
            -ms-overflow-style: none;
            scrollbar-width: none;
        }
        
        .gradient-bg {
            background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .fade-in {
            animation: fadeIn 0.5s ease-out forwards;
        }
        
        .note-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="gradient-bg text-white py-6 px-4 shadow-lg">
        <div class="container mx-auto flex justify-between items-center">
            <div class="flex items-center space-x-3">
                <i class="fas fa-truck-mix text-3xl"></i>
                <h1 class="text-2xl font-bold">Concreteira<span class="text-blue-200">Ltda</span></h1>
            </div>
            <button id="themeToggle" class="p-2 rounded-full bg-white bg-opacity-20 hover:bg-opacity-30 transition">
                <i class="fas fa-moon text-white"></i>
            </button>
        </div>
    </div>

    <div class="container mx-auto px-4 py-8">
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
            <!-- Formulário de Cadastro -->
            <div class="bg-white rounded-xl shadow-md p-6 fade-in">
                <h2 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-file-invoice-dollar mr-2 text-blue-500"></i>
                    Cadastrar Nota Fiscal
                </h2>
                <form id="noteForm" class="space-y-4">
                    <div>
                        <label for="noteNumber" class="block text-sm font-medium text-gray-700 mb-1">Número da Nota</label>
                        <input type="text" id="noteNumber" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                    </div>
                    
                    <div>
                        <label for="client" class="block text-sm font-medium text-gray-700 mb-1">Cliente</label>
                        <input type="text" id="client" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                    </div>
                    
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <label for="date" class="block text-sm font-medium text-gray-700 mb-1">Data</label>
                            <input type="date" id="date" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                        </div>
                        
                        <div>
                            <label for="value" class="block text-sm font-medium text-gray-700 mb-1">Valor (R$)</label>
                            <input type="number" step="0.01" id="value" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                        </div>
                    </div>
                    
                    <div>
                        <label for="mixType" class="block text-sm font-medium text-gray-700 mb-1">Tipo de Concreto</label>
                        <select id="mixType" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                            <option value="">Selecione...</option>
                            <option value="FCK25">Concreto FCK 25 MPa</option>
                            <option value="FCK30">Concreto FCK 30 MPa</option>
                            <option value="FCK35">Concreto FCK 35 MPa</option>
                            <option value="FCK40">Concreto FCK 40 MPa</option>
                            <option value="Bombeado">Concreto Bombeado</option>
                        </select>
                    </div>
                    
                    <div>
                        <label for="quantity" class="block text-sm font-medium text-gray-700 mb-1">Quantidade (m³)</label>
                        <input type="number" step="0.1" id="quantity" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                    </div>
                    
                    <div>
                        <label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
                        <select id="status" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                            <option value="pending">Pendente</option>
                            <option value="paid">Pago</option>
                            <option value="delivered">Entregue</option>
                            <option value="canceled">Cancelado</option>
                        </select>
                    </div>
                    
                    <div>
                        <label for="notes" class="block text-sm font-medium text-gray-700 mb-1">Observações</label>
                        <textarea id="notes" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition"></textarea>
                    </div>
                    
                    <button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition flex items-center justify-center">
                        <i class="fas fa-save mr-2"></i> Cadastrar Nota
                    </button>
                </form>
            </div>
            
            <!-- Listagem de Notas -->
            <div class="bg-white rounded-xl shadow-md p-6 fade-in">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-xl font-bold text-gray-800 flex items-center">
                        <i class="fas fa-list-check mr-2 text-blue-500"></i>
                        Notas Cadastradas
                    </h2>
                    <div class="relative">
                        <input type="text" id="searchInput" placeholder="Buscar..." class="pl-8 pr-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                        <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
                    </div>
                </div>
                
                <div class="overflow-auto max-h-[600px] scrollbar-hide">
                    <table id="notesTable" class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nota</th>
                                <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cliente</th>
                                <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Data</th>
                                <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valor</th>
                                <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
                                <th class="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
                            </tr>
                        </thead>
                        <tbody id="notesList" class="bg-white divide-y divide-gray-200">
                            <!-- Notas serão adicionadas aqui via JavaScript -->
                        </tbody>
                    </table>
                    <p id="emptyMessage" class="text-center py-4 text-gray-500">Nenhuma nota cadastrada ainda.</p>
                </div>
                
                <div class="mt-4 flex justify-between items-center">
                    <div>
                        <label for="itemsPerPage" class="text-sm text-gray-600">Itens por página:</label>
                        <select id="itemsPerPage" class="ml-2 border border-gray-300 rounded-md px-2 py-1 focus:ring-blue-500 focus:border-blue-500">
                            <option value="5">5</option>
                            <option value="10" selected>10</option>
                            <option value="20">20</option>
                            <option value="50">50</option>
                        </select>
                    </div>
                    <div id="pagination" class="flex space-x-2">
                        <!-- Pagination will be added here by JavaScript -->
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Modal para edição -->
    <div id="editModal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50 px-4">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-md max-h-[90vh] overflow-y-auto">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-lg font-bold text-gray-800">Editar Nota</h3>
                    <button id="closeModal" class="text-gray-500 hover:text-gray-700">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
                <form id="editForm" class="space-y-4">
                    <input type="hidden" id="editId">
                    <div>
                        <label for="editNoteNumber" class="block text-sm font-medium text-gray-700 mb-1">Número da Nota</label>
                        <input type="text" id="editNoteNumber" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                    </div>
                    
                    <div>
                        <label for="editClient" class="block text-sm font-medium text-gray-700 mb-1">Cliente</label>
                        <input type="text" id="editClient" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                    </div>
                    
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <label for="editDate" class="block text-sm font-medium text-gray-700 mb-1">Data</label>
                            <input type="date" id="editDate" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                        </div>
                        
                        <div>
                            <label for="editValue" class="block text-sm font-medium text-gray-700 mb-1">Valor (R$)</label>
                            <input type="number" step="0.01" id="editValue" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                        </div>
                    </div>
                    
                    <div>
                        <label for="editMixType" class="block text-sm font-medium text-gray-700 mb-1">Tipo de Concreto</label>
                        <select id="editMixType" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                            <option value="FCK25">Concreto FCK 25 MPa</option>
                            <option value="FCK30">Concreto FCK 30 MPa</option>
                            <option value="FCK35">Concreto FCK 35 MPa</option>
                            <option value="FCK40">Concreto FCK 40 MPa</option>
                            <option value="Bombeado">Concreto Bombeado</option>
                        </select>
                    </div>
                    
                    <div>
                        <label for="editQuantity" class="block text-sm font-medium text-gray-700 mb-1">Quantidade (m³)</label>
                        <input type="number" step="0.1" id="editQuantity" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                    </div>
                    
                    <div>
                        <label for="editStatus" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
                        <select id="editStatus" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
                            <option value="pending">Pendente</option>
                            <option value="paid">Pago</option>
                            <option value="delivered">Entregue</option>
                            <option value="canceled">Cancelado</option>
                        </select>
                    </div>
                    
                    <div>
                        <label for="editNotes" class="block text-sm font-medium text-gray-700 mb-1">Observações</label>
                        <textarea id="editNotes" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition"></textarea>
                    </div>
                    
                    <div class="flex space-x-4">
                        <button type="submit" class="flex-1 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition flex items-center justify-center">
                            <i class="fas fa-save mr-2"></i> Salvar
                        </button>
                        <button id="deleteNote" type="button" class="flex-1 bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-4 rounded-md transition flex items-center justify-center">
                            <i class="fas fa-trash-alt mr-2"></i> Excluir
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Sample data - in a real app, this would come from a database
            let notes = JSON.parse(localStorage.getItem('concreteNotes')) || [];
            let currentPage = 1;
            let itemsPerPage = 10;
            
            // DOM Elements
            const noteForm = document.getElementById('noteForm');
            const editForm = document.getElementById('editForm');
            const notesList = document.getElementById('notesList');
            const emptyMessage = document.getElementById('emptyMessage');
            const editModal = document.getElementById('editModal');
            const closeModal = document.getElementById('closeModal');
            const deleteBtn = document.getElementById('deleteNote');
            const searchInput = document.getElementById('searchInput');
            const itemsPerPageSelect = document.getElementById('itemsPerPage');
            const paginationDiv = document.getElementById('pagination');
            const themeToggle = document.getElementById('themeToggle');
            
            // Initialize
            renderNotes();
            
            // Theme Toggle
            themeToggle.addEventListener('click', () => {
                document.body.classList.toggle('dark');
                
                if (document.body.classList.contains('dark')) {
                    themeToggle.innerHTML = '<i class="fas fa-sun text-white"></i>';
                    localStorage.setItem('theme', 'dark');
                } else {
                    themeToggle.innerHTML = '<i class="fas fa-moon text-white"></i>';
                    localStorage.setItem('theme', 'light');
                }
            });
            
            // Check for saved theme preference
            if (localStorage.getItem('theme') === 'dark') {
                document.body.classList.add('dark');
                themeToggle.innerHTML = '<i class="fas fa-sun text-white"></i>';
            }
            
            // Form submission - Add new note
            noteForm.addEventListener('submit', function(e) {
                e.preventDefault();
                
                const noteNumber = document.getElementById('noteNumber').value;
                const client = document.getElementById('client').value;
                const date = document.getElementById('date').value;
                const value = parseFloat(document.getElementById('value').value);
                const mixType = document.getElementById('mixType').value;
                const quantity = parseFloat(document.getElementById('quantity').value);
                const status = document.getElementById('status').value;
                const notesText = document.getElementById('notes').value;
                
                const newNote = {
                    id: Date.now().toString(),
                    noteNumber,
                    client,
                    date,
                    value,
                    mixType,
                    quantity,
                    status,
                    notes: notesText,
                    createdAt: new Date().toISOString()
                };
                
                notes.unshift(newNote);
                saveNotes();
                renderNotes();
                
                // Reset form
                noteForm.reset();
                
                // Show success message
                showAlert('Nota cadastrada com sucesso!', 'success');
            });
            
            // Edit form submission
            editForm.addEventListener('submit', function(e) {
                e.preventDefault();
                
                const id = document.getElementById('editId').value;
                const noteNumber = document.getElementById('editNoteNumber').value;
                const client = document.getElementById('editClient').value;
                const date = document.getElementById('editDate').value;
                const value = parseFloat(document.getElementById('editValue').value);
                const mixType = document.getElementById('editMixType').value;
                const quantity = parseFloat(document.getElementById('editQuantity').value);
                const status = document.getElementById('editStatus').value;
                const notesText = document.getElementById('editNotes').value;
                
                // Find and update note
                const noteIndex = notes.findIndex(note => note.id === id);
                if (noteIndex !== -1) {
                    notes[noteIndex] = {
                        ...notes[noteIndex],
                        noteNumber,
                        client,
                        date,
                        value,
                        mixType,
                        quantity,
                        status,
                        notes: notesText
                    };
                    
                    saveNotes();
                    renderNotes();
                    closeModal.click();
                    
                    // Show success message
                    showAlert('Nota atualizada com sucesso!', 'success');
                }
            });
            
            // Delete note
            deleteBtn.addEventListener('click', function() {
                const id = document.getElementById('editId').value;
                const confirmation = confirm('Tem certeza que deseja excluir esta nota?');
                
                if (confirmation) {
                    notes = notes.filter(note => note.id !== id);
                    saveNotes();
                    renderNotes();
                    closeModal.click();
                    
                    // Show success message
                    showAlert('Nota excluída com sucesso!', 'success');
                }
            });
            
            // Close modal
            closeModal.addEventListener('click', function() {
                editModal.classList.add('hidden');
            });
            
            // Search functionality
            searchInput.addEventListener('input', function() {
                currentPage = 1;
                renderNotes();
            });
            
            // Items per page
            itemsPerPageSelect.addEventListener('change', function() {
                itemsPerPage = parseInt(this.value);
                currentPage = 1;
                renderNotes();
            });
            
            // Helper functions
            function saveNotes() {
                localStorage.setItem('concreteNotes', JSON.stringify(notes));
            }
            
            function renderNotes() {
                const searchTerm = searchInput.value.toLowerCase();
                let filteredNotes = notes;
                
                // Filter by search term if exists
                if (searchTerm) {
                    filteredNotes = notes.filter(note => 
                        note.noteNumber.toLowerCase().includes(searchTerm) ||
                        note.client.toLowerCase().includes(searchTerm) ||
                        note.date.toLowerCase().includes(searchTerm)
                    );
                }
                
                // Calculate pagination
                const totalPages = Math.ceil(filteredNotes.length / itemsPerPage);
                const startIndex = (currentPage - 1) * itemsPerPage;
                const endIndex = startIndex + itemsPerPage;
                const paginatedNotes = filteredNotes.slice(startIndex, endIndex);
                
                // Clear existing notes
                notesList.innerHTML = '';
                
                // Show empty message if no notes
                if (paginatedNotes.length === 0) {
                    emptyMessage.classList.remove('hidden');
                } else {
                    emptyMessage.classList.add('hidden');
                    
                    // Render each note
                    paginatedNotes.forEach(note => {
                        const tr = document.createElement('tr');
                        tr.className = 'note-item hover:bg-gray-50 transition cursor-pointer';
                        
                        // Format date
                        const formattedDate = formatDate(note.date);
                        // Format currency
                        const formattedValue = new Intl.NumberFormat('pt-BR', {
                            style: 'currency',
                            currency: 'BRL'
                        }).format(note.value);
                        
                        // Status badge
                        let statusClass, statusText;
                        switch(note.status) {
                            case 'pending':
                                statusClass = 'bg-yellow-100 text-yellow-800';
                                statusText = 'Pendente';
                                break;
                            case 'paid':
                                statusClass = 'bg-green-100 text-green-800';
                                statusText = 'Pago';
                                break;
                            case 'delivered':
                                statusClass = 'bg-blue-100 text-blue-800';
                                statusText = 'Entregue';
                                break;
                            case 'canceled':
                                statusClass = 'bg-red-100 text-red-800';
                                statusText = 'Cancelado';
                                break;
                        }
                        
                        tr.innerHTML = `
                            <td class="px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900">${note.noteNumber}</td>
                            <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-500">${note.client}</td>
                            <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-500">${formattedDate}</td>
                            <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-500">${formattedValue}</td>
                            <td class="px-4 py-3 whitespace-nowrap text-sm font-medium">
                                <span class="px-2 py-1 text-xs rounded-full ${statusClass}">${statusText}</span>
                            </td>
                            <td class="px-4 py-3 whitespace-nowrap text-right text-sm font-medium">
                                <button class="text-blue-600 hover:text-blue-900 edit-btn mr-3" data-id="${note.id}">
                                    <i class="fas fa-edit"></i>
                                </button>
                                <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${note.id}">
                                    <i class="fas fa-trash-alt"></i>
                                </button>
                            </td>
                        `;
                        
                        notesList.appendChild(tr);
                    });
                    
                    // Add event listeners to edit/delete buttons
                    document.querySelectorAll('.edit-btn').forEach(btn => {
                        btn.addEventListener('click', function(e) {
                            e.stopPropagation();
                            const id = this.getAttribute('data-id');
                            editNote(id);
                        });
                    });
                    
                    document.querySelectorAll('.delete-btn').forEach(btn => {
                        btn.addEventListener('click', function(e) {
                            e.stopPropagation();
                            const id = this.getAttribute('data-id');
                            deleteNote(id);
                        });
                    });
                    
                    // Add click event to row to show details
                    document.querySelectorAll('.note-item').forEach(row => {
                        row.addEventListener('click', function() {
                            const id = this.querySelector('.edit-btn').getAttribute('data-id');
                            editNote(id);
                        });
                    });
                }
                
                // Render pagination
                renderPagination(filteredNotes.length, itemsPerPage, currentPage);
            }
            
            function renderPagination(totalItems, perPage, currentPage) {
                const totalPages = Math.ceil(totalItems / perPage);
                paginationDiv.innerHTML = '';
                
                if (totalPages <= 1) return;
                
                // Previous button
                const prevBtn = document.createElement('button');
                prevBtn.innerHTML = '<i class="fas fa-chevron-left"></i>';
                prevBtn.className = `px-3 py-1 border rounded ${currentPage === 1 ? 'bg-gray-100 text-gray-400 cursor-not-allowed' : 'hover:bg-gray-100'}`;
                prevBtn.disabled = currentPage === 1;
                prevBtn.addEventListener('click', () => {
                    if (currentPage > 1) {
                        currentPage--;
                        renderNotes();
                    }
                });
                paginationDiv.appendChild(prevBtn);
                
                // Page numbers
                for (let i = 1; i <= totalPages; i++) {
                    const pageBtn = document.createElement('button');
                    pageBtn.textContent = i;
                    pageBtn.className = `px-3 py-1 border rounded ${currentPage === i ? 'bg-blue-500 text-white' : 'hover:bg-gray-100'}`;
                    pageBtn.addEventListener('click', () => {
                        currentPage = i;
                        renderNotes();
                    });
                    paginationDiv.appendChild(pageBtn);
                }
                
                // Next button
                const nextBtn = document.createElement('button');
                nextBtn.innerHTML = '<i class="fas fa-chevron-right"></i>';
                nextBtn.className = `px-3 py-1 border rounded ${currentPage === totalPages ? 'bg-gray-100 text-gray-400 cursor-not-allowed' : 'hover:bg-gray-100'}`;
                nextBtn.disabled = currentPage === totalPages;
                nextBtn.addEventListener('click', () => {
                    if (currentPage < totalPages) {
                        currentPage++;
                        renderNotes();
                    }
                });
                paginationDiv.appendChild(nextBtn);
            }
            
            function editNote(id) {
                const note = notes.find(note => note.id === id);
                if (note) {
                    document.getElementById('editId').value = note.id;
                    document.getElementById('editNoteNumber').value = note.noteNumber;
                    document.getElementById('editClient').value = note.client;
                    document.getElementById('editDate').value = note.date;
                    document.getElementById('editValue').value = note.value;
                    document.getElementById('editMixType').value = note.mixType;
                    document.getElementById('editQuantity').value = note.quantity;
                    document.getElementById('editStatus').value = note.status;
                    document.getElementById('editNotes').value = note.notes || '';
                    
                    editModal.classList.remove('hidden');
                }
            }
            
            function deleteNote(id) {
                const confirmation = confirm('Tem certeza que deseja excluir esta nota?');
                if (confirmation) {
                    notes = notes.filter(note => note.id !== id);
                    saveNotes();
                    renderNotes();
                    
                    // Show success message
                    showAlert('Nota excluída com sucesso!', 'success');
                }
            }
            
            function formatDate(dateString) {
                const options = { day: '2-digit', month: '2-digit', year: 'numeric' };
                return new Date(dateString).toLocaleDateString('pt-BR', options);
            }
            
            function showAlert(message, type) {
                const alert = document.createElement('div');
                alert.className = `fixed top-4 right-4 p-4 rounded-md shadow-lg z-50 animate-fade-in-out ${type === 'success' ? 'bg-green-500 text-white' : 'bg-red-500 text-white'}`;
                alert.innerHTML = `
                    <div class="flex items-center">
                        <i class="fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'} mr-2"></i>
                        ${message}
                    </div>
                `;
                
                document.body.appendChild(alert);
                
                // Remove after 3 seconds
                setTimeout(() => {
                    alert.classList.add('animate-fade-out');
                    setTimeout(() => {
                        document.body.removeChild(alert);
                    }, 500);
                }, 3000);
            }
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=luis35/hhhh" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>