File size: 29,671 Bytes
c2dcf84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5107ce4
c2dcf84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Data Entry Form with Google Sheets</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <style>
        .form-section {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }
        .data-table {
            max-height: 500px;
            overflow-y: auto;
        }
        .highlight-row {
            transition: all 0.3s ease;
        }
        .highlight-row:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body class="bg-gray-50">
    <div id="app" class="min-h-screen">
        <!-- Header -->
        <header class="bg-indigo-600 text-white shadow-lg">
            <div class="container mx-auto px-4 py-6">
                <div class="flex flex-col md:flex-row justify-between items-center">
                    <div class="flex items-center mb-4 md:mb-0">
                        <i data-feather="database" class="w-8 h-8 mr-3"></i>
                        <h1 class="text-2xl font-bold">Google Sheets Data Manager</h1>
                    </div>
                    <nav class="flex space-x-4">
                        <button id="showFormBtn" class="px-4 py-2 bg-white text-indigo-600 rounded-lg font-medium hover:bg-indigo-50 transition">
                            <i data-feather="plus" class="inline mr-2"></i>Add Record
                        </button>
                        <button id="refreshBtn" class="px-4 py-2 bg-indigo-700 rounded-lg font-medium hover:bg-indigo-800 transition">
                            <i data-feather="refresh-cw" class="inline mr-2"></i>Refresh
                        </button>
                    </nav>
                </div>
            </div>
        </header>

        <!-- Main Content -->
        <main class="container mx-auto px-4 py-8">
            <!-- Form Section (Initially Hidden) -->
            <section id="formSection" class="form-section hidden rounded-xl shadow-lg p-6 mb-8" data-aos="fade-up">
                <div class="flex justify-between items-center mb-6">
                    <h2 class="text-xl font-semibold text-gray-800">Data Entry Form</h2>
                    <button id="closeFormBtn" class="text-gray-500 hover:text-gray-700">
                        <i data-feather="x" class="w-6 h-6"></i>
                    </button>
                </div>
                
                <form id="dataForm" class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <input type="hidden" id="recordId" value="">
                    
                    <div>
                        <label for="name" class="block text-sm font-medium text-gray-700 mb-1">Full Name *</label>
                        <input type="text" id="name" name="name" required
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    </div>
                    
                    <div>
                        <label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email *</label>
                        <input type="email" id="email" name="email" required
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    </div>
                    
                    <div>
                        <label for="phone" class="block text-sm font-medium text-gray-700 mb-1">Phone Number</label>
                        <input type="tel" id="phone" name="phone"
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    </div>
                    
                    <div>
                        <label for="department" class="block text-sm font-medium text-gray-700 mb-1">Department *</label>
                        <select id="department" name="department" required
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                            <option value="">Select Department</option>
                            <option value="Sales">Sales</option>
                            <option value="Marketing">Marketing</option>
                            <option value="IT">IT</option>
                            <option value="HR">Human Resources</option>
                            <option value="Finance">Finance</option>
                        </select>
                    </div>
                    
                    <div class="md:col-span-2">
                        <label for="address" class="block text-sm font-medium text-gray-700 mb-1">Address</label>
                        <textarea id="address" name="address" rows="2"
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"></textarea>
                    </div>
                    
                    <div>
                        <label for="joinDate" class="block text-sm font-medium text-gray-700 mb-1">Join Date</label>
                        <input type="date" id="joinDate" name="joinDate"
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Employment Status</label>
                        <div class="flex space-x-4">
                            <label class="inline-flex items-center">
                                <input type="radio" name="status" value="Full-time" checked
                                    class="h-4 w-4 text-indigo-600 focus:ring-indigo-500">
                                <span class="ml-2 text-gray-700">Full-time</span>
                            </label>
                            <label class="inline-flex items-center">
                                <input type="radio" name="status" value="Part-time"
                                    class="h-4 w-4 text-indigo-600 focus:ring-indigo-500">
                                <span class="ml-2 text-gray-700">Part-time</span>
                            </label>
                            <label class="inline-flex items-center">
                                <input type="radio" name="status" value="Contract"
                                    class="h-4 w-4 text-indigo-600 focus:ring-indigo-500">
                                <span class="ml-2 text-gray-700">Contract</span>
                            </label>
                        </div>
                    </div>
                    
                    <div class="md:col-span-2 flex justify-end space-x-4 pt-4">
                        <button type="reset" id="resetBtn" class="px-6 py-2 border border-gray-300 rounded-lg font-medium text-gray-700 hover:bg-gray-50 transition">
                            <i data-feather="rotate-ccw" class="inline mr-2"></i>Reset
                        </button>
                        <button type="submit" id="submitBtn" class="px-6 py-2 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700 transition">
                            <i data-feather="save" class="inline mr-2"></i>Submit
                        </button>
                    </div>
                </form>
            </section>

            <!-- Data Table Section -->
            <section class="bg-white rounded-xl shadow-lg overflow-hidden" data-aos="fade-up">
                <div class="px-6 py-4 border-b border-gray-200">
                    <h2 class="text-xl font-semibold text-gray-800">Records</h2>
                </div>
                
                <div class="p-4">
                    <div class="mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between">
                        <div class="relative mb-2 sm:mb-0">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i data-feather="search" class="text-gray-400"></i>
                            </div>
                            <input type="text" id="searchInput" placeholder="Search records..."
                                class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 w-full sm:w-64">
                        </div>
                        <div class="flex space-x-2">
                            <select id="departmentFilter" class="px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                                <option value="">All Departments</option>
                                <option value="Sales">Sales</option>
                                <option value="Marketing">Marketing</option>
                                <option value="IT">IT</option>
                                <option value="HR">Human Resources</option>
                                <option value="Finance">Finance</option>
                            </select>
                            <select id="statusFilter" class="px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                                <option value="">All Statuses</option>
                                <option value="Full-time">Full-time</option>
                                <option value="Part-time">Part-time</option>
                                <option value="Contract">Contract</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="overflow-x-auto data-table">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Department</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Join Date</th>
                                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="dataTableBody" class="bg-white divide-y divide-gray-200">
                                <!-- Data will be loaded here -->
                                <tr>
                                    <td colspan="6" class="px-6 py-4 text-center text-gray-500">Loading data...</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="flex items-center justify-between mt-4 px-2">
                        <div class="text-sm text-gray-500">
                            Showing <span id="startItem">1</span> to <span id="endItem">10</span> of <span id="totalItems">0</span> entries
                        </div>
                        <div class="flex space-x-2">
                            <button id="prevPage" class="px-3 py-1 border border-gray-300 rounded text-gray-700 disabled:opacity-50" disabled>
                                <i data-feather="chevron-left" class="w-4 h-4"></i>
                            </button>
                            <button id="nextPage" class="px-3 py-1 border border-gray-300 rounded text-gray-700 disabled:opacity-50" disabled>
                                <i data-feather="chevron-right" class="w-4 h-4"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </section>
        </main>

        <!-- Notification Toast -->
        <div id="toast" class="fixed bottom-4 right-4 hidden">
            <div class="bg-green-500 text-white px-4 py-3 rounded-lg shadow-lg flex items-center">
                <i data-feather="check-circle" class="mr-2"></i>
                <span id="toastMessage">Operation successful!</span>
            </div>
        </div>

        <!-- Delete Confirmation Modal -->
        <div id="deleteModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
            <div class="bg-white rounded-lg p-6 max-w-md w-full" data-aos="zoom-in">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-lg font-semibold text-gray-800">Confirm Deletion</h3>
                    <button id="closeDeleteModal" class="text-gray-500 hover:text-gray-700">
                        <i data-feather="x" class="w-5 h-5"></i>
                    </button>
                </div>
                <p class="text-gray-600 mb-6">Are you sure you want to delete this record? This action cannot be undone.</p>
                <div class="flex justify-end space-x-3">
                    <button id="cancelDelete" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50">
                        Cancel
                    </button>
                    <button id="confirmDelete" class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700">
                        Delete
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Initialize AOS and Feather Icons
        AOS.init({
            duration: 600,
            once: true
        });
        feather.replace();
        
        // DOM Elements
        const showFormBtn = document.getElementById('showFormBtn');
        const closeFormBtn = document.getElementById('closeFormBtn');
        const formSection = document.getElementById('formSection');
        const dataForm = document.getElementById('dataForm');
        const submitBtn = document.getElementById('submitBtn');
        const resetBtn = document.getElementById('resetBtn');
        const refreshBtn = document.getElementById('refreshBtn');
        const dataTableBody = document.getElementById('dataTableBody');
        const searchInput = document.getElementById('searchInput');
        const departmentFilter = document.getElementById('departmentFilter');
        const statusFilter = document.getElementById('statusFilter');
        const toast = document.getElementById('toast');
        const toastMessage = document.getElementById('toastMessage');
        const deleteModal = document.getElementById('deleteModal');
        const closeDeleteModal = document.getElementById('closeDeleteModal');
        const cancelDelete = document.getElementById('cancelDelete');
        const confirmDelete = document.getElementById('confirmDelete');
        const prevPage = document.getElementById('prevPage');
        const nextPage = document.getElementById('nextPage');
        const startItem = document.getElementById('startItem');
        const endItem = document.getElementById('endItem');
        const totalItems = document.getElementById('totalItems');
        
        // State variables
        let currentRecordId = null;
        let currentPage = 1;
        const recordsPerPage = 10;
        let allRecords = [];
        let filteredRecords = [];
        
        // Event Listeners
        showFormBtn.addEventListener('click', () => {
            formSection.classList.remove('hidden');
            dataForm.reset();
            document.getElementById('recordId').value = '';
            window.scrollTo({ top: formSection.offsetTop - 20, behavior: 'smooth' });
        });
        
        closeFormBtn.addEventListener('click', () => {
            formSection.classList.add('hidden');
        });
        
        refreshBtn.addEventListener('click', loadData);
        
        dataForm.addEventListener('submit', async (e) => {
            e.preventDefault();
            submitBtn.disabled = true;
            submitBtn.innerHTML = '<i data-feather="loader" class="animate-spin inline mr-2"></i>Processing...';
            feather.replace();
            
            try {
                const formData = new FormData(dataForm);
                const record = Object.fromEntries(formData.entries());
                
                // Simulate API call to Google Apps Script
                await new Promise(resolve => setTimeout(resolve, 1000));
                
                showToast('Record saved successfully!');
                formSection.classList.add('hidden');
                loadData();
            } catch (error) {
                console.error('Error:', error);
                showToast('Error saving record!', 'error');
            } finally {
                submitBtn.disabled = false;
                submitBtn.innerHTML = '<i data-feather="save" class="inline mr-2"></i>Submit';
                feather.replace();
            }
        });
        
        searchInput.addEventListener('input', filterRecords);
        departmentFilter.addEventListener('change', filterRecords);
        statusFilter.addEventListener('change', filterRecords);
        
        prevPage.addEventListener('click', () => {
            if (currentPage > 1) {
                currentPage--;
                renderTable();
            }
        });
        
        nextPage.addEventListener('click', () => {
            if (currentPage < Math.ceil(filteredRecords.length / recordsPerPage)) {
                currentPage++;
                renderTable();
            }
        });
        
        // Functions
        function showToast(message, type = 'success') {
            toastMessage.textContent = message;
            toast.className = `fixed bottom-4 right-4 flex items-center px-4 py-3 rounded-lg shadow-lg ${type === 'success' ? 'bg-green-500' : 'bg-red-500'} text-white`;
            toast.classList.remove('hidden');
            
            setTimeout(() => {
                toast.classList.add('hidden');
            }, 3000);
            
            feather.replace();
        }
        
        function filterRecords() {
            const searchTerm = searchInput.value.toLowerCase();
            const department = departmentFilter.value;
            const status = statusFilter.value;
            
            filteredRecords = allRecords.filter(record => {
                const matchesSearch = 
                    record.name.toLowerCase().includes(searchTerm) || 
                    record.email.toLowerCase().includes(searchTerm);
                
                const matchesDepartment = department ? record.department === department : true;
                const matchesStatus = status ? record.status === status : true;
                
                return matchesSearch && matchesDepartment && matchesStatus;
            });
            
            currentPage = 1;
            renderTable();
        }
        
        function renderTable() {
            const startIndex = (currentPage - 1) * recordsPerPage;
            const endIndex = startIndex + recordsPerPage;
            const paginatedRecords = filteredRecords.slice(startIndex, endIndex);
            
            dataTableBody.innerHTML = '';
            
            if (paginatedRecords.length === 0) {
                dataTableBody.innerHTML = `
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">No records found</td>
                    </tr>
                `;
            } else {
                paginatedRecords.forEach(record => {
                    const row = document.createElement('tr');
                    row.className = 'highlight-row hover:bg-gray-50';
                    row.innerHTML = `
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="flex items-center">
                                <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center">
                                    <i data-feather="user" class="text-indigo-600"></i>
                                </div>
                                <div class="ml-4">
                                    <div class="text-sm font-medium text-gray-900">${record.name}</div>
                                    <div class="text-sm text-gray-500">${record.phone || 'N/A'}</div>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${record.email}</td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full 
                                ${getDepartmentColor(record.department)}">
                                ${record.department}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${record.status}</td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${formatDate(record.joinDate)}</td>
                        <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                            <button class="text-indigo-600 hover:text-indigo-900 mr-3 edit-btn" data-id="${record.id}">
                                <i data-feather="edit" class="w-4 h-4"></i>
                            </button>
                            <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${record.id}">
                                <i data-feather="trash-2" class="w-4 h-4"></i>
                            </button>
                        </td>
                    `;
                    dataTableBody.appendChild(row);
                });
                
                // Add event listeners to edit and delete buttons
                document.querySelectorAll('.edit-btn').forEach(btn => {
                    btn.addEventListener('click', (e) => {
                        const id = e.currentTarget.getAttribute('data-id');
                        editRecord(id);
                    });
                });
                
                document.querySelectorAll('.delete-btn').forEach(btn => {
                    btn.addEventListener('click', (e) => {
                        const id = e.currentTarget.getAttribute('data-id');
                        showDeleteModal(id);
                    });
                });
            }
            
            // Update pagination info
            startItem.textContent = startIndex + 1;
            endItem.textContent = Math.min(endIndex, filteredRecords.length);
            totalItems.textContent = filteredRecords.length;
            
            // Update pagination buttons
            prevPage.disabled = currentPage === 1;
            nextPage.disabled = currentPage === Math.ceil(filteredRecords.length / recordsPerPage);
            
            feather.replace();
        }
        
        function getDepartmentColor(department) {
            const colors = {
                'Sales': 'bg-blue-100 text-blue-800',
                'Marketing': 'bg-purple-100 text-purple-800',
                'IT': 'bg-green-100 text-green-800',
                'HR': 'bg-yellow-100 text-yellow-800',
                'Finance': 'bg-red-100 text-red-800'
            };
            return colors[department] || 'bg-gray-100 text-gray-800';
        }
        
        function formatDate(dateString) {
            if (!dateString) return 'N/A';
            const date = new Date(dateString);
            return date.toLocaleDateString();
        }
        
        function editRecord(id) {
            const record = allRecords.find(r => r.id === id);
            if (!record) return;
            
            // Populate form
            document.getElementById('recordId').value = record.id;
            document.getElementById('name').value = record.name;
            document.getElementById('email').value = record.email;
            document.getElementById('phone').value = record.phone;
            document.getElementById('department').value = record.department;
            document.getElementById('address').value = record.address;
            document.getElementById('joinDate').value = record.joinDate;
            document.querySelector(`input[name="status"][value="${record.status}"]`).checked = true;
            
            // Show form
            formSection.classList.remove('hidden');
            window.scrollTo({ top: formSection.offsetTop - 20, behavior: 'smooth' });
            
            showToast('Record loaded for editing');
        }
        
        function showDeleteModal(id) {
            currentRecordId = id;
            deleteModal.classList.remove('hidden');
        }
        
        function hideDeleteModal() {
            deleteModal.classList.add('hidden');
            currentRecordId = null;
        }
        
        async function deleteRecord() {
            try {
                // Simulate API call to Google Apps Script
                await new Promise(resolve => setTimeout(resolve, 800));
                
                showToast('Record deleted successfully!');
                hideDeleteModal();
                loadData();
            } catch (error) {
                console.error('Error:', error);
                showToast('Error deleting record!', 'error');
            }
        }
        
        async function loadData() {
            dataTableBody.innerHTML = `
                <tr>
                    <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                        <div class="flex justify-center">
                            <i data-feather="loader" class="animate-spin w-8 h-8 text-indigo-600"></i>
                        </div>
                    </td>
                </tr>
            `;
            feather.replace();
            
            try {
                // Simulate API call to Google Apps Script
                await new Promise(resolve => setTimeout(resolve, 1200));
                
                // Mock data - in a real app, this would come from Google Sheets
                allRecords = Array.from({ length: 35 }, (_, i) => ({
                    id: `rec-${i + 1}`,
                    name: `Employee ${i + 1}`,
                    email: `employee${i + 1}@example.com`,
                    phone: `555-${1000 + i}`,
                    department: ['Sales', 'Marketing', 'IT', 'HR', 'Finance'][Math.floor(Math.random() * 5)],
                    address: `${i + 100} Main St, City ${i % 5 + 1}`,
                    joinDate: new Date(Date.now() - Math.floor(Math.random() * 1000 * 60 * 60 * 24 * 365 * 3)).toISOString().split('T')[0],
                    status: ['Full-time', 'Part-time', 'Contract'][Math.floor(Math.random() * 3)]
                }));
                
                filteredRecords = [...allRecords];
                currentPage = 1;
                renderTable();
            } catch (error) {
                console.error('Error:', error);
                dataTableBody.innerHTML = `
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-red-500">
                            Error loading data. Please try again.
                        </td>
                    </tr>
                `;
            }
        }
        
        // Modal event listeners
        closeDeleteModal.addEventListener('click', hideDeleteModal);
        cancelDelete.addEventListener('click', hideDeleteModal);
        confirmDelete.addEventListener('click', deleteRecord);
        
        // Initial load
        loadData();
    </script>
</body>
</html>


This implementation includes:

1. A responsive form with validation for creating/editing records
2. A data table with search, filtering, and pagination
3. CRUD operations (Create, Read, Update, Delete)
4. Modal dialogs for confirmation
5. Toast notifications for user feedback
6. Loading states for better UX
7. Mobile-friendly design using Tailwind CSS
8. Feather icons for visual elements
9. AOS animations for smooth transitions

The code is structured to work with Google Apps Script in a real implementation (the API calls are simulated with timeouts in this demo). The UI follows modern design principles with a clean, professional look.