File size: 29,225 Bytes
ce0962e
 
 
 
 
 
 
 
 
 
eb40187
ce0962e
 
eb40187
 
ce0962e
 
 
 
eb40187
ce0962e
 
 
 
 
 
eb40187
 
ce0962e
 
eb40187
 
 
 
 
 
 
 
 
 
 
ce0962e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb40187
 
ce0962e
 
 
 
 
 
 
 
 
eb40187
ce0962e
 
 
 
eb40187
 
ce0962e
 
 
eb40187
ce0962e
 
 
 
 
 
 
 
eb40187
 
 
 
 
 
 
 
 
 
ce0962e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GarTime - Gestión Profesional de Tareas</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>
        .timer-active {
            animation: pulse 1.5s infinite ease-in-out;
        }
        @keyframes pulse {
            0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7); }
            50% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(59, 130, 246, 0); }
        }
        .task-completed {
            background-color: #f0fdf4;
            border-left: 4px solid #10b981;
            transition: all 0.3s ease;
        }
        .dark .task-completed {
            background-color: #052e16;
            border-left: 4px solid #10b981;
        }
        .dark-mode {
            background-color: #1a1a2e;
            color: #e6f1ff;
        }
        .dark-mode-secondary {
            background-color: #16213e;
        }
        .smooth-transition {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .slide-down {
            animation: slideDown 0.3s ease-out forwards;
        }
        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen transition-colors duration-300">
    <div class="container mx-auto px-4 py-8 max-w-6xl">
        <!-- Header -->
        <header class="flex flex-col md:flex-row justify-between items-center mb-8 gap-4">
            <div class="flex items-center">
                <div class="bg-blue-600 text-white p-3 rounded-lg mr-4">
                    <i class="fas fa-clock text-2xl"></i>
                </div>
                <div>
                    <h1 class="text-3xl font-bold text-gray-800 dark:text-white">GarTime</h1>
                    <p class="text-gray-600 dark:text-gray-300">Gestión profesional de tareas y tiempo</p>
                </div>
            </div>
            
            <div class="flex items-center space-x-4">
                <div class="flex items-center">
                    <span class="mr-2 text-gray-700 dark:text-gray-300">Modo oscuro</span>
                    <button id="darkModeToggle" class="relative inline-flex h-6 w-11 items-center rounded-full bg-gray-200 dark:bg-gray-600">
                        <span class="sr-only">Toggle dark mode</span>
                        <span id="darkModeToggleCircle" class="inline-block h-4 w-4 transform rounded-full bg-white dark:bg-gray-300 translate-x-1 dark:translate-x-6 transition-transform"></span>
                    </button>
                </div>
                
                <div class="hidden md:block">
                    <div class="flex items-center bg-blue-50 dark:bg-blue-900/30 p-2 rounded-lg">
                        <i class="fas fa-dollar-sign text-blue-600 dark:text-blue-300 mr-2"></i>
                        <span class="font-medium text-blue-600 dark:text-blue-300">Tarifa:</span>
                        <input id="hourlyRate" type="number" min="0" step="0.01" value="50.00" class="ml-2 w-20 bg-transparent border-b border-blue-300 dark:border-blue-600 focus:outline-none text-blue-800 dark:text-blue-100">
                        <span class="ml-1 text-blue-600 dark:text-blue-300">/h</span>
                    </div>
                </div>
            </div>
        </header>

        <!-- Stats Cards -->
        <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg smooth-transition hover:shadow-xl p-6 flex items-center">
                <div class="bg-green-100 dark:bg-green-900/30 p-3 rounded-full mr-4">
                    <i class="fas fa-check-circle text-green-600 dark:text-green-400 text-xl"></i>
                </div>
                <div>
                    <p class="text-gray-500 dark:text-gray-400 text-sm">Tareas completadas</p>
                    <h3 id="completedTasksCount" class="text-2xl font-bold text-gray-800 dark:text-white">0</h3>
                </div>
            </div>
            
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg smooth-transition hover:shadow-xl p-6 flex items-center">
                <div class="bg-blue-100 dark:bg-blue-900/30 p-3 rounded-full mr-4">
                    <i class="fas fa-clock text-blue-600 dark:text-blue-400 text-xl"></i>
                </div>
                <div>
                    <p class="text-gray-500 dark:text-gray-400 text-sm">Tiempo hoy</p>
                    <h3 id="todayTime" class="text-2xl font-bold text-gray-800 dark:text-white">00:00:00</h3>
                </div>
            </div>
            
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg smooth-transition hover:shadow-xl p-6 flex items-center">
                <div class="bg-purple-100 dark:bg-purple-900/30 p-3 rounded-full mr-4">
                    <i class="fas fa-money-bill-wave text-purple-600 dark:text-purple-400 text-xl"></i>
                </div>
                <div>
                    <p class="text-gray-500 dark:text-gray-400 text-sm">Valor total</p>
                    <h3 id="totalValue" class="text-2xl font-bold text-gray-800 dark:text-white">$0.00</h3>
                </div>
            </div>
            
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg smooth-transition hover:shadow-xl p-6 flex items-center">
                <div class="bg-amber-100 dark:bg-amber-900/30 p-3 rounded-full mr-4">
                    <i class="fas fa-stopwatch text-amber-600 dark:text-amber-400 text-xl"></i>
                </div>
                <div>
                    <p class="text-gray-500 dark:text-gray-400 text-sm">Tiempo total</p>
                    <h3 id="totalTime" class="text-2xl font-bold text-gray-800 dark:text-white">00:00:00</h3>
                </div>
            </div>
        </div>

        <!-- Main Content -->
        <div class="flex flex-col lg:flex-row gap-8">
            <!-- Task Form -->
            <div class="lg:w-1/3">
                <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6 sticky top-4">
                    <h2 class="text-xl font-bold text-gray-800 dark:text-white mb-4">Nueva Tarea</h2>
                    
                    <div class="mb-4">
                        <label for="taskName" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Nombre de la tarea</label>
                        <input type="text" id="taskName" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white" placeholder="Ej: Diseño de logo">
                    </div>
                    
                    <div class="mb-4">
                        <label for="taskDescription" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Descripción</label>
                        <textarea id="taskDescription" rows="3" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white" placeholder="Detalles de la tarea..."></textarea>
                    </div>
                    
                    <div class="mb-6">
                        <label for="taskProject" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Proyecto</label>
                        <input type="text" id="taskProject" class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white" placeholder="Ej: Sitio web cliente X">
                    </div>
                    
                    <div class="md:hidden mb-6">
                        <label for="mobileHourlyRate" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Tarifa por hora</label>
                        <div class="relative">
                            <div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
                                <span class="text-gray-500 dark:text-gray-400">$</span>
                            </div>
                            <input id="mobileHourlyRate" type="number" min="0" step="0.01" value="50.00" class="pl-8 w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white">
                        </div>
                    </div>
                    
                    <button id="addTaskBtn" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition duration-300 flex items-center justify-center">
                        <i class="fas fa-plus mr-2"></i> Agregar Tarea
                    </button>
                </div>
            </div>
            
            <!-- Task List -->
            <div class="lg:w-2/3">
                <div class="bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden">
                    <div class="border-b border-gray-200 dark:border-gray-700 px-6 py-4 flex justify-between items-center">
                        <h2 class="text-xl font-bold text-gray-800 dark:text-white">Mis Tareas</h2>
                        <div class="relative">
                            <select id="taskFilter" class="appearance-none bg-gray-100 dark:bg-gray-700 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-white py-2 px-4 pr-8 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                                <option value="all">Todas</option>
                                <option value="active">Activas</option>
                                <option value="completed">Completadas</option>
                            </select>
                            <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700 dark:text-gray-300">
                                <i class="fas fa-chevron-down"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div id="taskList" class="divide-y divide-gray-200 dark:divide-gray-700">
                        <!-- Tasks will be added here dynamically -->
                        <div class="p-6 text-center text-gray-500 dark:text-gray-400">
                            <i class="fas fa-tasks text-4xl mb-2"></i>
                            <p>No hay tareas registradas</p>
                            <p class="text-sm">Agrega tu primera tarea usando el formulario</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Task Template (hidden) -->
    <template id="taskTemplate">
        <div class="task-item p-6 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors duration-200">
            <div class="flex justify-between items-start mb-2">
                <div>
                    <h3 class="task-name font-medium text-lg text-gray-800 dark:text-white"></h3>
                    <p class="task-project text-sm text-blue-600 dark:text-blue-400 mt-1"></p>
                </div>
                <div class="flex space-x-2">
                    <button class="timer-toggle-btn bg-blue-100 dark:bg-blue-900/30 hover:bg-blue-200 dark:hover:bg-blue-800 text-blue-800 dark:text-blue-200 px-3 py-1 rounded-md text-sm flex items-center transition-colors duration-200">
                        <i class="fas fa-play mr-1"></i> <span class="timer-label">Iniciar</span>
                    </button>
                    <button class="complete-btn bg-green-100 dark:bg-green-900/30 hover:bg-green-200 dark:hover:bg-green-800 text-green-800 dark:text-green-200 px-3 py-1 rounded-md text-sm flex items-center transition-colors duration-200">
                        <i class="fas fa-check mr-1"></i> Completar
                    </button>
                    <button class="delete-btn bg-red-100 dark:bg-red-900/30 hover:bg-red-200 dark:hover:bg-red-800 text-red-800 dark:text-red-200 px-3 py-1 rounded-md text-sm flex items-center transition-colors duration-200">
                        <i class="fas fa-trash mr-1"></i>
                    </button>
                </div>
            </div>
            
            <p class="task-description text-gray-600 dark:text-gray-300 mb-3"></p>
            
            <div class="flex flex-wrap justify-between items-center pt-3 border-t border-gray-200 dark:border-gray-700">
                <div class="flex items-center text-sm text-gray-500 dark:text-gray-400">
                    <i class="fas fa-clock mr-1"></i>
                    <span class="task-time">00:00:00</span>
                </div>
                <div class="flex items-center text-sm font-medium">
                    <span class="text-gray-500 dark:text-gray-400 mr-1">Valor:</span>
                    <span class="task-value text-blue-600 dark:text-blue-400">$0.00</span>
                </div>
                <div class="text-xs text-gray-400 task-date"></div>
            </div>
        </div>
    </template>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // DOM Elements
            const darkModeToggle = document.getElementById('darkModeToggle');
            const darkModeToggleCircle = document.getElementById('darkModeToggleCircle');
            const hourlyRateInput = document.getElementById('hourlyRate');
            const mobileHourlyRateInput = document.getElementById('mobileHourlyRate');
            const taskNameInput = document.getElementById('taskName');
            const taskDescriptionInput = document.getElementById('taskDescription');
            const taskProjectInput = document.getElementById('taskProject');
            const addTaskBtn = document.getElementById('addTaskBtn');
            const taskList = document.getElementById('taskList');
            const taskFilter = document.getElementById('taskFilter');
            const completedTasksCount = document.getElementById('completedTasksCount');
            const totalTimeElement = document.getElementById('totalTime');
            const totalValueElement = document.getElementById('totalValue');
            const taskTemplate = document.getElementById('taskTemplate');
            
            // State
            let tasks = JSON.parse(localStorage.getItem('garTimeTasks')) || [];
            let activeTimer = null;
            let isDarkMode = localStorage.getItem('darkMode') === 'true';
            
            // Initialize
            updateUI();
            updateStats();
            applyDarkMode();
            
            // Event Listeners
            darkModeToggle.addEventListener('click', toggleDarkMode);
            addTaskBtn.addEventListener('click', addTask);
            taskFilter.addEventListener('change', filterTasks);
            hourlyRateInput.addEventListener('change', updateHourlyRate);
            mobileHourlyRateInput.addEventListener('change', updateHourlyRate);
            
            // Functions
            function toggleDarkMode() {
                isDarkMode = !isDarkMode;
                localStorage.setItem('darkMode', isDarkMode);
                applyDarkMode();
            }
            
            function applyDarkMode() {
                if (isDarkMode) {
                    document.body.classList.add('dark-mode');
                    document.body.classList.add('dark');
                    darkModeToggleCircle.classList.remove('translate-x-1');
                    darkModeToggleCircle.classList.add('translate-x-6');
                } else {
                    document.body.classList.remove('dark-mode');
                    document.body.classList.remove('dark');
                    darkModeToggleCircle.classList.add('translate-x-1');
                    darkModeToggleCircle.classList.remove('translate-x-6');
                }
            }
            
            function updateHourlyRate() {
                const rate = parseFloat(hourlyRateInput.value) || 0;
                hourlyRateInput.value = rate.toFixed(2);
                mobileHourlyRateInput.value = rate.toFixed(2);
                updateTasksValues();
                updateStats();
                saveTasks();
            }
            
            function addTask() {
                const name = taskNameInput.value.trim();
                const description = taskDescriptionInput.value.trim();
                const project = taskProjectInput.value.trim();
                
                if (!name) {
                    alert('Por favor ingresa un nombre para la tarea');
                    return;
                }
                
                const newTask = {
                    id: Date.now(),
                    name,
                    description,
                    project,
                    isCompleted: false,
                    timeSpent: 0, // in seconds
                    timerInterval: null,
                    createdAt: new Date().toISOString(),
                    lastActiveAt: null
                };
                
                tasks.push(newTask);
                saveTasks();
                updateUI();
                
                // Clear form
                taskNameInput.value = '';
                taskDescriptionInput.value = '';
                taskProjectInput.value = '';
                taskNameInput.focus();
            }
            
            function updateUI() {
                taskList.innerHTML = '';
                
                if (tasks.length === 0) {
                    taskList.innerHTML = `
                        <div class="p-6 text-center text-gray-500 dark:text-gray-400">
                            <i class="fas fa-tasks text-4xl mb-2"></i>
                            <p>No hay tareas registradas</p>
                            <p class="text-sm">Agrega tu primera tarea usando el formulario</p>
                        </div>
                    `;
                    return;
                }
                
                const filteredTasks = filterTasksByStatus(taskFilter.value);
                
                filteredTasks.forEach(task => {
                    const taskElement = createTaskElement(task);
                    taskList.appendChild(taskElement);
                });
            }
            
            function filterTasksByStatus(status) {
                if (status === 'all') return [...tasks].sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
                if (status === 'active') return tasks.filter(task => !task.isCompleted);
                if (status === 'completed') return tasks.filter(task => task.isCompleted);
                return tasks;
            }
            
            function filterTasks() {
                updateUI();
            }
            
            function createTaskElement(task) {
                const taskElement = taskTemplate.content.cloneNode(true);
                const taskContainer = taskElement.querySelector('.task-item');
                
                if (task.isCompleted) {
                    taskContainer.classList.add('task-completed');
                }
                
                // Set task data
                taskElement.querySelector('.task-name').textContent = task.name;
                taskElement.querySelector('.task-description').textContent = task.description || 'Sin descripción';
                taskElement.querySelector('.task-project').textContent = task.project || 'Sin proyecto';
                taskElement.querySelector('.task-time').textContent = formatTime(task.timeSpent);
                taskElement.querySelector('.task-value').textContent = calculateTaskValue(task.timeSpent);
                taskElement.querySelector('.task-date').textContent = formatDate(task.createdAt);
                
                // Set timer button state
                const timerBtn = taskElement.querySelector('.timer-toggle-btn');
                const timerLabel = taskElement.querySelector('.timer-label');
                
                if (task.timerInterval) {
                    timerBtn.classList.add('timer-active');
                    timerBtn.classList.remove('bg-blue-100', 'dark:bg-blue-900/30');
                    timerBtn.classList.add('bg-blue-600', 'text-white');
                    timerLabel.textContent = 'En progreso';
                    timerLabel.innerHTML = `<i class="fas fa-spinner fa-spin mr-1"></i> En progreso`;
                } else {
                    timerBtn.classList.remove('timer-active');
                    timerLabel.textContent = 'Iniciar';
                }
                
                // Button event listeners
                timerBtn.addEventListener('click', () => toggleTimer(task.id));
                taskElement.querySelector('.complete-btn').addEventListener('click', () => toggleTaskCompletion(task.id));
                taskElement.querySelector('.delete-btn').addEventListener('click', () => deleteTask(task.id));
                
                return taskElement;
            }
            
            function toggleTimer(taskId) {
                // Stop any active timer first
                if (activeTimer) {
                    stopTimer(activeTimer);
                }
                
                const task = tasks.find(t => t.id === taskId);
                
                if (task.timerInterval) {
                    stopTimer(taskId);
                } else {
                    startTimer(taskId);
                    activeTimer = taskId;
                }
                
                updateUI();
                saveTasks();
            }
            
            function startTimer(taskId) {
                const task = tasks.find(t => t.id === taskId);
                
                if (!task) return;
                
                task.lastActiveAt = new Date().toISOString();
                
                task.timerInterval = setInterval(() => {
                    task.timeSpent++;
                    updateStats();
                    
                    // Update the UI for this specific task if it's visible
                    const taskElement = document.querySelector(`[data-task-id="${taskId}"]`);
                    if (taskElement) {
                        taskElement.querySelector('.task-time').textContent = formatTime(task.timeSpent);
                        taskElement.querySelector('.task-value').textContent = calculateTaskValue(task.timeSpent);
                    }
                }, 1000);
                
                saveTasks();
            }
            
            function stopTimer(taskId) {
                const task = tasks.find(t => t.id === taskId);
                
                if (!task || !task.timerInterval) return;
                
                clearInterval(task.timerInterval);
                task.timerInterval = null;
                
                if (activeTimer === taskId) {
                    activeTimer = null;
                }
                
                saveTasks();
            }
            
            function toggleTaskCompletion(taskId) {
                const task = tasks.find(t => t.id === taskId);
                
                if (!task) return;
                
                // Stop timer if running
                if (task.timerInterval) {
                    stopTimer(taskId);
                    if (activeTimer === taskId) {
                        activeTimer = null;
                    }
                }
                
                task.isCompleted = !task.isCompleted;
                updateUI();
                updateStats();
                saveTasks();
            }
            
            function deleteTask(taskId) {
                if (!confirm('¿Estás seguro de que quieres eliminar esta tarea?')) return;
                
                // Stop timer if running
                const task = tasks.find(t => t.id === taskId);
                if (task && task.timerInterval) {
                    stopTimer(taskId);
                    if (activeTimer === taskId) {
                        activeTimer = null;
                    }
                }
                
                tasks = tasks.filter(t => t.id !== taskId);
                updateUI();
                updateStats();
                saveTasks();
            }
            
            function updateTasksValues() {
                tasks.forEach(task => {
                    // Update is handled in the timer interval for active tasks
                    // For completed tasks, we don't need to do anything as value is calculated on demand
                });
                
                updateUI();
            }
            
            function updateStats() {
                const completedTasks = tasks.filter(t => t.isCompleted).length;
                const totalTime = tasks.reduce((sum, task) => sum + task.timeSpent, 0);
                const totalValue = tasks.reduce((sum, task) => {
                    const hourlyRate = parseFloat(hourlyRateInput.value) || 0;
                    return sum + (task.timeSpent / 3600 * hourlyRate);
                }, 0);
                
                completedTasksCount.textContent = completedTasks;
                totalTimeElement.textContent = formatTime(totalTime);
                totalValueElement.textContent = `$${totalValue.toFixed(2)}`;
            }
            
            function formatTime(seconds) {
                const hrs = Math.floor(seconds / 3600);
                const mins = Math.floor((seconds % 3600) / 60);
                const secs = seconds % 60;
                
                return `${String(hrs).padStart(2, '0')}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
            }
            
            function calculateTaskValue(seconds) {
                const hourlyRate = parseFloat(hourlyRateInput.value) || 0;
                const value = (seconds / 3600) * hourlyRate;
                return `$${value.toFixed(2)}`;
            }
            
            function formatDate(isoString) {
                const date = new Date(isoString);
                return date.toLocaleDateString('es-ES', {
                    day: '2-digit',
                    month: '2-digit',
                    year: 'numeric',
                    hour: '2-digit',
                    minute: '2-digit'
                });
            }
            
            function saveTasks() {
                localStorage.setItem('garTimeTasks', JSON.stringify(tasks));
            }
            
            // Initialize tasks with data attributes for easier selection
            document.addEventListener('click', function(e) {
                if (e.target.closest('.task-item')) {
                    const taskElement = e.target.closest('.task-item');
                    const taskId = parseInt(taskElement.dataset.taskId);
                    // You can add more specific event handling here if needed
                }
            });
            
            // Restore any active timers on page load
            tasks.forEach(task => {
                if (task.timerInterval) {
                    // Clear any existing interval (shouldn't exist on page load)
                    if (task.timerInterval) {
                        clearInterval(task.timerInterval);
                    }
                    
                    // Calculate time passed since last active
                    if (task.lastActiveAt) {
                        const lastActive = new Date(task.lastActiveAt);
                        const now = new Date();
                        const secondsPassed = Math.floor((now - lastActive) / 1000);
                        task.timeSpent += secondsPassed;
                    }
                    
                    // Restart the timer
                    startTimer(task.id);
                }
            });
        });
    </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=fgarola/gartime" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>