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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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988

# Time Tracker Pro - Offline Installation

## Prerequisites
- Node.js (v16 or later)
- npm (comes with Node.js)

## Installation Steps

1. **Download the application files** including:
   - `index.html` (main application file)
   - `package.json` (configuration file)
   - `main.js` (Electron main process file)
   - `/build` folder with application icon (optional)

2. **Install dependencies**:
   ```bash
   npm install
   ```

3. **Run the application in development mode**:
   ```bash
   npm start
   ```

4. **Create installer packages**:

   For Windows:
   ```bash
   npm run dist
   ```

   This will create:
   - Setup executable in `dist` folder
   - Portable version in `dist/win-unpacked`

## Building for Other Platforms

To build for other platforms, add the appropriate build configuration to `package.json` and run:
```bash
npm run dist
```

## Offline Usage
Once installed, the application works completely offline:
- All data is stored in local storage
- No internet connection required
- Reports can be printed or saved as PDF


const { app, BrowserWindow } = require('electron')
const path = require('path')

function createWindow () {
  const win = new BrowserWindow({
    width: 1200,
    height: 800,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  })

  win.loadFile('index.html')
}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})


{
  "name": "time-tracker-pro",
  "version": "1.0.0",
  "description": "Offline Time Tracking Application",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "postinstall": "electron-builder install-app-deps"
  },
  "build": {
    "appId": "com.example.timetrackerpro",
    "productName": "Time Tracker Pro",
    "win": {
      "target": "nsis",
      "icon": "build/icon.ico"
    },
    "nsis": {
      "oneClick": false,
      "allowToChangeInstallationDirectory": true
    }
  },
  "devDependencies": {
    "electron": "^25.0.0",
    "electron-builder": "^24.0.0"
  }
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Time Tracker Pro</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">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3b82f6',
                        secondary: '#10b981',
                        dark: '#1e293b',
                        light: '#f8fafc'
                    }
                }
            }
        }
    </script>
    <style>
        /* Custom scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        ::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 4px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
        
        /* Animation for buttons */
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        .pulse:hover {
            animation: pulse 1.5s infinite;
        }
        
        /* Print styles */
        @media print {
            .no-print {
                display: none !important;
            }
            .print-full {
                width: 100% !important;
            }
        }
    </style>
</head>
<body class="bg-gray-100 font-sans">
    <div class="min-h-screen flex flex-col">
        <!-- Header -->
        <header class="bg-dark text-white shadow-lg">
            <div class="container mx-auto px-4 py-4 flex justify-between items-center">
                <div class="flex items-center space-x-2">
                    <i class="fas fa-clock text-2xl text-primary"></i>
                    <h1 class="text-2xl font-bold">Time Tracker Pro</h1>
                </div>
                <div class="flex items-center space-x-4">
                    <div id="current-time" class="text-sm bg-primary px-3 py-1 rounded-full"></div>
                    <button id="theme-toggle" class="p-2 rounded-full hover:bg-gray-700">
                        <i class="fas fa-moon"></i>
                    </button>
                </div>
            </div>
        </header>

        <!-- Main Content -->
        <main class="flex-grow container mx-auto px-4 py-6">
            <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
                <!-- Time Entry Section -->
                <div class="lg:col-span-1">
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <h2 class="text-xl font-semibold mb-4 text-dark flex items-center">
                            <i class="fas fa-stopwatch mr-2 text-primary"></i> Time Entry
                        </h2>
                        
                        <div class="space-y-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Employee ID</label>
                                <input type="text" id="employee-id" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
                            </div>
                            
                            <div class="grid grid-cols-2 gap-4">
                                <button id="clock-in" class="bg-green-600 hover:bg-green-700 text-white py-3 px-4 rounded-md font-medium flex items-center justify-center pulse">
                                    <i class="fas fa-sign-in-alt mr-2"></i> Clock In
                                </button>
                                <button id="lunch-out" class="bg-yellow-600 hover:bg-yellow-700 text-white py-3 px-4 rounded-md font-medium flex items-center justify-center pulse">
                                    <i class="fas fa-utensils mr-2"></i> Lunch Out
                                </button>
                                <button id="lunch-in" class="bg-blue-600 hover:bg-blue-700 text-white py-3 px-4 rounded-md font-medium flex items-center justify-center pulse">
                                    <i class="fas fa-utensils mr-2"></i> Lunch In
                                </button>
                                <button id="clock-out" class="bg-red-600 hover:bg-red-700 text-white py-3 px-4 rounded-md font-medium flex items-center justify-center pulse">
                                    <i class="fas fa-sign-out-alt mr-2"></i> Clock Out
                                </button>
                            </div>
                            
                            <div class="pt-4 border-t border-gray-200">
                                <h3 class="text-lg font-medium text-dark mb-2">Today's Summary</h3>
                                <div class="grid grid-cols-2 gap-2">
                                    <div class="bg-gray-50 p-3 rounded">
                                        <p class="text-xs text-gray-500">Clock In</p>
                                        <p id="today-clock-in" class="font-semibold">--:--</p>
                                    </div>
                                    <div class="bg-gray-50 p-3 rounded">
                                        <p class="text-xs text-gray-500">Lunch Out</p>
                                        <p id="today-lunch-out" class="font-semibold">--:--</p>
                                    </div>
                                    <div class="bg-gray-50 p-3 rounded">
                                        <p class="text-xs text-gray-500">Lunch In</p>
                                        <p id="today-lunch-in" class="font-semibold">--:--</p>
                                    </div>
                                    <div class="bg-gray-50 p-3 rounded">
                                        <p class="text-xs text-gray-500">Clock Out</p>
                                        <p id="today-clock-out" class="font-semibold">--:--</p>
                                    </div>
                                </div>
                                <div class="mt-2 bg-gray-50 p-3 rounded">
                                    <p class="text-xs text-gray-500">Total Hours</p>
                                    <p id="today-total-hours" class="font-semibold text-lg">0.00 hrs</p>
                                </div>
                                <div class="mt-2 bg-gray-50 p-3 rounded">
                                    <p class="text-xs text-gray-500">Overtime</p>
                                    <p id="today-overtime" class="font-semibold text-lg">0.00 hrs</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Records and Reports Section -->
                <div class="lg:col-span-2 space-y-6">
                    <!-- Records Table -->
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex justify-between items-center mb-4">
                            <h2 class="text-xl font-semibold text-dark flex items-center">
                                <i class="fas fa-list-alt mr-2 text-primary"></i> Time Records
                            </h2>
                            <div class="flex space-x-2">
                                <select id="records-filter" class="text-sm border border-gray-300 rounded px-3 py-1 focus:outline-none focus:ring-1 focus:ring-primary">
                                    <option value="today">Today</option>
                                    <option value="week">This Week</option>
                                    <option value="month">This Month</option>
                                    <option value="all">All Records</option>
                                </select>
                                <button id="refresh-records" class="p-1 text-gray-500 hover:text-primary">
                                    <i class="fas fa-sync-alt"></i>
                                </button>
                            </div>
                        </div>
                        
                        <div class="overflow-x-auto">
                            <table 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">Date</th>
                                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock In</th>
                                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch Out</th>
                                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch In</th>
                                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock Out</th>
                                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total</th>
                                        <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Overtime</th>
                                    </tr>
                                </thead>
                                <tbody id="records-body" class="bg-white divide-y divide-gray-200">
                                    <tr>
                                        <td colspan="7" class="px-4 py-6 text-center text-gray-500">No records found</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                    <!-- Reports Section -->
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex justify-between items-center mb-4">
                            <h2 class="text-xl font-semibold text-dark flex items-center">
                                <i class="fas fa-chart-bar mr-2 text-primary"></i> Reports
                            </h2>
                            <div class="flex space-x-2">
                                <select id="report-period" class="text-sm border border-gray-300 rounded px-3 py-1 focus:outline-none focus:ring-1 focus:ring-primary">
                                    <option value="daily">Daily</option>
                                    <option value="weekly">Weekly</option>
                                    <option value="monthly">Monthly</option>
                                </select>
                                <button id="generate-report" class="bg-primary hover:bg-blue-700 text-white px-4 py-1 rounded flex items-center">
                                    <i class="fas fa-file-pdf mr-1"></i> Generate
                                </button>
                                <button id="print-report" class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-1 rounded flex items-center no-print">
                                    <i class="fas fa-print mr-1"></i> Print
                                </button>
                            </div>
                        </div>
                        
                        <div id="report-content" class="mt-4">
                            <div class="text-center py-10 text-gray-400">
                                <i class="fas fa-file-alt text-4xl mb-2"></i>
                                <p>Select report type and click Generate</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>

        <!-- Footer -->
        <footer class="bg-dark text-white py-4">
            <div class="container mx-auto px-4 text-center text-sm">
                <p>© 2023 Time Tracker Pro. All rights reserved.</p>
            </div>
        </footer>
    </div>

    <script>
        // Sample data storage
        let timeRecords;
        
        // Initialize storage - works differently in Electron
        function initStorage() {
            if (typeof localStorage !== 'undefined') {
                timeRecords = JSON.parse(localStorage.getItem('timeRecords')) || [];
            } else {
                // Fallback for Electron
                const fs = require('fs');
                const path = require('path');
                const dataPath = path.join(app.getPath('userData'), 'timeRecords.json');
                
                try {
                    timeRecords = JSON.parse(fs.readFileSync(dataPath)) || [];
                } catch (e) {
                    timeRecords = [];
                }
                
                // Override localStorage methods
                window.localStorage = {
                    getItem: () => null,
                    setItem: (key, value) => {
                        if (key === 'timeRecords') {
                            fs.writeFileSync(dataPath, JSON.stringify(timeRecords));
                        }
                    }
                };
            }
        }
        
        initStorage();
        let currentEmployeeId = '';
        
        // DOM Elements
        const employeeIdInput = document.getElementById('employee-id');
        const clockInBtn = document.getElementById('clock-in');
        const lunchOutBtn = document.getElementById('lunch-out');
        const lunchInBtn = document.getElementById('lunch-in');
        const clockOutBtn = document.getElementById('clock-out');
        const todayClockIn = document.getElementById('today-clock-in');
        const todayLunchOut = document.getElementById('today-lunch-out');
        const todayLunchIn = document.getElementById('today-lunch-in');
        const todayClockOut = document.getElementById('today-clock-out');
        const todayTotalHours = document.getElementById('today-total-hours');
        const todayOvertime = document.getElementById('today-overtime');
        const recordsFilter = document.getElementById('records-filter');
        const recordsBody = document.getElementById('records-body');
        const refreshRecordsBtn = document.getElementById('refresh-records');
        const reportPeriod = document.getElementById('report-period');
        const generateReportBtn = document.getElementById('generate-report');
        const printReportBtn = document.getElementById('print-report');
        const reportContent = document.getElementById('report-content');
        const currentTimeDisplay = document.getElementById('current-time');
        const themeToggle = document.getElementById('theme-toggle');
        
        // Initialize
        document.addEventListener('DOMContentLoaded', () => {
            updateCurrentTime();
            setInterval(updateCurrentTime, 1000);
            loadTodayRecords();
            loadAllRecords();
            
            // Check for dark mode preference
            if (localStorage.getItem('darkMode') === 'enabled') {
                document.documentElement.classList.add('dark');
                themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
            }
        });
        
        // Update current time
        function updateCurrentTime() {
            const now = new Date();
            currentTimeDisplay.textContent = now.toLocaleTimeString() + ' ' + now.toLocaleDateString();
        }
        
        // Theme toggle
        themeToggle.addEventListener('click', () => {
            document.documentElement.classList.toggle('dark');
            if (document.documentElement.classList.contains('dark')) {
                localStorage.setItem('darkMode', 'enabled');
                themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
            } else {
                localStorage.setItem('darkMode', 'disabled');
                themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
            }
        });
        
        // Time entry buttons
        clockInBtn.addEventListener('click', () => recordTime('clockIn'));
        lunchOutBtn.addEventListener('click', () => recordTime('lunchOut'));
        lunchInBtn.addEventListener('click', () => recordTime('lunchIn'));
        clockOutBtn.addEventListener('click', () => recordTime('clockOut'));
        
        // Record time function
        function recordTime(type) {
            currentEmployeeId = employeeIdInput.value.trim();
            
            if (!currentEmployeeId) {
                alert('Please enter your Employee ID');
                return;
            }
            
            const now = new Date();
            const today = now.toISOString().split('T')[0];
            
            // Find or create today's record
            let record = timeRecords.find(r => r.date === today && r.employeeId === currentEmployeeId);
            
            if (!record) {
                record = {
                    date: today,
                    employeeId: currentEmployeeId,
                    clockIn: '',
                    lunchOut: '',
                    lunchIn: '',
                    clockOut: '',
                    totalHours: 0,
                    overtime: 0
                };
                timeRecords.push(record);
            }
            
            // Update the record
            const timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
            
            switch (type) {
                case 'clockIn':
                    if (record.clockIn) {
                        alert('Clock-in already recorded for today');
                        return;
                    }
                    record.clockIn = timeString;
                    break;
                case 'lunchOut':
                    if (!record.clockIn) {
                        alert('Please clock in first');
                        return;
                    }
                    if (record.lunchOut) {
                        alert('Lunch-out already recorded for today');
                        return;
                    }
                    record.lunchOut = timeString;
                    break;
                case 'lunchIn':
                    if (!record.lunchOut) {
                        alert('Please take lunch out first');
                        return;
                    }
                    if (record.lunchIn) {
                        alert('Lunch-in already recorded for today');
                        return;
                    }
                    record.lunchIn = timeString;
                    break;
                case 'clockOut':
                    if (!record.clockIn) {
                        alert('Please clock in first');
                        return;
                    }
                    if (record.clockOut) {
                        alert('Clock-out already recorded for today');
                        return;
                    }
                    record.clockOut = timeString;
                    
                    // Calculate total hours and overtime
                    const clockInTime = parseTimeString(record.clockIn);
                    const clockOutTime = parseTimeString(record.clockOut);
                    
                    let totalMinutes = (clockOutTime - clockInTime) / (1000 * 60);
                    
                    // Subtract lunch time if applicable
                    if (record.lunchOut && record.lunchIn) {
                        const lunchOutTime = parseTimeString(record.lunchOut);
                        const lunchInTime = parseTimeString(record.lunchIn);
                        const lunchMinutes = (lunchInTime - lunchOutTime) / (1000 * 60);
                        totalMinutes -= lunchMinutes;
                    }
                    
                    const totalHours = totalMinutes / 60;
                    record.totalHours = totalHours.toFixed(2);
                    
                    // Calculate overtime (assuming 8 hours standard workday)
                    const overtime = Math.max(0, totalHours - 8);
                    record.overtime = overtime.toFixed(2);
                    break;
            }
            
            // Save to localStorage
            localStorage.setItem('timeRecords', JSON.stringify(timeRecords));
            
            // Update UI
            loadTodayRecords();
            loadAllRecords();
        }
        
        // Helper function to parse time string into Date object
        function parseTimeString(timeStr) {
            const [time, period] = timeStr.split(' ');
            const [hours, minutes] = time.split(':').map(Number);
            
            let hours24 = hours;
            if (period === 'PM' && hours < 12) hours24 += 12;
            if (period === 'AM' && hours === 12) hours24 = 0;
            
            const date = new Date();
            date.setHours(hours24, minutes, 0, 0);
            return date;
        }
        
        // Load today's records
        function loadTodayRecords() {
            const today = new Date().toISOString().split('T')[0];
            const employeeId = employeeIdInput.value.trim();
            
            if (!employeeId) {
                resetTodayDisplay();
                return;
            }
            
            const record = timeRecords.find(r => r.date === today && r.employeeId === employeeId);
            
            if (record) {
                todayClockIn.textContent = record.clockIn || '--:--';
                todayLunchOut.textContent = record.lunchOut || '--:--';
                todayLunchIn.textContent = record.lunchIn || '--:--';
                todayClockOut.textContent = record.clockOut || '--:--';
                todayTotalHours.textContent = record.totalHours ? record.totalHours + ' hrs' : '0.00 hrs';
                todayOvertime.textContent = record.overtime ? record.overtime + ' hrs' : '0.00 hrs';
            } else {
                resetTodayDisplay();
            }
        }
        
        // Reset today's display
        function resetTodayDisplay() {
            todayClockIn.textContent = '--:--';
            todayLunchOut.textContent = '--:--';
            todayLunchIn.textContent = '--:--';
            todayClockOut.textContent = '--:--';
            todayTotalHours.textContent = '0.00 hrs';
            todayOvertime.textContent = '0.00 hrs';
        }
        
        // Load all records based on filter
        function loadAllRecords() {
            const filter = recordsFilter.value;
            const employeeId = employeeIdInput.value.trim();
            
            if (!employeeId) {
                recordsBody.innerHTML = '<tr><td colspan="7" class="px-4 py-6 text-center text-gray-500">Please enter Employee ID</td></tr>';
                return;
            }
            
            let filteredRecords = timeRecords.filter(r => r.employeeId === employeeId);
            
            // Apply additional filters
            const now = new Date();
            const today = now.toISOString().split('T')[0];
            const weekStart = getWeekStartDate(now);
            const monthStart = new Date(now.getFullYear(), now.getMonth(), 1).toISOString().split('T')[0];
            
            if (filter === 'today') {
                filteredRecords = filteredRecords.filter(r => r.date === today);
            } else if (filter === 'week') {
                filteredRecords = filteredRecords.filter(r => r.date >= weekStart);
            } else if (filter === 'month') {
                filteredRecords = filteredRecords.filter(r => r.date >= monthStart);
            }
            
            // Sort by date (newest first)
            filteredRecords.sort((a, b) => new Date(b.date) - new Date(a.date));
            
            // Update table
            if (filteredRecords.length === 0) {
                recordsBody.innerHTML = '<tr><td colspan="7" class="px-4 py-6 text-center text-gray-500">No records found</td></tr>';
                return;
            }
            
            let html = '';
            filteredRecords.forEach(record => {
                html += `
                    <tr>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${formatDate(record.date)}</td>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.clockIn || '--:--'}</td>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.lunchOut || '--:--'}</td>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.lunchIn || '--:--'}</td>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.clockOut || '--:--'}</td>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${record.totalHours || '0.00'} hrs</td>
                        <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${record.overtime || '0.00'} hrs</td>
                    </tr>
                `;
            });
            
            recordsBody.innerHTML = html;
        }
        
        // Helper function to get week start date (Monday)
        function getWeekStartDate(date) {
            const day = date.getDay();
            const diff = date.getDate() - day + (day === 0 ? -6 : 1); // adjust when day is Sunday
            return new Date(date.setDate(diff)).toISOString().split('T')[0];
        }
        
        // Format date for display
        function formatDate(dateStr) {
            const options = { year: 'numeric', month: 'short', day: 'numeric', weekday: 'short' };
            return new Date(dateStr).toLocaleDateString(undefined, options);
        }
        
        // Refresh records when filter changes
        recordsFilter.addEventListener('change', loadAllRecords);
        refreshRecordsBtn.addEventListener('click', loadAllRecords);
        
        // Employee ID input change
        employeeIdInput.addEventListener('change', () => {
            loadTodayRecords();
            loadAllRecords();
        });
        
        // Generate report
        generateReportBtn.addEventListener('click', generateReport);
        printReportBtn.addEventListener('click', () => window.print());
        
        // Generate report function
        function generateReport() {
            const period = reportPeriod.value;
            const employeeId = employeeIdInput.value.trim();
            
            if (!employeeId) {
                reportContent.innerHTML = `
                    <div class="text-center py-10 text-red-500">
                        <i class="fas fa-exclamation-circle text-4xl mb-2"></i>
                        <p>Please enter Employee ID</p>
                    </div>
                `;
                return;
            }
            
            let filteredRecords = timeRecords.filter(r => r.employeeId === employeeId);
            
            if (filteredRecords.length === 0) {
                reportContent.innerHTML = `
                    <div class="text-center py-10 text-gray-500">
                        <i class="fas fa-file-alt text-4xl mb-2"></i>
                        <p>No records found for this employee</p>
                    </div>
                `;
                return;
            }
            
            // Sort by date (oldest first for reports)
            filteredRecords.sort((a, b) => new Date(a.date) - new Date(b.date));
            
            let reportTitle = '';
            let reportData = [];
            let summary = { totalHours: 0, overtime: 0, daysWorked: 0 };
            
            if (period === 'daily') {
                reportTitle = 'Daily Time Report';
                reportData = filteredRecords.map(record => ({
                    date: formatDate(record.date),
                    clockIn: record.clockIn || '--:--',
                    lunchOut: record.lunchOut || '--:--',
                    lunchIn: record.lunchIn || '--:--',
                    clockOut: record.clockOut || '--:--',
                    totalHours: record.totalHours || '0.00',
                    overtime: record.overtime || '0.00'
                }));
                
                // Calculate summary
                filteredRecords.forEach(record => {
                    if (record.totalHours) {
                        summary.totalHours += parseFloat(record.totalHours);
                        summary.overtime += parseFloat(record.overtime);
                        summary.daysWorked++;
                    }
                });
            } else if (period === 'weekly') {
                reportTitle = 'Weekly Time Report';
                
                // Group by week
                const weeklyData = {};
                filteredRecords.forEach(record => {
                    const date = new Date(record.date);
                    const weekStart = getWeekStartDate(date);
                    const weekEnd = new Date(new Date(weekStart).getTime() + 6 * 24 * 60 * 60 * 1000);
                    const weekLabel = `${formatDate(weekStart)} to ${formatDate(weekEnd.toISOString().split('T')[0])}`;
                    
                    if (!weeklyData[weekLabel]) {
                        weeklyData[weekLabel] = {
                            week: weekLabel,
                            days: [],
                            totalHours: 0,
                            overtime: 0
                        };
                    }
                    
                    weeklyData[weekLabel].days.push({
                        date: formatDate(record.date),
                        clockIn: record.clockIn || '--:--',
                        lunchOut: record.lunchOut || '--:--',
                        lunchIn: record.lunchIn || '--:--',
                        clockOut: record.clockOut || '--:--',
                        totalHours: record.totalHours || '0.00',
                        overtime: record.overtime || '0.00'
                    });
                    
                    if (record.totalHours) {
                        weeklyData[weekLabel].totalHours += parseFloat(record.totalHours);
                        weeklyData[weekLabel].overtime += parseFloat(record.overtime);
                    }
                });
                
                // Convert to array and calculate summary
                reportData = Object.values(weeklyData);
                reportData.forEach(week => {
                    summary.totalHours += week.totalHours;
                    summary.overtime += week.overtime;
                    summary.daysWorked += week.days.length;
                });
            } else if (period === 'monthly') {
                reportTitle = 'Monthly Time Report';
                
                // Group by month
                const monthlyData = {};
                filteredRecords.forEach(record => {
                    const date = new Date(record.date);
                    const monthLabel = date.toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
                    
                    if (!monthlyData[monthLabel]) {
                        monthlyData[monthLabel] = {
                            month: monthLabel,
                            days: [],
                            totalHours: 0,
                            overtime: 0
                        };
                    }
                    
                    monthlyData[monthLabel].days.push({
                        date: formatDate(record.date),
                        clockIn: record.clockIn || '--:--',
                        lunchOut: record.lunchOut || '--:--',
                        lunchIn: record.lunchIn || '--:--',
                        clockOut: record.clockOut || '--:--',
                        totalHours: record.totalHours || '0.00',
                        overtime: record.overtime || '0.00'
                    });
                    
                    if (record.totalHours) {
                        monthlyData[monthLabel].totalHours += parseFloat(record.totalHours);
                        monthlyData[monthLabel].overtime += parseFloat(record.overtime);
                    }
                });
                
                // Convert to array and calculate summary
                reportData = Object.values(monthlyData);
                reportData.forEach(month => {
                    summary.totalHours += month.totalHours;
                    summary.overtime += month.overtime;
                    summary.daysWorked += month.days.length;
                });
            }
            
            // Generate report HTML
            let reportHTML = `
                <div class="print-full">
                    <div class="flex justify-between items-center mb-6 border-b pb-4">
                        <div>
                            <h3 class="text-2xl font-bold text-dark">${reportTitle}</h3>
                            <p class="text-gray-600">Employee ID: ${employeeId}</p>
                            <p class="text-gray-600">Generated on: ${new Date().toLocaleDateString()}</p>
                        </div>
                        <div class="bg-primary text-white p-2 rounded">
                            <i class="fas fa-clock text-3xl"></i>
                        </div>
                    </div>
            `;
            
            if (period === 'daily') {
                reportHTML += `
                    <div class="overflow-x-auto">
                        <table 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">Date</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock In</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch Out</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch In</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock Out</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total Hours</th>
                                    <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Overtime</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                `;
                
                reportData.forEach(record => {
                    reportHTML += `
                        <tr>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.date}</td>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.clockIn}</td>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.lunchOut}</td>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.lunchIn}</td>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${record.clockOut}</td>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${record.totalHours} hrs</td>
                            <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${record.overtime} hrs</td>
                        </tr>
                    `;
                });
                
                reportHTML += `
                            </tbody>
                        </table>
                    </div>
                `;
            } else if (period === 'weekly') {
                reportData.forEach(week => {
                    reportHTML += `
                        <div class="mb-8">
                            <h4 class="text-lg font-semibold mb-2 bg-gray-100 p-2 rounded">${week.week}</h4>
                            <div class="overflow-x-auto mb-2">
                                <table 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">Date</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock In</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch Out</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch In</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock Out</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total Hours</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Overtime</th>
                                        </tr>
                                    </thead>
                                    <tbody class="bg-white divide-y divide-gray-200">
                    `;
                    
                    week.days.forEach(day => {
                        reportHTML += `
                            <tr>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.date}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.clockIn}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.lunchOut}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.lunchIn}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.clockOut}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${day.totalHours} hrs</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${day.overtime} hrs</td>
                            </tr>
                        `;
                    });
                    
                    reportHTML += `
                                    </tbody>
                                </table>
                            </div>
                            <div class="flex justify-end">
                                <div class="bg-gray-100 p-3 rounded">
                                    <p class="text-sm font-medium">Week Total: <span class="font-bold">${week.totalHours.toFixed(2)} hrs</span></p>
                                    <p class="text-sm font-medium">Week Overtime: <span class="font-bold">${week.overtime.toFixed(2)} hrs</span></p>
                                </div>
                            </div>
                        </div>
                    `;
                });
            } else if (period === 'monthly') {
                reportData.forEach(month => {
                    reportHTML += `
                        <div class="mb-8">
                            <h4 class="text-lg font-semibold mb-2 bg-gray-100 p-2 rounded">${month.month}</h4>
                            <div class="overflow-x-auto mb-2">
                                <table 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">Date</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock In</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch Out</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Lunch In</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clock Out</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total Hours</th>
                                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Overtime</th>
                                        </tr>
                                    </thead>
                                    <tbody class="bg-white divide-y divide-gray-200">
                    `;
                    
                    month.days.forEach(day => {
                        reportHTML += `
                            <tr>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.date}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.clockIn}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.lunchOut}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.lunchIn}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${day.clockOut}</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${day.totalHours} hrs</td>
                                <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900 font-medium">${day.overtime} hrs</td>
                            </tr>
                        `;
                    });
                    
                    reportHTML += `
                                    </tbody>
                                </table>
                            </div>
                            <div class="flex justify-end">
                                <div class="bg-gray-100 p-3 rounded">
                                    <p class="text-sm font-medium">Month Total: <span class="font-bold">${month.totalHours.toFixed(2)} hrs</span></p>
                                    <p class="text-sm font-medium">Month Overtime: <span class="font-bold">${month.overtime.toFixed(2)} hrs</span></p>
                                </div>
                            </div>
                        </div>
                    `;
                });
            }
            
            // Add summary section
            reportHTML += `
                <div class="mt-8 pt-4 border-t border-gray-200">
                    <h4 class="text-lg font-semibold mb-4">Summary</h4>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="bg-blue-50 p-4 rounded-lg">
                            <p class="text-sm text-blue-600">Days Worked</p>
                            <p class="text-2xl font-bold text-blue-800">${summary.daysWorked}</p>
                        </div>
                        <div class="bg-green-50 p-4 rounded-lg">
                            <p class="text-sm text-green-600">Total Hours</p>
                            <p class="text-2xl font-bold text-green-800">${summary.totalHours.toFixed(2)} hrs</p>
                        </div>
                        <div class="bg-purple-50 p-4 rounded-lg">
                            <p class="text-sm text-purple-600">Total Overtime</p>
                            <p class="text-2xl font-bold text-purple-800">${summary.overtime.toFixed(2)} hrs</p>
                        </div>
                    </div>
                </div>
            `;
            
            // Add footer
            reportHTML += `
                <div class="mt-8 pt-4 border-t border-gray-200 text-center text-xs text-gray-500">
                    <p>This report was generated by Time Tracker Pro on ${new Date().toLocaleString()}</p>
                </div>
            </div>
            `;
            
            reportContent.innerHTML = reportHTML;
        }
    </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=limalex/alexandre" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>