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
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TableToDash - WordPress Dashboard Converter</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="components/navbar.js"></script>
    <script src="components/footer.js"></script>
    <style>
        .dropzone {
            border: 2px dashed #ccc;
            border-radius: 8px;
            padding: 40px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
        }
        .dropzone.active {
            border-color: #3b82f6;
            background-color: #f0f7ff;
        }
        #previewTable {
            max-height: 400px;
            overflow-y: auto;
        }
        .chart-container {
            position: relative;
            height: 300px;
            margin-bottom: 2rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <custom-navbar></custom-navbar>
    
    <main class="container mx-auto px-4 py-8">
        <div class="text-center mb-8">
            <h1 class="text-3xl font-bold text-gray-800">TableToDash Converter</h1>
            <p class="text-gray-600 mt-2">Upload your Excel/CSV table and transform it into a WordPress dashboard</p>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
            <div class="bg-white rounded-xl shadow-md p-6">
                <h2 class="text-xl font-semibold mb-4">Upload Your Data</h2>
                
                <div id="dropZone" class="dropzone">
                    <div class="space-y-2">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 mx-auto text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
                        </svg>
                        <p class="text-lg font-medium">Drag & Drop your Excel/CSV file here</p>
                        <p class="text-gray-500">or click to browse files</p>
                        <input type="file" id="fileInput" class="hidden" accept=".xlsx,.xls,.csv">
                    </div>
                </div>
                
                <div class="mt-4 flex justify-between">
                    <div class="flex items-center">
                        <input type="checkbox" id="hasHeaders" class="mr-2" checked>
                        <label for="hasHeaders">First row contains headers</label>
                    </div>
                    <button id="processBtn" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition disabled:opacity-50" disabled>
                        Process File
                    </button>
                </div>

                <div id="tablePreview" class="mt-6 hidden">
                    <h3 class="text-lg font-medium mb-2">Data Preview</h3>
                    <div id="previewTable" class="border rounded-lg overflow-auto"></div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md p-6">
                <h2 class="text-xl font-semibold mb-4">Dashboard Configuration</h2>
                
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Dashboard Title</label>
                        <input type="text" id="dashboardTitle" class="w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="Enter dashboard title">
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Key Metrics</label>
                        <div id="metricFields" class="space-y-2"></div>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Visualizations</label>
                        <div class="space-y-3">
                            <div class="flex items-center">
                                <input type="checkbox" id="includeBarChart" class="mr-2" checked>
                                <label for="includeBarChart">Bar Chart</label>
                            </div>
                            <div class="flex items-center">
                                <input type="checkbox" id="includePieChart" class="mr-2" checked>
                                <label for="includePieChart">Pie Chart</label>
                            </div>
                            <div class="flex items-center">
                                <input type="checkbox" id="includeLineChart" class="mr-2" checked>
                                <label for="includeLineChart">Line Chart</label>
                            </div>
                        </div>
                    </div>
                    
                    <div id="chartConfigs" class="space-y-4 hidden">
                        <!-- Chart configurations will be added here -->
                    </div>
                    
                    <button id="generateBtn" class="w-full px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 transition disabled:opacity-50" disabled>
                        Generate WordPress Dashboard
                    </button>
                </div>
            </div>
        </div>

        <div id="dashboardPreview" class="mt-8 hidden">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-2xl font-bold text-gray-800">Dashboard Preview</h2>
                <button id="exportBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition flex items-center gap-2">
                    Export to WordPress
                </button>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6">
                <h2 id="previewTitle" class="text-2xl font-bold mb-6"></h2>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8" id="metricsPreview">
                    <!-- Metrics will be populated here -->
                </div>
                
                <div class="grid grid-cols-1 gap-8">
                    <div id="barChartContainer" class="chart-container">
                        <canvas id="barChart"></canvas>
                    </div>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                        <div id="pieChartContainer" class="chart-container">
                            <canvas id="pieChart"></canvas>
                        </div>
                        <div id="lineChartContainer" class="chart-container">
                            <canvas id="lineChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <custom-footer></custom-footer>
    
    <script src="components/navbar.js"></script>
    <script src="components/footer.js"></script>
    <script src="script.js"></script>
    <script>
        // Initialize feather icons
        document.addEventListener('DOMContentLoaded', function() {
            feather.replace();
            
            // Drag and drop functionality
            const dropZone = document.getElementById('dropZone');
            const fileInput = document.getElementById('fileInput');
            const processBtn = document.getElementById('processBtn');
            let uploadedFile = null;
            
            dropZone.addEventListener('click', () => fileInput.click());
            
            fileInput.addEventListener('change', (e) => {
                if (e.target.files.length) {
                    uploadedFile = e.target.files[0];
                    processBtn.disabled = false;
                    dropZone.classList.add('active');
                }
            });
            
            dropZone.addEventListener('dragover', (e) => {
                e.preventDefault();
                dropZone.classList.add('active');
            });
            
            ['dragleave', 'dragend'].forEach(type => {
                dropZone.addEventListener(type, () => {
                    dropZone.classList.remove('active');
                });
            });
            
            dropZone.addEventListener('drop', (e) => {
                e.preventDefault();
                dropZone.classList.remove('active');
                
                if (e.dataTransfer.files.length) {
                    fileInput.files = e.dataTransfer.files;
                    uploadedFile = e.dataTransfer.files[0];
                    processBtn.disabled = false;
                }
            });
            
            // Process file button
            processBtn.addEventListener('click', processFile);
            
            // Generate dashboard button
            document.getElementById('generateBtn').addEventListener('click', generateDashboard);
            
            // Export button
            document.getElementById('exportBtn').addEventListener('click', exportToWordPress);
        });
        
        function processFile() {
            const file = uploadedFile;
            const reader = new FileReader();
            
            reader.onload = function(e) {
                const data = new Uint8Array(e.target.result);
                const workbook = XLSX.read(data, { type: 'array' });
                const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
                const jsonData = XLSX.utils.sheet_to_json(firstSheet, { header: 1 });
                
                // Store data globally for later use
                window.tableData = {
                    headers: document.getElementById('hasHeaders').checked ? jsonData[0] : jsonData[0].map((_, i) => `Column ${i+1}`),
                    rows: document.getElementById('hasHeaders').checked ? jsonData.slice(1) : jsonData
                };
                
                // Display preview
                displayTablePreview();
                
                // Setup metric selection
                setupMetricSelection();
            };
            
            reader.readAsArrayBuffer(file);
        }
        
        function displayTablePreview() {
            const previewDiv = document.getElementById('tablePreview');
            const previewTable = document.getElementById('previewTable');
            
            previewDiv.classList.remove('hidden');
            
            let html = '<table class="min-w-full divide-y divide-gray-200"><thead class="bg-gray-50"><tr>';
            
            // Add headers
            window.tableData.headers.forEach(header => {
                html += `<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">${header}</th>`;
            });
            
            html += '</tr></thead><tbody class="bg-white divide-y divide-gray-200">';
            
            // Add first 5 rows
            window.tableData.rows.slice(0, 5).forEach(row => {
                html += '<tr>';
                row.forEach(cell => {
                    html += `<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${cell}</td>`;
                });
                html += '</tr>';
            });
            
            html += '</tbody></table>';
            
            previewTable.innerHTML = html;
            document.getElementById('generateBtn').disabled = false;
        }
        
        function setupMetricSelection() {
            const metricFields = document.getElementById('metricFields');
            metricFields.innerHTML = '';
            
            window.tableData.headers.forEach((header, index) => {
                // Skip non-numeric columns for metrics
                if (typeof window.tableData.rows[0][index] === 'number' || !isNaN(window.tableData.rows[0][index])) {
                    metricFields.innerHTML += `
                        <div class="flex items-center space-x-3">
                            <input type="checkbox" id="metric-${index}" class="metric-checkbox" data-column="${index}" checked>
                            <div class="flex-1">
                                <label for="metric-${index}" class="text-sm">${header}</label>
                                <select class="mt-1 w-full border border-gray-300 rounded-md px-2 py-1 text-sm">
                                    <option value="sum">Sum</option>
                                    <option value="avg">Average</option>
                                    <option value="min">Min</option>
                                    <option value="max">Max</option>
                                    <option value="count">Count</option>
                                </select>
                            </div>
                        </div>
                    `;
                }
            });
        }
        
        function generateDashboard() {
            const dashboardTitle = document.getElementById('dashboardTitle').value || 'Data Dashboard';
            document.getElementById('previewTitle').textContent = dashboardTitle;
            
            // Generate metrics
            const metricsPreview = document.getElementById('metricsPreview');
            metricsPreview.innerHTML = '';
            
            document.querySelectorAll('.metric-checkbox:checked').forEach(checkbox => {
                const columnIndex = parseInt(checkbox.dataset.column);
                const header = window.tableData.headers[columnIndex];
                const operation = checkbox.parentNode.querySelector('select').value;
                
                let value;
                const numericValues = window.tableData.rows.map(row => parseFloat(row[columnIndex])).filter(v => !isNaN(v));
                
                switch(operation) {
                    case 'sum':
                        value = numericValues.reduce((a, b) => a + b, 0).toFixed(2);
                        break;
                    case 'avg':
                        value = (numericValues.reduce((a, b) => a + b, 0) / numericValues.length).toFixed(2);
                        break;
                    case 'min':
                        value = Math.min(...numericValues).toFixed(2);
                        break;
                    case 'max':
                        value = Math.max(...numericValues).toFixed(2);
                        break;
                    case 'count':
                        value = numericValues.length;
                        break;
                }
                
                metricsPreview.innerHTML += `
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <div class="flex items-center justify-between">
                            <h3 class="text-sm font-medium text-gray-600">${header} (${operation})</h3>
                            <div class="p-2 rounded-full bg-blue-100 text-blue-600">
                                <i data-feather="activity"></i>
                            </div>
                        </div>
                        <p class="mt-2 text-2xl font-bold text-gray-900">${value}</p>
                    </div>
                `;
            });
            
            // Generate charts if selected
            if (document.getElementById('includeBarChart').checked) {
                createBarChart();
                document.getElementById('barChartContainer').classList.remove('hidden');
            } else {
                document.getElementById('barChartContainer').classList.add('hidden');
            }
            
            if (document.getElementById('includePieChart').checked) {
                createPieChart();
                document.getElementById('pieChartContainer').classList.remove('hidden');
            } else {
                document.getElementById('pieChartContainer').classList.add('hidden');
            }
            
            if (document.getElementById('includeLineChart').checked) {
                createLineChart();
                document.getElementById('lineChartContainer').classList.remove('hidden');
            } else {
                document.getElementById('lineChartContainer').classList.add('hidden');
            }
            
            document.getElementById('dashboardPreview').classList.remove('hidden');
            feather.replace();
        }
        
        function createBarChart() {
            // Simple implementation - in a real app you'd let user select columns
            const ctx = document.getElementById('barChart').getContext('2d');
            
            // Destroy previous chart if it exists
            if (window.barChart) window.barChart.destroy();
            
            // Find first numeric column for demo purposes
            let numericColumnIndex = -1;
            for (let i = 0; i < window.tableData.headers.length; i++) {
                if (typeof window.tableData.rows[0][i] === 'number' || !isNaN(window.tableData.rows[0][i])) {
                    numericColumnIndex = i;
                    break;
                }
            }
            
            if (numericColumnIndex === -1) return;
            
            const labels = window.tableData.rows.slice(0, 10).map(row => row[0]); // First column as labels
            const data = window.tableData.rows.slice(0, 10).map(row => parseFloat(row[numericColumnIndex]));
            
            window.barChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: labels,
                    datasets: [{
                        label: window.tableData.headers[numericColumnIndex],
                        data: data,
                        backgroundColor: 'rgba(59, 130, 246, 0.5)',
                        borderColor: 'rgba(59, 130, 246, 1)',
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });
        }
        
        function createPieChart() {
            const ctx = document.getElementById('pieChart').getContext('2d');
            
            if (window.pieChart) window.pieChart.destroy();
            
            // Group by first column for demo purposes
            const groups = {};
            window.tableData.rows.slice(0, 5).forEach(row => {
                const key = row[0];
                if (!groups[key]) groups[key] = 0;
                groups[key]++;
            });
            
            window.pieChart = new Chart(ctx, {
                type: 'pie',
                data: {
                    labels: Object.keys(groups),
                    datasets: [{
                        data: Object.values(groups),
                        backgroundColor: [
                            'rgba(255, 99, 132, 0.5)',
                            'rgba(54, 162, 235, 0.5)',
                            'rgba(255, 206, 86, 0.5)',
                            'rgba(75, 192, 192, 0.5)',
                            'rgba(153, 102, 255, 0.5)'
                        ],
                        borderColor: [
                            'rgba(255, 99, 132, 1)',
                            'rgba(54, 162, 235, 1)',
                            'rgba(255, 206, 86, 1)',
                            'rgba(75, 192, 192, 1)',
                            'rgba(153, 102, 255, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false
                }
            });
        }
        
        function createLineChart() {
            const ctx = document.getElementById('lineChart').getContext('2d');
            
            if (window.lineChart) window.lineChart.destroy();
            
            // Find first numeric column for demo purposes
            let numericColumnIndex = -1;
            for (let i = 0; i < window.tableData.headers.length; i++) {
                if (typeof window.tableData.rows[0][i] === 'number' || !isNaN(window.tableData.rows[0][i])) {
                    numericColumnIndex = i;
                    break;
                }
            }
            
            if (numericColumnIndex === -1) return;
            
            const labels = window.tableData.rows.slice(0, 10).map(row => row[0]); // First column as labels
            const data = window.tableData.rows.slice(0, 10).map(row => parseFloat(row[numericColumnIndex]));
            
            window.lineChart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: labels,
                    datasets: [{
                        label: window.tableData.headers[numericColumnIndex],
                        data: data,
                        fill: false,
                        backgroundColor: 'rgba(59, 130, 246, 0.5)',
                        borderColor: 'rgba(59, 130, 246, 1)',
                        tension: 0.1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });
        }
        
        function exportToWordPress() {
            // In a real implementation, this would generate the WordPress code
            alert('In a real implementation, this would generate WordPress PHP code and shortcodes that you can copy into your WordPress site.');
        }
    </script>
</body>
</html>