File size: 32,090 Bytes
e728afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ded1ec
 
e728afb
 
6ded1ec
 
e728afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ded1ec
 
e728afb
6ded1ec
 
 
 
 
 
 
 
 
 
 
 
 
 
e728afb
 
 
 
 
 
 
 
 
6ded1ec
e728afb
 
 
 
 
 
 
 
 
 
 
6ded1ec
e728afb
 
 
 
 
 
 
 
 
 
 
6ded1ec
e728afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ded1ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e728afb
6ded1ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e728afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ded1ec
e728afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ded1ec
 
 
 
 
 
 
 
 
 
 
 
e728afb
6ded1ec
 
 
 
 
 
 
e728afb
 
 
 
 
 
 
 
 
 
 
6ded1ec
e728afb
 
 
 
 
 
 
 
 
 
 
 
6ded1ec
e728afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TaskFlow - Task Management App</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: '#1F2937',
                    }
                }
            }
        }
    </script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
        
        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
            min-height: 100vh;
        }
        
        .task-card {
            transition: all 0.3s ease;
            transform-origin: top;
            animation: fadeIn 0.5s ease-out;
        }
        
        .task-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        
        .priority-high { border-left: 4px solid #EF4444; }
        .priority-medium { border-left: 4px solid #F59E0B; }
        .priority-low { border-left: 4px solid #10B981; }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .modal {
            animation: modalFade 0.3s ease-out;
        }
        
        @keyframes modalFade {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .completed-task {
            opacity: 0.5;
            background-color: #f8fafc;
        }
        
        .pending-task {
            border-left: 4px solid #3B82F6;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Header -->
    <header class="bg-white shadow-sm">
        <div class="container mx-auto px-4 py-6 flex flex-col md:flex-row justify-between items-center">
            <div class="flex items-center mb-4 md:mb-0">
                <div class="bg-primary p-3 rounded-lg mr-3">
                    <i class="fas fa-tasks text-white text-xl"></i>
                </div>
                <h1 class="text-3xl font-bold text-gray-800">Task<span class="text-primary">Flow</span></h1>
            </div>
            <div class="flex items-center space-x-4">
                <div class="relative">
                    <input type="text" placeholder="Search tasks..." class="pl-10 pr-4 py-2 rounded-full border border-gray-300 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent">
                    <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
                </div>
                <button class="bg-primary hover:bg-blue-700 text-white px-6 py-2 rounded-full transition duration-300">
                    <i class="fas fa-plus mr-2"></i>New Task
                </button>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto px-4 py-8">
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Task Form -->
            <div class="lg:col-span-1">
                <div class="bg-white rounded-xl shadow-md p-6 sticky top-6">
                    <h2 class="text-2xl font-bold text-gray-800 mb-6">Create New Task</h2>
                    <form id="taskForm" class="space-y-4">
                        <div>
                            <label for="title" class="block text-sm font-medium text-gray-700 mb-1">Task Title</label>
                            <input type="text" id="title" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="What needs to be done?" required>
                        </div>
                        
                        <div>
                            <label for="description" class="block text-sm font-medium text-gray-700 mb-1">Description</label>
                            <textarea id="description" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="Add details..."></textarea>
                        </div>
                        
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label for="dueDate" class="block text-sm font-medium text-gray-700 mb-1">Due Date</label>
                                <input type="date" id="dueDate" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
                            </div>
                            
                            <div>
                                <label for="priority" class="block text-sm font-medium text-gray-700 mb-1">Priority</label>
                                <select id="priority" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
                                    <option value="low">Low</option>
                                    <option value="medium" selected>Medium</option>
                                    <option value="high">High</option>
                                </select>
                            </div>
                        </div>
                        
                        <div>
                            <label for="category" class="block text-sm font-medium text-gray-700 mb-1">Category</label>
                            <select id="category" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
                                <option value="work">Work</option>
                                <option value="personal">Personal</option>
                                <option value="shopping">Shopping</option>
                                <option value="health">Health</option>
                                <option value="other">Other</option>
                            </select>
                        </div>
                        
                        <div class="pt-4">
                            <button type="submit" class="w-full bg-primary hover:bg-blue-700 text-white font-medium py-3 rounded-lg transition duration-300">
                                <i class="fas fa-plus-circle mr-2"></i>Add Task
                            </button>
                        </div>
                    </form>
                </div>
            </div>
            
            <!-- Task List -->
            <div class="lg:col-span-2">
                <div class="flex justify-between items-center mb-6">
                    <h2 class="text-2xl font-bold text-gray-800">My Tasks</h2>
                    <div class="flex space-x-2">
                        <button id="filterPending" class="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50">
                            <i class="fas fa-filter mr-2"></i>Show Pending
                        </button>
                        <div class="relative">
                            <button id="sortButton" class="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 flex items-center">
                                <i class="fas fa-sort mr-2"></i>Sort
                                <i class="fas fa-chevron-down ml-2 text-xs"></i>
                            </button>
                            <div id="sortDropdown" class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 hidden">
                                <div class="py-1">
                                    <a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="date-asc">Date (Oldest First)</a>
                                    <a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="date-desc">Date (Newest First)</a>
                                    <a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="priority">Priority</a>
                                    <a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="category">Category</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Stats Cards -->
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
                    <div class="bg-white rounded-xl shadow-sm p-4">
                        <div class="flex justify-between">
                            <div>
                                <p class="text-sm text-gray-500">Total Tasks</p>
                                <h3 id="totalTasks" class="text-2xl font-bold text-gray-800">3</h3>
                            </div>
                            <div class="bg-blue-100 p-3 rounded-lg">
                                <i class="fas fa-tasks text-primary text-xl"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-sm p-4">
                        <div class="flex justify-between">
                            <div>
                                <p class="text-sm text-gray-500">Completed</p>
                                <h3 id="completedTasks" class="text-2xl font-bold text-gray-800">1</h3>
                            </div>
                            <div class="bg-green-100 p-3 rounded-lg">
                                <i class="fas fa-check-circle text-secondary text-xl"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-sm p-4">
                        <div class="flex justify-between">
                            <div>
                                <p class="text-sm text-gray-500">Pending</p>
                                <h3 id="pendingTasks" class="text-2xl font-bold text-gray-800">2</h3>
                            </div>
                            <div class="bg-yellow-100 p-3 rounded-lg">
                                <i class="fas fa-exclamation-circle text-yellow-500 text-xl"></i>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Task List Content -->
                <div id="taskList" class="space-y-4">
                    <!-- Task cards will be added here dynamically -->
                </div>
                
                <!-- Empty State -->
                <div id="emptyState" class="text-center py-12 hidden">
                    <div class="mx-auto bg-gray-100 p-6 rounded-full w-24 h-24 flex items-center justify-center mb-4">
                        <i class="fas fa-check-circle text-gray-400 text-4xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-gray-700 mb-2">No tasks yet</h3>
                    <p class="text-gray-500 max-w-md mx-auto">Get started by creating your first task. Click the "New Task" button to add a task.</p>
                </div>
            </div>
        </div>
    </main>
    
    <!-- Edit Task Modal -->
    <div id="editModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-md mx-4 modal">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-xl font-bold text-gray-800">Edit Task</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="editTitle" class="block text-sm font-medium text-gray-700 mb-1">Task Title</label>
                        <input type="text" id="editTitle" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent" required>
                    </div>
                    
                    <div>
                        <label for="editDescription" class="block text-sm font-medium text-gray-700 mb-1">Description</label>
                        <textarea id="editDescription" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent"></textarea>
                    </div>
                    
                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <label for="editDueDate" class="block text-sm font-medium text-gray-700 mb-1">Due Date</label>
                            <input type="date" id="editDueDate" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
                        </div>
                        
                        <div>
                            <label for="editPriority" class="block text-sm font-medium text-gray-700 mb-1">Priority</label>
                            <select id="editPriority" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
                                <option value="low">Low</option>
                                <option value="medium">Medium</option>
                                <option value="high">High</option>
                            </select>
                        </div>
                    </div>
                    
                    <div>
                        <label for="editCategory" class="block text-sm font-medium text-gray-700 mb-1">Category</label>
                        <select id="editCategory" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
                            <option value="work">Work</option>
                            <option value="personal">Personal</option>
                            <option value="shopping">Shopping</option>
                            <option value="health">Health</option>
                            <option value="other">Other</option>
                        </select>
                    </div>
                    
                    <div class="pt-4 flex space-x-3">
                        <button type="button" id="deleteTask" class="flex-1 bg-red-100 hover:bg-red-200 text-red-700 font-medium py-3 rounded-lg transition duration-300">
                            <i class="fas fa-trash mr-2"></i>Delete
                        </button>
                        <button type="submit" class="flex-1 bg-primary hover:bg-blue-700 text-white font-medium py-3 rounded-lg transition duration-300">
                            <i class="fas fa-save mr-2"></i>Save Changes
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <!-- Footer -->
    <footer class="bg-white border-t mt-12">
        <div class="container mx-auto px-4 py-6">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <p class="text-gray-600">© 2023 TaskFlow. All rights reserved.</p>
                <div class="flex space-x-4 mt-4 md:mt-0">
                    <a href="#" class="text-gray-500 hover:text-primary">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <a href="#" class="text-gray-500 hover:text-primary">
                        <i class="fab fa-facebook"></i>
                    </a>
                    <a href="#" class="text-gray-500 hover:text-primary">
                        <i class="fab fa-github"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>
    
    <script>
        // Sample initial tasks
        let tasks = [
            {
                id: 1,
                title: "Complete project proposal",
                description: "Finish and submit the project proposal document to the client",
                dueDate: "2023-06-15",
                priority: "high",
                category: "work",
                completed: false
            },
            {
                id: 2,
                title: "Grocery shopping",
                description: "Milk, eggs, bread, fruits, and vegetables",
                dueDate: "2023-06-10",
                priority: "medium",
                category: "shopping",
                completed: false
            },
            {
                id: 3,
                title: "Morning jog",
                description: "5km run in the park",
                dueDate: "2023-06-08",
                priority: "low",
                category: "health",
                completed: true
            }
        ];
        
        // DOM Elements
        const taskForm = document.getElementById('taskForm');
        const editForm = document.getElementById('editForm');
        const taskList = document.getElementById('taskList');
        const emptyState = document.getElementById('emptyState');
        const editModal = document.getElementById('editModal');
        const closeModal = document.getElementById('closeModal');
        const deleteButton = document.getElementById('deleteTask');
        
        // Initialize app
        document.addEventListener('DOMContentLoaded', () => {
            renderTasks();
            setupEventListeners();
            
            // Add filter event listener
            document.getElementById('filterPending').addEventListener('click', () => {
                const filteredTasks = tasks.filter(task => !task.completed);
                renderFilteredTasks(filteredTasks);
            });

            // Sort functionality
            const sortButton = document.getElementById('sortButton');
            const sortDropdown = document.getElementById('sortDropdown');
            
            sortButton.addEventListener('click', () => {
                sortDropdown.classList.toggle('hidden');
            });

            // Close dropdown when clicking outside
            document.addEventListener('click', (e) => {
                if (!sortButton.contains(e.target) && !sortDropdown.contains(e.target)) {
                    sortDropdown.classList.add('hidden');
                }
            });

            // Handle sort option selection
            document.querySelectorAll('.sort-option').forEach(option => {
                option.addEventListener('click', (e) => {
                    e.preventDefault();
                    const sortType = e.target.dataset.sort;
                    sortTasks(sortType);
                    sortDropdown.classList.add('hidden');
                });
            });
        });

        // Sort tasks based on selected criteria
        function sortTasks(sortType) {
            let sortedTasks = [...tasks];
            
            switch(sortType) {
                case 'date-asc':
                    sortedTasks.sort((a, b) => {
                        if (!a.dueDate && !b.dueDate) return 0;
                        if (!a.dueDate) return 1;
                        if (!b.dueDate) return -1;
                        return new Date(a.dueDate) - new Date(b.dueDate);
                    });
                    break;
                    
                case 'date-desc':
                    sortedTasks.sort((a, b) => {
                        if (!a.dueDate && !b.dueDate) return 0;
                        if (!a.dueDate) return 1;
                        if (!b.dueDate) return -1;
                        return new Date(b.dueDate) - new Date(a.dueDate);
                    });
                    break;
                    
                case 'priority':
                    const priorityOrder = { high: 3, medium: 2, low: 1 };
                    sortedTasks.sort((a, b) => priorityOrder[b.priority] - priorityOrder[a.priority]);
                    break;
                    
                case 'category':
                    sortedTasks.sort((a, b) => a.category.localeCompare(b.category));
                    break;
            }
            
            renderFilteredTasks(sortedTasks);
            showNotification(`Tasks sorted by ${sortType.replace('-', ' ')}`);
        }
        
        // Set up event listeners
        function setupEventListeners() {
            taskForm.addEventListener('submit', addTask);
            editForm.addEventListener('submit', updateTask);
            closeModal.addEventListener('click', () => editModal.classList.add('hidden'));
            deleteButton.addEventListener('click', deleteTask);
            
            // Close modal when clicking outside
            editModal.addEventListener('click', (e) => {
                if (e.target === editModal) {
                    editModal.classList.add('hidden');
                }
            });
        }
        
        // Add new task
        function addTask(e) {
            e.preventDefault();
            
            const title = document.getElementById('title').value;
            const description = document.getElementById('description').value;
            const dueDate = document.getElementById('dueDate').value;
            const priority = document.getElementById('priority').value;
            const category = document.getElementById('category').value;
            
            const newTask = {
                id: Date.now(),
                title,
                description,
                dueDate,
                priority,
                category,
                completed: false
            };
            
            tasks.push(newTask);
            renderTasks();
            
            // Reset form
            taskForm.reset();
            
            // Show notification
            showNotification('Task added successfully!');
        }
        
        // Update task
        function updateTask(e) {
            e.preventDefault();
            
            const id = parseInt(document.getElementById('editId').value);
            const title = document.getElementById('editTitle').value;
            const description = document.getElementById('editDescription').value;
            const dueDate = document.getElementById('editDueDate').value;
            const priority = document.getElementById('editPriority').value;
            const category = document.getElementById('editCategory').value;
            
            const taskIndex = tasks.findIndex(task => task.id === id);
            
            if (taskIndex !== -1) {
                tasks[taskIndex] = {
                    ...tasks[taskIndex],
                    title,
                    description,
                    dueDate,
                    priority,
                    category
                };
                
                renderTasks();
                editModal.classList.add('hidden');
                
                // Show notification
                showNotification('Task updated successfully!');
            }
        }
        
        // Delete task
        function deleteTask() {
            const id = parseInt(document.getElementById('editId').value);
            
            tasks = tasks.filter(task => task.id !== id);
            renderTasks();
            editModal.classList.add('hidden');
            
            // Show notification
            showNotification('Task deleted successfully!');
        }
        
        // Toggle task completion
        function toggleTaskCompletion(id) {
            const task = tasks.find(task => task.id === id);
            if (task) {
                task.completed = !task.completed;
                renderTasks();
                updateStats();
                
                // Show notification
                const message = task.completed ? 'Task marked as completed!' : 'Task marked as pending!';
                showNotification(message);
            }
        }
        
        // Open edit modal
        function openEditModal(id) {
            const task = tasks.find(task => task.id === id);
            
            if (task) {
                document.getElementById('editId').value = task.id;
                document.getElementById('editTitle').value = task.title;
                document.getElementById('editDescription').value = task.description;
                document.getElementById('editDueDate').value = task.dueDate;
                document.getElementById('editPriority').value = task.priority;
                document.getElementById('editCategory').value = task.category;
                
                editModal.classList.remove('hidden');
            }
        }
        
        // Update stats counters
        function updateStats() {
            const totalTasks = tasks.length;
            const completedTasks = tasks.filter(task => task.completed).length;
            const pendingTasks = totalTasks - completedTasks;
            
            document.getElementById('totalTasks').textContent = totalTasks;
            document.getElementById('completedTasks').textContent = completedTasks;
            document.getElementById('pendingTasks').textContent = pendingTasks;
        }

        // Render all tasks
        function renderTasks() {
            renderFilteredTasks(tasks);
            updateStats();
        }
        
        // Render filtered tasks
        function renderFilteredTasks(filteredTasks) {
            if (filteredTasks.length === 0) {
                taskList.classList.add('hidden');
                emptyState.classList.remove('hidden');
                return;
            }
            
            taskList.classList.remove('hidden');
            emptyState.classList.add('hidden');
            
            taskList.innerHTML = '';
            
            // Sort tasks: uncompleted first, then by priority (high to low)
            const sortedTasks = [...filteredTasks].sort((a, b) => {
                if (a.completed !== b.completed) {
                    return a.completed ? 1 : -1;
                }
                
                const priorityOrder = { high: 3, medium: 2, low: 1 };
                return priorityOrder[b.priority] - priorityOrder[a.priority];
            });
            
            sortedTasks.forEach(task => {
                const taskCard = document.createElement('div');
                taskCard.className = `task-card bg-white rounded-xl shadow-sm overflow-hidden ${task.completed ? 'completed-task' : ''}`;
                taskCard.innerHTML = `
                    <div class="p-5 flex ${!task.completed ? 'pending-task' : ''}">
                        <div class="mr-4 mt-1">
                            <button onclick="toggleTaskCompletion(${task.id})" class="w-6 h-6 rounded-full border-2 flex items-center justify-center ${task.completed ? 'bg-secondary border-secondary' : 'border-gray-300'}">
                                ${task.completed ? '<i class="fas fa-check text-white text-xs"></i>' : ''}
                            </button>
                        </div>
                        <div class="flex-1">
                            <div class="flex justify-between items-start">
                                <h3 class="font-semibold text-gray-800 ${task.completed ? 'line-through' : ''}">${task.title}</h3>
                                <span class="text-xs font-medium px-2 py-1 rounded-full ${task.priority === 'high' ? 'bg-red-100 text-red-800' : task.priority === 'medium' ? 'bg-yellow-100 text-yellow-800' : 'bg-green-100 text-green-800'}">
                                    ${task.priority.charAt(0).toUpperCase() + task.priority.slice(1)}
                                </span>
                            </div>
                            <p class="text-gray-600 text-sm mt-1 ${task.completed ? 'line-through' : ''}">${task.description || 'No description'}</p>
                            
                            <div class="flex justify-between items-center mt-3">
                                <div class="flex items-center text-sm text-gray-500">
                                    <i class="far fa-calendar mr-1"></i>
                                    <span>${task.dueDate || 'No due date'}</span>
                                </div>
                                <div class="flex space-x-2">
                                    <button onclick="openEditModal(${task.id})" class="text-gray-500 hover:text-primary">
                                        <i class="fas fa-edit"></i>
                                    </button>
                                    <span class="text-xs font-medium px-2 py-1 rounded-full bg-gray-100 text-gray-700">
                                        ${task.category.charAt(0).toUpperCase() + task.category.slice(1)}
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                `;
                taskList.appendChild(taskCard);
            });
        }
        
        // Show notification
        function showNotification(message) {
            // Create notification element
            const notification = document.createElement('div');
            notification.className = 'fixed top-4 right-4 bg-white shadow-lg rounded-lg px-4 py-3 flex items-center transform translate-y-0 opacity-100 transition-all duration-300';
            notification.innerHTML = `
                <div class="bg-green-100 p-2 rounded-full mr-3">
                    <i class="fas fa-check-circle text-green-600"></i>
                </div>
                <div>
                    <p class="font-medium text-gray-800">Success</p>
                    <p class="text-sm text-gray-600">${message}</p>
                </div>
            `;
            
            document.body.appendChild(notification);
            
            // Remove notification after 3 seconds
            setTimeout(() => {
                notification.style.transform = 'translateY(-20px)';
                notification.style.opacity = '0';
                setTimeout(() => {
                    document.body.removeChild(notification);
                }, 300);
            }, 3000);
        }
        
        // Expose functions to global scope for inline event handlers
        window.toggleTaskCompletion = toggleTaskCompletion;
        window.openEditModal = openEditModal;
    </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=Ragnarucem/taskflow-rag" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>