File size: 16,722 Bytes
f93e15c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
```html
<!DOCTYPE html>
<html lang="th" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>โภชนาการ - ชีพจร</title>
    <link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌿</text></svg>">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <link rel="stylesheet" href="style.css">
</head>
<body class="bg-gray-900 text-white font-sans pb-20">
    <!-- Main Container -->
    <div class="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900">
        <!-- Header -->
        <header class="px-4 pt-12 pb-6">
            <div class="flex items-center justify-between">
                <div>
                    <h1 class="text-2xl font-bold bg-gradient-to-r from-purple-400 to-pink-500 bg-clip-text text-transparent">
                        โภชนาการ
                    </h1>
                    <p class="text-gray-400 text-sm mt-1">ติดตามการรับประทานอาหารของคุณ 🍎</p>
                </div>
                <button onclick="window.location.href='index.html'" class="w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center">
                    <i data-feather="arrow-left" class="w-5 h-5"></i>
                </button>
            </div>
        </header>

        <!-- Daily Nutrition Overview -->
        <section class="px-4 mb-6">
            <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
                <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
                    <i data-feather="pie-chart" class="w-5 h-5 text-purple-400"></i>
                    ภาพรวมวันนี้
                </h3>
                
                <div class="grid grid-cols-3 gap-4 mb-4">
                    <div class="text-center">
                        <p class="text-2xl font-bold text-orange-400">1,847</p>
                        <p class="text-xs text-gray-400">แคลอรี</p>
                    </div>
                    <div class="text-center">
                        <p class="text-2xl font-bold text-blue-400">92g</p>
                        <p class="text-xs text-gray-400">โปรตีน</p>
                    </div>
                    <div class="text-center">
                        <p class="text-2xl font-bold text-green-400">35g</p>
                        <p class="text-xs text-gray-400">ใยอาหาร</p>
                    </div>
                </div>

                <div class="bg-gray-800/50 rounded-xl p-3">
                    <div class="flex justify-between text-sm mb-2">
                        <span>เป้าหมาย: 2,200 แคลอรี</span>
                        <span>73%</span>
                    </div>
                    <div class="bg-gray-700 rounded-full h-3">
                        <div class="bg-gradient-to-r from-purple-500 to-pink-600 h-3 rounded-full" style="width: 73%"></div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Macro Distribution -->
        <section class="px-4 mb-6">
            <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
                <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
                    <i data-feather="percent" class="w-5 h-5 text-yellow-400"></i>
                    สัดส่วนสารอาหาร
                </h3>
                <canvas id="macroChart" height="200"></canvas>
            </div>
        </section>

        <!-- Meal Timeline -->
        <section class="px-4 mb-6">
            <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
                <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
                    <i data-feather="clock" class="w-5 h-5 text-green-400"></i>
                    มื้ออาหารวันนี้
                </h3>
                
                <div class="space-y-4" id="mealTimeline">
                    <div class="flex gap-3">
                        <div class="flex-shrink-0 w-16 h-16 bg-gradient-to-r from-yellow-400 to-orange-500 rounded-xl flex items-center justify-center text-xl">
                            🌅
                        </div>
                        <div class="flex-1">
                            <div class="flex justify-between items-start mb-1">
                                <h4 class="font-medium">มื้อเช้า</h4>
                                <span class="text-sm text-gray-400">07:30</span>
                            </div>
                            <p class="text-sm text-gray-300 mb-1">ข้าวต้มหมู + ไข่ลวก</p>
                            <p class="text-xs text-orange-400">580 แคลอรี</p>
                        </div>
                    </div>
                    
                    <div class="flex gap-3">
                        <div class="flex-shrink-0 w-16 h-16 bg-gradient-to-r from-red-500 to-pink-600 rounded-xl flex items-center justify-center text-xl">
                            ☀️
                        </div>
                        <div class="flex-1">
                            <div class="flex justify-between items-start mb-1">
                                <h4 class="font-medium">มื้อเที่ยง</h4>
                                <span class="text-sm text-gray-400">12:15</span>
                            </div>
                            <p class="text-sm text-gray-300 mb-1">ส้มตำไทย + ไก่ย่าง</p>
                            <p class="text-xs text-orange-400">450 แคลอรี</p>
                        </div>
                    </div>
                    
                    <div class="flex gap-3">
                        <div class="flex-shrink-0 w-16 h-16 bg-gradient-to-r from-blue-500 to-indigo-600 rounded-xl flex items-center justify-center text-xl">
                        🌙
                        </div>
                    <div class="flex-1">
                        <div class="flex justify-between items-start mb-1">
                            <h4 class="font-medium">มื้อเย็น</h4>
                            <span class="text-sm text-gray-400">18:30</span>
                        </div>
                        <p class="text-sm text-gray-300 mb-1">ยังไม่บันทึก</p>
                        <button class="text-xs text-blue-400 hover:underline">+ เพิ่มมื้อเย็น</button>
                    </div>
                </div>
            </div>
        </section>

        <!-- Enhanced Meal Logger -->
        <meal-logger-enhanced></meal-logger-enhanced>

        <!-- Water Intake -->
        <section class="px-4 mb-6">
            <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
                <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
                    <i data-feather="droplet" class="w-5 h-5 text-cyan-400"></i>
                    การดื่มน้ำ
                </h3>
                
                <div class="flex items-center justify-between mb-4">
                    <div class="text-center">
                        <p class="text-2xl font-bold text-cyan-400">1.8L</p>
                        <p class="text-xs text-gray-400">ดื่มไปแล้ว</p>
                    </div>
                    <div class="text-center">
                        <p class="text-2xl font-bold text-gray-400">2.5L</p>
                        <p class="text-xs text-gray-400">เป้าหมาย</p>
                    </div>
                </div>
                
                <div class="grid grid-cols-4 gap-2 mb-4">
                    <div class="aspect-square bg-cyan-500 rounded-lg flex items-center justify-center">
                        <i data-feather="check" class="w-4 h-4 text-white"></i>
                    </div>
                    <div class="aspect-square bg-cyan-500 rounded-lg flex items-center justify-center">
                        <i data-feather="check" class="w-4 h-4 text-white"></i>
                    </div>
                    <div class="aspect-square bg-cyan-500 rounded-lg flex items-center justify-center">
                        <i data-feather="check" class="w-4 h-4 text-white"></i>
                    </div>
                    <div class="aspect-square bg-gray-700 rounded-lg flex items-center justify-center">
                        <span class="text-xs text-gray-400">4</span>
                    </div>
                </div>
                
                <button class="w-full bg-gradient-to-r from-cyan-500 to-blue-600 py-2 rounded-lg text-sm font-medium" onclick="logWater()">
                    <i data-feather="plus" class="w-4 h-4 inline mr-1"></i>
                    เพิ่มแก้วน้ำ (250ml)
                </button>
            </div>
        </section>

        <!-- Nutrition Insights -->
        <section class="px-4 mb-6">
            <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
                <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
                    <i data-feather="info" class="w-5 h-5 text-yellow-400"></i>
                    คำแนะนำโภชนาการ
                </h3>
                
                <div class="space-y-3">
                    <div class="p-3 bg-green-500/10 border border-green-500/30 rounded-xl">
                        <div class="flex items-center gap-3">
                            <div class="w-8 h-8 bg-green-500 rounded-lg flex items-center justify-center">
                                <i data-feather="check-circle" class="w-4 h-4 text-white"></i>
                            </div>
                            <div class="flex-1">
                                <p class="text-sm font-medium">โปรตีนเพียงพอ</p>
                                <p class="text-xs text-gray-400">คุณได้รับโปรตีนครบตามเป้าหมายแล้ว</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="p-3 bg-orange-500/10 border border-orange-500/30 rounded-xl">
                        <div class="flex items-center gap-3">
                            <div class="w-8 h-8 bg-orange-500 rounded-lg flex items-center justify-center">
                                <i data-feather="alert-circle" class="w-4 h-4 text-white"></i>
                            </div>
                            <div class="flex-1">
                                <p class="text-sm font-medium">ใยอาหารต่ำ</p>
                                <p class="text-xs text-gray-400">ควรทานผักเพิ่มขึ้นอีก 15g</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Bottom Navigation -->
    <main-navbar></main-navbar>

    <!-- Scripts -->
    <script src="components/navbar.js"></script>
    <script src="components/meal-logger-enhanced.js"></script>
    <script src="script.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Set active page in navbar
            const navbar = document.querySelector('main-navbar');
            if (navbar) {
                navbar.setActivePage('nutrition');
            }

            // Macro distribution chart
            const ctx = document.getElementById('macroChart');
            if (ctx) {
                new Chart(ctx, {
                    type: 'doughnut',
                    data: {
                        labels: ['คาร์โบไฮเดรต', 'โปรตีน', 'ไขมัน', 'ใยอาหาร'],
                        datasets: [{
                            data: [45, 25, 25, 5],
                            backgroundColor: [
                                '#f59e0b',
                                '#3b82f6',
                                '#10b981',
                                '#8b5cf6'
                            ],
                            borderWidth: 0
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                position: 'bottom',
                                labels: {
                                    padding: 15,
                                    font: { size: 12, family: 'Prompt' },
                                    color: '#e5e7eb'
                                }
                            }
                        }
                    }
                });
            }

            // Load meals from localStorage
            loadMealsFromStorage();
        });

        function logWater() {
            const waterGrid = document.querySelector('.grid.grid-cols-4');
            const emptyGlass = waterGrid.querySelector('.bg-gray-700');
            
            if (emptyGlass) {
                emptyGlass.className = 'aspect-square bg-cyan-500 rounded-lg flex items-center justify-center';
                emptyGlass.innerHTML = '<i data-feather="check" class="w-4 h-4 text-white"></i>';
                feather.replace();
                
                showNotification('บันทึกการดื่มน้ำ 250ml สำเร็จ!', 'success');
                
                // Update total
                const currentText = document.querySelector('.text-2xl.font-bold.text-cyan-400').textContent;
                const current = parseFloat(currentText);
                document.querySelector('.text-2xl.font-bold.text-cyan-400').textContent = (current + 0.25).toFixed(1) + 'L';
            } else {
                showNotification('คุณดื่มน้ำครบเป้าหมายแล้ววันนี้! 🎉', 'success');
            }
        }

        function loadMealsFromStorage() {
            const meals = JSON.parse(localStorage.getItem('todayMeals') || '[]');
            const timeline = document.getElementById('mealTimeline');
            
            // Update timeline with saved meals
            if (meals.length > 0) {
                // Clear existing meals except the "dinner" placeholder
                const existingMeals = timeline.querySelectorAll('.flex.gap-3:not(:last-child)');
                existingMeals.forEach(meal => meal.remove());
                
                // Add saved meals
                meals.forEach((meal, index) => {
                    const mealElement = document.createElement('div');
                    mealElement.className = 'flex gap-3';
                    mealElement.innerHTML = `
                        <div class="flex-shrink-0 w-16 h-16 bg-gradient-to-r from-orange-500 to-red-600 rounded-xl flex items-center justify-center text-xl">
                            ${meal.mealType === 'เช้า' ? '🌅' : meal.mealType === 'เที่ยง' ? '☀️' : '🌙'}
                        </div>
                        <div class="flex-1">
                            <div class="flex justify-between items-start mb-1">
                                <h4 class="font-medium">มื้อ${meal.mealType}</h4>
                                <span class="text-sm text-gray-400">${new Date(meal.timestamp).toLocaleTimeString('th-TH', { hour: '2-digit', minute: '2-digit' })}</span>
                            </div>
                            <p class="text-sm text-gray-300 mb-1">${meal.name}</p>
                            <p class="text-xs text-orange-400">${meal.calories} แคลอรี</p>
                        </div>
                    `;
                    timeline.insertBefore(mealElement, timeline.firstChild);
                });
            }
        }
    </script>
    <script>feather.replace();</script>
</body>
</html>
>>>>>>> REPLACE