CSNET commited on
Commit
4a7cb62
·
verified ·
1 Parent(s): 4212c95

**Project Name:** ชีพจร (Pulse) - The Ultimate Thai Health & Recovery Platform

Browse files

Display only in thai language
**Core Objective:**
พัฒนา Mobile Application (iOS & Android) และระบบหลังบ้าน สำหรับติดตามสุขภาพ การฟื้นตัว และสมรรถภาพร่างกาย ที่ออกแบบมาเพื่อคนไทยโดยเฉพาะ โดยมีเป้าหมายเพื่อเป็นผู้นำตลาดแทนที่ WHOOP ในประเทศไทย

**Key Differentiators (จุดขายหลัก):**
1. **Hyper-localization:** Database อาหารไทย, กิจกรรมยอดนิยมของไทย, และภาษาที่เข้าใจง่าย
2. **Actionable AI Coach:** AI ที่ให้คำแนะนำเชิงปฏิบัติ ไม่ใช่แค่แสดงข้อมูล
3. **Holistic Tracking:** เชื่อมโยง Strain, Sleep, Recovery เข้ากับ Nutrition และ Mental Health

---

### **Module 1: User Onboarding & Profile**
* **Function 1.1: Authentication:** สมัครสมาชิกผ่าน Email, Google, Facebook, Apple ID
* **Function 1.2: Profile Setup:**
* ข้อมูลพื้นฐาน (ชื่อ, เพศ, วันเกิด, ส่วนสูง, น้ำหนัก)
* เป้าหมายหลัก (Goal Setting): ลดน้ำหนัก, สร้างกล้ามเนื้อ, นอนดีขึ้น, ลดความเครียด, เพิ่ม Performance
* ประวัติสุขภาพเบื้องต้น (Health Baseline): โรคประจำตัว, การสูบบุหรี่/ดื่มแอลกอฮอล์
* **Function 1.3: Hardware Pairing:**
* หน้าจอค้นหาและเชื่อมต่อ Bluetooth กับ Hardware (Smartwatch, Smart Ring, หรือ Chest Strap ที่รองรับ)
* Tutorial การสวมใส่ที่ถูกต้อง
* **Function 1.4: Permission Request:** ขอสิทธิ์เข้าถึง HealthKit (iOS) / Health Connect (Android), Location, Camera, Notifications

---

### **Module 2: Dashboard (หน้าหลัก "วันนี้")**
* **Function 2.1: Main Vitals (วงกลม 3 วงหลัก):**
* **Recovery (การฟื้นตัว):** แสดงผลเป็น % (คำนวณจาก HRV, RHR, Sleep Quality) พร้อมแถบสี (แดง/เหลือง/เขียว)
* **Strain (ความเครียด/ภาระ):** แสดงผลเป็นคะแนน (0-21) คำนวณจาก Heart Rate ตลอดทั้งวันและระหว่างออกกำลังกาย
* **Sleep (การนอนหลับ):** แสดงผลเป็น % Performance (เทียบกับ "Sleep Need" ที่ระบบคำนวณ)
* **Function 2.2: AI Coach Summary:** การ์ดสรุปสั้นๆ จาก AI Coach ประจำวัน (เช่น "วันนี้คุณฟื้นตัวเต็มที่! เหมาะจะออกกำลังกายหนัก")
* **Function 2.3: Quick-Log Buttons:** ปุ่มลัดสำหรับ "บันทึกอาหาร", "เริ่มออกกำลังกาย", "บันทึกอารมณ์"
* **Function 2.4: Today's Data:**
* กราฟ Heart Rate ตลอดวัน (Real-time)
* แคลอรีที่เผาผลาญ (Total & Active)
* จำนวนก้าว

---

### **Module 3: Sleep Tracking (การนอนหลับ)**
* **Function 3.1: Automatic Detection:** ตรวจจับการนอนหลับและตื่นนอนอัตโนมัติ (ไม่ต้องกดเริ่ม/หยุด)
* **Function 3.2: Sleep Stages:** กราฟแบ่งระยะการนอน (Awake, Light, Deep, REM) พร้อม % และเวลารวม
* **Function 3.3: Sleep Metrics:**
* Sleep Efficiency (ประสิทธิภาพการนอน)
* Latency (ใช้เวลาล้มตัวลงนอนนานเท่าไหร่)
* Disturbances (การตื่นกลางดึก)
* Respiratory Rate (อัตราการหายใจ)
* **Function 3.4: Sleep Need Calculator:** ระบบคำนวณ "หนี้การนอน" (Sleep Debt) และแนะนำว่าคืนนี้ควรนอนกี่ชั่วโมง
* **Function 3.5: Smart Alarm:** ตั้งนาฬิกาปลุกอัจฉริยะ (ปลุกในช่วง Light Sleep ภายใน 30 นาทีก่อนเวลาที่ตั้งไว้)

---

### **Module 4: Strain & Activity (การออกกำลังกาย)**
* **Function 4.1: Activity Detection:** ตรวจจับกิจกรรมอัตโนมัติ (เช่น การเดิน, วิ่ง)
* **Function 4.2: Manual Activity Logging:**
* หน้าจอเลือกประเภทกิจกรรม (มี List กีฬาไทย: **มวยไทย, แบดมินตัน, ตะกร้อ, วิ่งสวนลุม, ปั่นจักรยาน, ว่ายน้ำ, โยคะ, เวทเทรนนิ่ง**)
* หน้าจอ Tracking ระหว่างออกกำลังกาย (แสดง HR Zone, เวลา, แคลอรี)
* หน้าจอสรุปผลหลังจบ (Strain Score, HR-Max, HR-Avg, กราฟ HR)
* **Function 4.3: Daily Strain Score:** คะแนนภาระรวมของวัน (0-21)
* **Function 4.4: Strain Coach:** AI แนะนำระดับ Strain ที่เหมาะสมสำหรับวันนี้ (อิงตามค่า Recovery)

---

### **Module 5: Recovery & Readiness (การฟื้นตัว)**
* **Function 5.1: Daily Recovery Score:** แสดงผล % (คำนวณตอนตื่นนอน)
* **Function 5.2: Key Recovery Metrics:**
* **HRV (Heart Rate Variability):** ตัวเลข ms และกราฟแนวโน้ม
* **RHR (Resting Heart Rate):** ตัวเลข bpm และกราฟแนวโน้ม
* **Skin Temperature:** (ถ้า Hardware รองรับ)
* **Function 5.3: Recovery Insights:** อธิบายว่าทำไมวันนี้ Recovery ถึงสูง/ต่ำ (เช่น "ผลจากการดื่มแอลกอฮอล์เมื่อคืน", "การนอนหลับที่มีคุณภาพ")

---

### **Module 6: Nutrition Log (บันทึกโภชนาการ) - [!! KILLER FEATURE !!]**
* **Function 6.1: Thai Food Database:**
* Database อาหารไทย (อาหารตามสั่ง, อาหารจานเดียว, แกง, ขนม, เครื่องดื่ม) พร้อม Macro-nutrients (Carbs, Fat, Protein) และแคลอรี
* รองรับการค้นหาด้วยชื่อไทย (เช่น "ข้าวมันไก่", "ผัดซีอิ๊ว", "ชานม")
* **Function 6.2: AI Food Photo Logging:**
* ใช้กล้องถ่ายรูปอาหาร (เช่น ถ่ายรูป "กะเพราไก่ไข่ดาว")
* AI ทำการ Identify อาหารและปริมาณโดยประมาณ (e.g., "ข้าวราดกะเพราไก่ 1 จาน + ไข่ดาว 1 ฟอง")
* User ยืนยันและบันทึก
* **Function 6.3: Barcode Scanner:** สแกนบาร์โค้ดสินค้าในซูเปอร์มาร์เก็ต/ร้านสะดวกซื้อ
* **Function 6.4: Manual Entry & Custom Meals:** กรอกเอง หรือสร้างเมนู "ประจำ" ของตัวเอง
* **Function 6.5: Nutrition Summary:** สรุปแคลอรีรวม, Macro-split, และน้ำตาล ประจำวัน/สัปดาห์
* **Function 6.6: Water & Caffeine Tracking:** ปุ่มกดบันทึกน้ำเปล่า และ กาแฟ/ชา

---

### **Module 7: Mental Wellness & Office Syndrome**
* **Function 7.1: Mood Log:** "วันนี้คุณรู้สึกอย่างไร?" (เลือก Emoji + บันทึกสั้นๆ)
* **Function 7.2: Guided Meditation:**
* คลังเสียงนำนั่งสมาธิ/ฝึกหายใจ (ภาษาไทย)
* แบ่งตามเป้าหมาย (ลดเครียด, ก่อนนอน, เพิ่มสมาธิ)
* **Function 7.3: Sedentary Alert (Office Syndrome Alert):**
* แจ้งเตือนเมื่อ User นั่งนิ่งนานเกิน 1 ชั่วโมง
* แสดง Pop-up พร้อมวิดีโอท่ากายบริหารสั้นๆ (Micro-workout 1-3 นาที) สำหรับยืดเหยียดคอ บ่า ไหล่

---

### **Module 8: AI Coach & Insights ("ผู้ช่วยชีพจร")**
* **Function 8.1: Daily Report:** สรุปรายงานสุขภาพรายวัน (ตอนเช้า) และรายสัปดาห์ (วันอาทิตย์)
* **Function 8.2: Actionable Insights:**
* วิเคราะห์ความสัมพันธ์ (Correlation) เช่น "เราพบว่าวันที่คุณดื่มกาแฟหลังบ่าย 3 จะทำให้ค่า D

README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Pulse Whoop
3
- emoji: ⚡
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: ชีพจร Pulse แอปไทยฟิตสู้ WHOOP 💪
3
+ colorFrom: green
4
+ colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
components/ai-coach-card.js ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class AICoachCard extends HTMLElement {
2
+ constructor() {
3
+ super();
4
+ this.defaultMessage = "วันนี้คุณฟื้นตัวเต็มที่! เหมาะสำหรับการออกกำลังกายระดับกลาง-หนัก อย่าลืมทานอาหารให้ครบ 5 หมู่นะคะ";
5
+ this.currentMessage = this.defaultMessage;
6
+ }
7
+
8
+ connectedCallback() {
9
+ this.attachShadow({ mode: 'open' });
10
+ this.render();
11
+ this.startTypingAnimation();
12
+ }
13
+
14
+ render() {
15
+ this.shadowRoot.innerHTML = `
16
+ <style>
17
+ :host {
18
+ display: block;
19
+ margin: 0 1rem 1.5rem;
20
+ }
21
+
22
+ .coach-card {
23
+ background: linear-gradient(135deg, rgba(52, 211, 153, 0.15), rgba(16, 185, 129, 0.1));
24
+ border: 1px solid rgba(52, 211, 153, 0.3);
25
+ border-radius: 1.25rem;
26
+ padding: 1.25rem;
27
+ position: relative;
28
+ overflow: hidden;
29
+ backdrop-filter: blur(10px);
30
+ -webkit-backdrop-filter: blur(10px);
31
+ }
32
+
33
+ .coach-avatar {
34
+ position: absolute;
35
+ top: -10px;
36
+ right: -10px;
37
+ width: 60px;
38
+ height: 60px;
39
+ background: linear-gradient(135deg, #34d399, #10b981);
40
+ border-radius: 50%;
41
+ display: flex;
42
+ align-items: center;
43
+ justify-content: center;
44
+ box-shadow: 0 4px 15px rgba(52, 211, 153, 0.3);
45
+ }
46
+
47
+ .coach-icon {
48
+ width: 30px;
49
+ height: 30px;
50
+ color: white;
51
+ }
52
+
53
+ .coach-header {
54
+ display: flex;
55
+ align-items: center;
56
+ gap: 0.75rem;
57
+ margin-bottom: 0.75rem;
58
+ }
59
+
60
+ .coach-title {
61
+ font-size: 0.9rem;
62
+ font-weight: 600;
63
+ color: #34d399;
64
+ font-family: 'Prompt', sans-serif;
65
+ }
66
+
67
+ .coach-badge {
68
+ background: rgba(52, 211, 153, 0.2);
69
+ color: #34d399;
70
+ padding: 0.25rem 0.75rem;
71
+ border-radius: 9999px;
72
+ font-size: 0.7rem;
73
+ font-weight: 500;
74
+ }
75
+
76
+ .coach-message {
77
+ font-size: 0.85rem;
78
+ line-height: 1.5;
79
+ color: #e5e7eb;
80
+ margin-bottom: 0.75rem;
81
+ font-family: 'Prompt', sans-serif;
82
+ min-height: 2.5rem;
83
+ }
84
+
85
+ .coach-message.typing {
86
+ border-right: 2px solid #34d399;
87
+ animation: typing 3s steps(40, end), blink-caret 0.75s step-end infinite;
88
+ }
89
+
90
+ @keyframes typing {
91
+ from { width: 0 }
92
+ to { width: 100% }
93
+ }
94
+
95
+ @keyframes blink-caret {
96
+ from, to { border-color: transparent }
97
+ 50% { border-color: #34d399 }
98
+ }
99
+
100
+ .coach-actions {
101
+ display: flex;
102
+ gap: 0.75rem;
103
+ }
104
+
105
+ .coach-btn {
106
+ background: rgba(52, 211, 153, 0.1);
107
+ border: 1px solid rgba(52, 211, 153, 0.3);
108
+ color: #34d399;
109
+ padding: 0.5rem 1rem;
110
+ border-radius: 0.75rem;
111
+ font-size: 0.75rem;
112
+ font-weight: 500;
113
+ cursor: pointer;
114
+ transition: all 0.3s ease;
115
+ text-decoration: none;
116
+ display: inline-flex;
117
+ align-items: center;
118
+ gap: 0.5rem;
119
+ font-family: 'Prompt', sans-serif;
120
+ }
121
+
122
+ .coach-btn:hover {
123
+ background: rgba(52, 211, 153, 0.2);
124
+ transform: translateY(-2px);
125
+ }
126
+
127
+ .pulse-ring {
128
+ position: absolute;
129
+ top: 0;
130
+ left: 0;
131
+ right: 0;
132
+ bottom: 0;
133
+ border-radius: 1.25rem;
134
+ border: 2px solid transparent;
135
+ animation: pulse-ring 2s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
136
+ }
137
+
138
+ @keyframes pulse-ring {
139
+ 0% {
140
+ transform: scale(0.9);
141
+ border-color: rgba(52, 211, 153, 0.6);
142
+ }
143
+ 100% {
144
+ transform: scale(1.05);
145
+ border-color: transparent;
146
+ }
147
+ }
148
+
149
+ .typing-dots {
150
+ display: inline-flex;
151
+ gap: 0.2rem;
152
+ }
153
+
154
+ .typing-dot {
155
+ width: 4px;
156
+ height: 4px;
157
+ background: #34d399;
158
+ border-radius:
components/hardware-status.js ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class HardwareStatus extends HTMLElement {
2
+ constructor() {
3
+ super();
4
+ this.attachShadow({ mode: 'open' });
5
+ this.devices = [
6
+ { name: 'Apple Watch Series 9', icon: 'watch', connected: true, battery: 85 },
7
+ { name: 'Oura Ring Gen 3', icon: 'circle', connected: false, battery: 0 },
8
+ { name: 'Polar H10', icon: 'heart', connected: true, battery: 62 }
9
+ ];
10
+ }
11
+
12
+ connectedCallback() {
13
+ this.render();
14
+ this.simulateDeviceUpdates();
15
+ }
16
+
17
+ render() {
18
+ this.shadowRoot.innerHTML = `
19
+ <style>
20
+ :host {
21
+ display: block;
22
+ margin: 0 1rem 1rem;
23
+ }
24
+
25
+ .hardware-container {
26
+ background: rgba(31, 41, 55, 0.4);
27
+ backdrop-filter: blur(10px);
28
+ border: 1px solid rgba(75, 85, 99, 0.3);
29
+ border-radius: 1rem;
30
+ padding: 1rem;
31
+ position: relative;
32
+ overflow: hidden;
33
+ }
34
+
35
+ .hardware-header {
36
+ display: flex;
37
+ align-items: center;
38
+ justify-content: space-between;
39
+ margin-bottom: 0.75rem;
40
+ }
41
+
42
+ .hardware-title {
43
+ font-size: 0.85rem;
44
+ font-weight: 600;
45
+ color: #e5e7eb;
46
+ display: flex;
47
+ align-items: center;
48
+ gap: 0.5rem;
49
+ }
50
+
51
+ .hardware-status {
52
+ font-size: 0.7rem;
53
+ padding: 0.25rem 0.5rem;
54
+ border-radius: 9999px;
55
+ font-weight: 500;
56
+ }
57
+
58
+ .status-connected {
59
+ background: rgba(52, 211, 153, 0.2);
60
+ color: #34d399;
61
+ }
62
+
63
+ .status-disconnected {
64
+ background: rgba(239, 68, 68, 0.2);
65
+ color: #ef4444;
66
+ }
67
+
68
+ .device-list {
69
+ display: flex;
70
+ flex-direction: column;
71
+ gap: 0.5rem;
72
+ }
73
+
74
+ .device-item {
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: space-between;
78
+ padding: 0.5rem;
79
+ background: rgba(17, 24, 39, 0.3);
80
+ border-radius: 0.75rem;
81
+ transition: all 0.3s ease;
82
+ }
83
+
84
+ .device-item:hover {
85
+ background: rgba(31, 41, 55, 0.6);
86
+ }
87
+
88
+ .device-info {
89
+ display: flex;
90
+ align-items: center;
91
+ gap: 0.75rem;
92
+ }
93
+
94
+ .device-icon {
95
+ width: 32px;
96
+ height: 32px;
97
+ border-radius: 0.5rem;
98
+ background: linear-gradient(135deg, #374151, #4b5563);
99
+ display: flex;
100
+ align-items: center;
101
+ justify-content: center;
102
+ color: #9ca3af;
103
+ }
104
+
105
+ .device-icon.connected {
106
+ background: linear-gradient(135deg, #34d399, #10b981);
107
+ color: white;
108
+ }
109
+
110
+ .device-details {
111
+ display: flex;
112
+ flex-direction: column;
113
+ }
114
+
115
+ .device-name {
116
+ font-size: 0.8rem;
117
+ font-weight: 500;
118
+ color: #e5e7eb;
119
+ }
120
+
121
+ .device-meta {
122
+ font-size: 0.65rem;
123
+ color: #9ca3af;
124
+ }
125
+
126
+ .device-actions {
127
+ display: flex;
128
+ gap: 0.5rem;
129
+ align-items: center;
130
+ }
131
+
132
+ .battery-indicator {
133
+ display: flex;
134
+ align-items: center;
135
+ gap: 0.25rem;
136
+ font-size: 0.65rem;
137
+ color: #9ca3af;
138
+ }
139
+
140
+ .battery-bar {
141
+ width: 20px;
142
+ height: 8px;
143
+ border: 1px solid #4b5563;
144
+ border-radius: 2px;
145
+ position: relative;
146
+ overflow: hidden;
147
+ }
148
+
149
+ .battery-fill {
150
+ height: 100%;
151
+ background: #34d399;
152
+ transition: width 0.3s ease;
153
+ }
154
+
155
+ .battery-fill.low {
156
+ background: #f87171;
157
+ }
158
+
159
+ .connect-btn {
160
+ padding: 0.25rem 0.5rem;
161
+ border: 1px solid #34d399;
162
+ background: transparent;
163
+ color: #34d399;
164
+ border-radius: 0.25rem;
165
+ font-size: 0.65rem;
166
+ cursor: pointer;
167
+ transition: all 0.3s ease;
168
+ }
169
+
170
+ .connect-btn:hover {
171
+ background: rgba(52, 211, 153, 0.1);
172
+ }
173
+
174
+ .pulse-animation {
175
+ animation: pulse 2s infinite;
176
+ }
177
+
178
+ @keyframes pulse {
179
+ 0% { opacity: 1; }
180
+ 50% { opacity: 0.5; }
181
+ 100% { opacity: 1; }
182
+ }
183
+
184
+ .add-device-btn {
185
+ width: 100%;
186
+ padding: 0.5rem;
187
+ margin-top: 0.5rem;
188
+ background: rgba(52, 211, 153, 0.1);
189
+ border: 1px dashed rgba(52, 211, 153, 0.5);
190
+ border-radius: 0.75rem;
191
+ color: #34d399;
192
+ font-size: 0.75rem;
193
+ font-weight: 500;
194
+ cursor: pointer;
195
+ transition: all 0.3s ease;
196
+ }
197
+
198
+ .add-device-btn:hover {
199
+ background: rgba(52, 211, 153, 0.2);
200
+ }
201
+ </style>
202
+
203
+ <div class="hardware-container">
204
+ <div class="hardware-header">
205
+ <div class="hardware-title">
206
+ <i data-feather="bluetooth" class="w-4 h-4"></i>
207
+ อุปกรณ์ที่เชื่อมต่อ
208
+ </div>
209
+ <div class="hardware-status status-connected">
210
+ ${this.devices.filter(d => d.connected).length}/${this.devices.length} เชื่อมต่อ
211
+ </div>
212
+ </div>
213
+
214
+ <div class="device-list" id="deviceList">
215
+ ${this.devices.map(device => this.renderDevice(device)).join('')}
216
+ </div>
217
+
218
+ <button class="add-device-btn" id="addDeviceBtn">
219
+ <i data-feather="plus" class="w-4 h-4 inline mr-1"></i>
220
+ เพิ่มอุปกรณ์ใหม่
221
+ </button>
222
+ </div>
223
+ `;
224
+
225
+ // Replace feather icons
226
+ if (typeof feather !== 'undefined') {
227
+ feather.replace({ root: this.shadowRoot });
228
+ }
229
+
230
+ this.setupEventListeners();
231
+ }
232
+
233
+ renderDevice(device) {
234
+ const icon = device.connected ? 'check' : 'x';
235
+ const statusClass = device.connected ? 'connected' : 'disconnected';
236
+ const batteryClass = device.battery < 20 ? 'low' : '';
237
+
238
+ return `
239
+ <div class="device-item" data-name="${device.name}">
240
+ <div class="device-info">
241
+ <div class="device-icon ${statusClass}">
242
+ <i data-feather="${device.icon}" class="w-4 h-4"></i>
243
+ </div>
244
+ <div class="device-details">
245
+ <div class="device-name">${device.name}</div>
246
+ <div class="device-meta">
247
+ ${device.connected ? 'เชื่อมต่อแล้ว' : 'ยังไม่ได้เชื่อมต่อ'} •
248
+ ${device.battery > 0 ? `แบตเตอรี่ ${device.battery}%` : 'ไม่พบแบตเตอรี่'}
249
+ </div>
250
+ </div>
251
+ </div>
252
+ <div class="device-actions">
253
+ ${device.connected && device.battery > 0 ? `
254
+ <div class="battery-indicator">
255
+ <div class="battery-bar">
256
+ <div class="battery-fill ${batteryClass}" style="width: ${device.battery}%"></div>
257
+ </div>
258
+ <span>${device.battery}%</span>
259
+ </div>
260
+ ` : ''}
261
+ ${!device.connected ? `
262
+ <button class="connect-btn" data-device="${device.name}">
263
+ เชื่อมต่อ
264
+ </button>
265
+ ` : `
266
+ <div class="pulse-animation">
267
+ <i data-feather="activity" class="w-4 h-4 text-green-400"></i>
268
+ </div>
269
+ `}
270
+ </div>
271
+ </div>
272
+ `;
273
+ }
274
+
275
+ setupEventListeners() {
276
+ const connectButtons = this.shadowRoot.querySelectorAll('.connect-btn');
277
+ connectButtons.forEach(btn => {
278
+ btn.addEventListener('click', (e) => {
279
+ const deviceName = e.target.dataset.device;
280
+ this.connectDevice(deviceName);
281
+ });
282
+ });
283
+
284
+ const addDeviceBtn = this.shadowRoot.getElementById('addDeviceBtn');
285
+ addDeviceBtn.addEventListener('click', () => {
286
+ this.showAddDeviceModal();
287
+ });
288
+ }
289
+
290
+ connectDevice(deviceName) {
291
+ const device = this.devices.find(d => d.name === deviceName);
292
+ if (device) {
293
+ this.showNotification(`กำลังเชื่อมต่อ ${deviceName}...`, 'info');
294
+
295
+ // Simulate connection process
296
+ setTimeout(() => {
297
+ device.connected = true;
298
+ device.battery = Math.floor(Math.random() * 50) + 50;
299
+ this.render();
300
+ this.showNotification(`เชื่อมต่อ ${deviceName} สำเร็จ!`, 'success');
301
+ }, 2000);
302
+ }
303
+ }
304
+
305
+ showAddDeviceModal() {
306
+ // Create modal
307
+ const modal = document.createElement('div');
308
+ modal.className = 'fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4';
309
+ modal.innerHTML = `
310
+ <div class="glass-card rounded-2xl p-6 max-w-sm w-full border border-gray-700/50">
311
+ <h3 class="text-xl font-bold mb-4">ค้นหาอุปกรณ์</h3>
312
+ <div class="space-y-3 mb-4" id="deviceSearchResults">
313
+ <div class="flex items-center justify-center py-8">
314
+ <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-green-400"></div>
315
+ </div>
316
+ </div>
317
+ <button onclick="this.closest('.fixed').remove()" class="w-full bg-gray-700 hover:bg-gray-600 py-3 rounded-xl font-medium transition-colors">
318
+ ปิด
319
+ </button>
320
+ </div>
321
+ `;
322
+
323
+ document.body.appendChild(modal);
324
+
325
+ // Simulate device search
326
+ setTimeout(() => {
327
+ const results = document.getElementById('deviceSearchResults');
328
+ results.innerHTML = `
329
+ <div class="space-y-2">
330
+ <div class="p-3 bg-gray-800/50 rounded-lg cursor-pointer hover:bg-gray-700/50 transition-colors" onclick="alert('กำลังเชื่อมต่อ Garmin Fenix 7...')">
331
+ <div class="flex items-center gap-3">
332
+ <i data-feather="watch" class="w-5 h-5 text-green-400"></i>
333
+ <div>
334
+ <div class="font-medium">Garmin Fenix 7</div>
335
+ <div class="text-sm text-gray-400">สัญญาณแรง</div>
336
+ </div>
337
+ </div>
338
+ </div>
339
+ <div class="p-3 bg-gray-800/50 rounded-lg cursor-pointer hover:bg-gray-700/50 transition-colors" onclick="alert('กำลังเชื่อมต่อ Fitbit Sense...')">
340
+ <div class="flex items-center gap-3">
341
+ <i data-feather="watch" class="w-5 h-5 text-blue-400"></i>
342
+ <div>
343
+ <div class="font-medium">Fitbit Sense</div>
344
+ <div class="text-sm text-gray-400">สัญญาณปานกลาง</div>
345
+ </div>
346
+ </div>
347
+ </div>
348
+ </div>
349
+ `;
350
+ feather.replace({ root: results });
351
+ }, 1500);
352
+ }
353
+
354
+ simulateDeviceUpdates() {
355
+ // Simulate real-time battery updates
356
+ setInterval(() => {
357
+ this.devices.forEach(device => {
358
+ if (device.connected && device.battery > 0) {
359
+ // Randomly decrease battery by 0-3%
360
+ device.battery = Math.max(0, device.battery - Math.floor(Math.random() * 3));
361
+ }
362
+ });
363
+ this.render();
364
+ }, 30000); // Update every 30 seconds
365
+ }
366
+
367
+ showNotification(message, type = 'info') {
368
+ if (window.showNotification) {
369
+ window.showNotification(message, type);
370
+ } else {
371
+ alert(message);
372
+ }
373
+ }
374
+ }
375
+
376
+ customElements.define('hardware-status', HardwareStatus);
components/meal-logger-enhanced.js ADDED
@@ -0,0 +1,551 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class MealLoggerEnhanced extends HTMLElement {
2
+ constructor() {
3
+ super();
4
+ this.attachShadow({ mode: 'open' });
5
+
6
+ // Thai food database
7
+ this.thaiFoodDatabase = [
8
+ { name: 'ข้าวมันไก่', calories: 580, protein: 25, carbs: 65, fat: 20, image: 'http://static.photos/food/200x200/567' },
9
+ { name: 'ส้มตำไทย + ไก่ย่าง', calories: 450, protein: 30, carbs: 35, fat: 18, image: 'http://static.photos/food/200x200/789' },
10
+ { name: 'กะเพราไก่ไข่ดาว', calories: 520, protein: 28, carbs: 45, fat: 25, image: 'http://static.photos/food/200x200/133' },
11
+ { name: 'ข้าวขาหมู', calories: 620, protein: 35, carbs: 55, fat: 28, image: 'http://static.photos/food/200x200/234' },
12
+ { name: 'บะหมี่เกี๊ยว', calories: 480, protein: 22, carbs: 58, fat: 16, image: 'http://static.photos/food/200x200/345' },
13
+ { name: 'มาม่าต้มยำกุ้ง', calories: 320, protein: 12, carbs: 42, fat: 10, image: 'http://static.photos/food/200x200/456' },
14
+ { name: 'ข้าวผัดกระเพรากุ้ง', calories: 580, protein: 25, carbs: 65, fat: 22, image: 'http://static.photos/food/200x200/567' },
15
+ { name: 'สุกี้แห้งหมู', calories: 520, protein: 20, carbs: 68, fat: 18, image: 'http://static.photos/food/200x200/678' },
16
+ { name: 'ชานมไข่มุก', calories: 280, protein: 4, carbs: 45, fat: 8, image: 'http://static.photos/food/200x200/789' },
17
+ { name: 'ข้าวเหนียวมะม่วง', calories: 350, protein: 3, carbs: 58, fat: 12, image: 'http://static.photos/food/200x200/890' }
18
+ ];
19
+ }
20
+
21
+ connectedCallback() {
22
+ this.render();
23
+ }
24
+
25
+ render() {
26
+ this.shadowRoot.innerHTML = `
27
+ <style>
28
+ :host {
29
+ display: block;
30
+ margin: 0 1rem 1rem;
31
+ }
32
+
33
+ .meal-container {
34
+ background: rgba(31, 41, 55, 0.4);
35
+ backdrop-filter: blur(10px);
36
+ border: 1px solid rgba(75, 85, 99, 0.3);
37
+ border-radius: 1rem;
38
+ padding: 1rem;
39
+ }
40
+
41
+ .meal-header {
42
+ display: flex;
43
+ align-items: center;
44
+ justify-content: space-between;
45
+ margin-bottom: 0.75rem;
46
+ }
47
+
48
+ .meal-title {
49
+ font-size: 0.85rem;
50
+ font-weight: 600;
51
+ color: #e5e7eb;
52
+ display: flex;
53
+ align-items: center;
54
+ gap: 0.5rem;
55
+ }
56
+
57
+ .ai-photo-btn {
58
+ background: linear-gradient(135deg, #8b5cf6, #a855f7);
59
+ color: white;
60
+ padding: 0.25rem 0.5rem;
61
+ border-radius: 0.5rem;
62
+ font-size: 0.65rem;
63
+ font-weight: 500;
64
+ cursor: pointer;
65
+ transition: all 0.3s ease;
66
+ border: none;
67
+ display: flex;
68
+ align-items: center;
69
+ gap: 0.25rem;
70
+ }
71
+
72
+ .ai-photo-btn:hover {
73
+ transform: translateY(-2px);
74
+ box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
75
+ }
76
+
77
+ .search-container {
78
+ position: relative;
79
+ margin-bottom: 0.75rem;
80
+ }
81
+
82
+ .search-input {
83
+ width: 100%;
84
+ padding: 0.5rem 1rem;
85
+ background: rgba(17, 24, 39, 0.4);
86
+ border: 1px solid rgba(75, 85, 99, 0.3);
87
+ border-radius: 0.75rem;
88
+ color: #e5e7eb;
89
+ font-size: 0.75rem;
90
+ font-family: 'Prompt', sans-serif;
91
+ }
92
+
93
+ .search-input::placeholder {
94
+ color: #6b7280;
95
+ }
96
+
97
+ .search-input:focus {
98
+ outline: none;
99
+ border-color: #34d399;
100
+ box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.2);
101
+ }
102
+
103
+ .search-results {
104
+ position: absolute;
105
+ top: 100%;
106
+ left: 0;
107
+ right: 0;
108
+ background: rgba(31, 41, 55, 0.95);
109
+ border: 1px solid rgba(75, 85, 99, 0.5);
110
+ border-radius: 0.75rem;
111
+ margin-top: 0.25rem;
112
+ max-height: 200px;
113
+ overflow-y: auto;
114
+ z-index: 10;
115
+ display: none;
116
+ }
117
+
118
+ .search-results.show {
119
+ display: block;
120
+ }
121
+
122
+ .search-item {
123
+ padding: 0.5rem;
124
+ cursor: pointer;
125
+ transition: all 0.2s ease;
126
+ border-bottom: 1px solid rgba(75, 85, 99, 0.2);
127
+ }
128
+
129
+ .search-item:last-child {
130
+ border-bottom: none;
131
+ }
132
+
133
+ .search-item:hover {
134
+ background: rgba(52, 211, 153, 0.1);
135
+ }
136
+
137
+ .recent-meals {
138
+ display: flex;
139
+ flex-direction: column;
140
+ gap: 0.5rem;
141
+ }
142
+
143
+ .meal-item {
144
+ display: flex;
145
+ align-items: center;
146
+ gap: 0.75rem;
147
+ padding: 0.5rem;
148
+ background: rgba(17, 24, 39, 0.3);
149
+ border-radius: 0.75rem;
150
+ transition: all 0.3s ease;
151
+ cursor: pointer;
152
+ }
153
+
154
+ .meal-item:hover {
155
+ background: rgba(31, 41, 55, 0.6);
156
+ transform: translateX(5px);
157
+ }
158
+
159
+ .meal-image {
160
+ width: 48px;
161
+ height: 48px;
162
+ border-radius: 0.5rem;
163
+ object-fit: cover;
164
+ border: 1px solid rgba(75, 85, 99, 0.3);
165
+ }
166
+
167
+ .meal-info {
168
+ flex: 1;
169
+ display: flex;
170
+ flex-direction: column;
171
+ }
172
+
173
+ .meal-name {
174
+ font-size: 0.8rem;
175
+ font-weight: 500;
176
+ color: #e5e7eb;
177
+ margin-bottom: 0.25rem;
178
+ }
179
+
180
+ .meal-meta {
181
+ font-size: 0.65rem;
182
+ color: #9ca3af;
183
+ display: flex;
184
+ gap: 0.5rem;
185
+ }
186
+
187
+ .meal-calories {
188
+ background: rgba(251, 146, 60, 0.2);
189
+ color: #fb923c;
190
+ padding: 0.1rem 0.5rem;
191
+ border-radius: 9999px;
192
+ font-weight: 600;
193
+ }
194
+
195
+ .meal-macros {
196
+ display: flex;
197
+ gap: 0.25rem;
198
+ }
199
+
200
+ .macro {
201
+ background: rgba(107, 114, 128, 0.2);
202
+ padding: 0.1rem 0.3rem;
203
+ border-radius: 0.25rem;
204
+ }
205
+
206
+ .ai-suggestion {
207
+ background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(168, 85, 247, 0.1));
208
+ border: 1px solid rgba(139, 92, 246, 0.3);
209
+ border-radius: 0.75rem;
210
+ padding: 0.75rem;
211
+ margin-bottom: 0.75rem;
212
+ display: none;
213
+ }
214
+
215
+ .ai-suggestion.show {
216
+ display: block;
217
+ }
218
+
219
+ .ai-header {
220
+ display: flex;
221
+ align-items: center;
222
+ gap: 0.5rem;
223
+ margin-bottom: 0.25rem;
224
+ }
225
+
226
+ .ai-icon {
227
+ width: 16px;
228
+ height: 16px;
229
+ background: linear-gradient(135deg, #8b5cf6, #a855f7);
230
+ border-radius: 50%;
231
+ display: flex;
232
+ align-items: center;
233
+ justify-content: center;
234
+ color: white;
235
+ font-size: 0.6rem;
236
+ }
237
+
238
+ .ai-title {
239
+ font-size: 0.7rem;
240
+ font-weight: 600;
241
+ color: #c4b5fd;
242
+ }
243
+
244
+ .ai-message {
245
+ font-size: 0.65rem;
246
+ color: #d1d5db;
247
+ line-height: 1.4;
248
+ }
249
+
250
+ .quick-add-section {
251
+ display: flex;
252
+ gap: 0.5rem;
253
+ overflow-x: auto;
254
+ padding-bottom: 0.5rem;
255
+ margin-top: 0.75rem;
256
+ }
257
+
258
+ .quick-add-item {
259
+ flex-shrink: 0;
260
+ padding: 0.5rem 1rem;
261
+ background: rgba(52, 211, 153, 0.1);
262
+ border: 1px solid rgba(52, 211, 153, 0.3);
263
+ border-radius: 9999px;
264
+ font-size: 0.65rem;
265
+ color: #34d399;
266
+ cursor: pointer;
267
+ transition: all 0.3s ease;
268
+ }
269
+
270
+ .quick-add-item:hover {
271
+ background: rgba(52, 211, 153, 0.2);
272
+ transform: translateY(-2px);
273
+ }
274
+
275
+ .hidden-file-input {
276
+ display: none;
277
+ }
278
+ </style>
279
+
280
+ <div class="meal-container">
281
+ <div class="meal-header">
282
+ <div class="meal-title">
283
+ <i data-feather="coffee" class="w-4 h-4 text-orange-400"></i>
284
+ มื้ออาหารล่าสุด
285
+ </div>
286
+ <div class="flex gap-2">
287
+ <button class="ai-photo-btn" id="aiPhotoBtn">
288
+ <i data-feather="camera" class="w-3 h-3"></i>
289
+ AI ถ่ายรูป
290
+ </button>
291
+ <button class="ai-photo-btn" style="background: linear-gradient(135deg, #f59e0b, #f97316);" id="barcodeBtn">
292
+ <i data-feather="maximize" class="w-3 h-3"></i>
293
+ สแกนบาร์โค้ด
294
+ </button>
295
+ </div>
296
+ </div>
297
+
298
+ <input type="file" accept="image/*" class="hidden-file-input" id="photoInput" capture="environment">
299
+ <input type="file" accept="image/*" class="hidden-file-input" id="barcodeInput">
300
+
301
+ <div class="search-container">
302
+ <input type="text" class="search-input" id="searchInput" placeholder="ค้นหาอาหารไทย... (เช่น กะเพรา, ส้มตำ, ข้าวมันไก่)">
303
+ <div class="search-results" id="searchResults"></div>
304
+ </div>
305
+
306
+ <div class="ai-suggestion" id="aiSuggestion">
307
+ <div class="ai-header">
308
+ <div class="ai-icon">AI</div>
309
+ <div class="ai-title">คำแนะนำอัจฉริยะ</div>
310
+ </div>
311
+ <div class="ai-message" id="aiMessage"></div>
312
+ </div>
313
+
314
+ <div class="recent-meals" id="recentMeals">
315
+ ${this.thaiFoodDatabase.slice(0, 3).map(food => this.renderMealItem(food)).join('')}
316
+ </div>
317
+
318
+ <div class="quick-add-section">
319
+ <div class="quick-add-item" data-meal="ข้าวมันไก่">ข้าวมันไก่</div>
320
+ <div class="quick-add-item" data-meal="ส้มตำ">ส้มตำ</div>
321
+ <div class="quick-add-item" data-meal="กะเพรา">กะเพรา</div>
322
+ <div class="quick-add-item" data-meal="ชานม">ชานมไข่มุก</div>
323
+ <div class="quick-add-item" data-meal="ข้าวเหนียว">ข้าวเหนียวมะม่วง</div>
324
+ </div>
325
+
326
+ <div class="mood-actions" style="margin-top: 0.75rem;">
327
+ <button class="mood-btn save-btn" id="viewAllMealsBtn">ดูทั้งหมด</button>
328
+ <button class="mood-btn history-btn" id="customMealBtn">สร้างเมนู</button>
329
+ </div>
330
+ </div>
331
+ `;
332
+
333
+ this.setupEventListeners();
334
+ }
335
+
336
+ renderMealItem(food) {
337
+ return `
338
+ <div class="meal-item" data-food="${food.name}">
339
+ <img src="${food.image}" alt="${food.name}" class="meal-image">
340
+ <div class="meal-info">
341
+ <div class="meal-name">${food.name}</div>
342
+ <div class="meal-meta">
343
+ <span class="meal-calories">${food.calories} แคล</span>
344
+ <div class="meal-macros">
345
+ <span class="macro">P:${food.protein}g</span>
346
+ <span class="macro">C:${food.carbs}g</span>
347
+ <span class="macro">F:${food.fat}g</span>
348
+ </div>
349
+ </div>
350
+ </div>
351
+ <i data-feather="plus-circle" class="w-5 h-5 text-green-400"></i>
352
+ </div>
353
+ `;
354
+ }
355
+
356
+ setupEventListeners() {
357
+ const searchInput = this.shadowRoot.getElementById('searchInput');
358
+ const searchResults = this.shadowRoot.getElementById('searchResults');
359
+ const aiPhotoBtn = this.shadowRoot.getElementById('aiPhotoBtn');
360
+ const barcodeBtn = this.shadowRoot.getElementById('barcodeBtn');
361
+ const photoInput = this.shadowRoot.getElementById('photoInput');
362
+ const barcodeInput = this.shadowRoot.getElementById('barcodeInput');
363
+ const quickAddItems = this.shadowRoot.querySelectorAll('.quick-add-item');
364
+
365
+ // Search functionality
366
+ searchInput.addEventListener('input', (e) => {
367
+ const query = e.target.value.toLowerCase().trim();
368
+
369
+ if (query.length < 2) {
370
+ searchResults.classList.remove('show');
371
+ return;
372
+ }
373
+
374
+ const matches = this.thaiFoodDatabase.filter(food =>
375
+ food.name.toLowerCase().includes(query) ||
376
+ food.name.replace(/\s/g, '').includes(query.replace(/\s/g, ''))
377
+ );
378
+
379
+ if (matches.length > 0) {
380
+ searchResults.innerHTML = matches.slice(0, 5).map(food => `
381
+ <div class="search-item" data-food='${JSON.stringify(food)}'>
382
+ <div class="flex items-center gap-2">
383
+ <img src="${food.image}" alt="${food.name}" class="w-8 h-8 rounded object-cover">
384
+ <div>
385
+ <div class="font-medium text-sm">${food.name}</div>
386
+ <div class="text-xs text-gray-400">${food.calories} แคลอรี</div>
387
+ </div>
388
+ </div>
389
+ </div>
390
+ `).join('');
391
+ searchResults.classList.add('show');
392
+
393
+ // Add click handlers
394
+ searchResults.querySelectorAll('.search-item').forEach(item => {
395
+ item.addEventListener('click', () => {
396
+ const food = JSON.parse(item.dataset.food);
397
+ this.addMeal(food);
398
+ searchResults.classList.remove('show');
399
+ searchInput.value = '';
400
+ });
401
+ });
402
+ } else {
403
+ searchResults.innerHTML = '<div class="search-item text-gray-400">ไม่พบอาหาร ลองสร้างเมนูเอง?</div>';
404
+ searchResults.classList.add('show');
405
+ }
406
+ });
407
+
408
+ // Hide search results when clicking outside
409
+ document.addEventListener('click', (e) => {
410
+ if (!this.shadowRoot.contains(e.target)) {
411
+ searchResults.classList.remove('show');
412
+ }
413
+ });
414
+
415
+ // AI Photo logging
416
+ aiPhotoBtn.addEventListener('click', () => {
417
+ photoInput.click();
418
+ });
419
+
420
+ photoInput.addEventListener('change', (e) => {
421
+ const file = e.target.files[0];
422
+ if (file) {
423
+ this.processFoodPhoto(file);
424
+ }
425
+ });
426
+
427
+ // Barcode scanning
428
+ barcodeBtn.addEventListener('click', () => {
429
+ barcodeInput.click();
430
+ });
431
+
432
+ barcodeInput.addEventListener('change', (e) => {
433
+ const file = e.target.files[0];
434
+ if (file) {
435
+ this.processBarcode(file);
436
+ }
437
+ });
438
+
439
+ // Quick add buttons
440
+ quickAddItems.forEach(item => {
441
+ item.addEventListener('click', () => {
442
+ const mealName = item.dataset.meal;
443
+ const food = this.thaiFoodDatabase.find(f => f.name.includes(mealName));
444
+ if (food) {
445
+ this.addMeal(food);
446
+ }
447
+ });
448
+ });
449
+
450
+ // Meal item clicks
451
+ this.shadowRoot.addEventListener('click', (e) => {
452
+ const mealItem = e.target.closest('.meal-item');
453
+ if (mealItem) {
454
+ const foodName = mealItem.dataset.food;
455
+ const food = this.thaiFoodDatabase.find(f => f.name === foodName);
456
+ if (food) {
457
+ this.addMeal(food);
458
+ }
459
+ }
460
+ });
461
+ }
462
+
463
+ processFoodPhoto(file) {
464
+ this.showNotification('กำลังวิเคราะห์รูปภาพด้วย AI...', 'info');
465
+
466
+ // Simulate AI processing
467
+ setTimeout(() => {
468
+ const detectedFood = this.thaiFoodDatabase[Math.floor(Math.random() * this.thaiFoodDatabase.length)];
469
+
470
+ this.showAIsuggestion(
471
+ `ระบบตรวจพบ "${detectedFood.name}" ด้วยความมั่นใจ 85%`,
472
+ `คลิกเพื่อบันทึก ${detectedFood.calories} แคลอรี หรือแก้ไขถ้าไม่ถูกต้อง`
473
+ );
474
+
475
+ // Auto-select the detected food
476
+ setTimeout(() => {
477
+ this.addMeal(detectedFood);
478
+ }, 2000);
479
+ }, 3000);
480
+ }
481
+
482
+ processBarcode(file) {
483
+ this.showNotification('กำลังสแกนบาร์โค้ด...', 'info');
484
+
485
+ setTimeout(() => {
486
+ this.showNotification('พบสินค้า: โยเกิร์ตไขมันต่ำ 180 แคลอรี', 'success');
487
+ }, 2000);
488
+ }
489
+
490
+ showAIsuggestion(title, message) {
491
+ const suggestion = this.shadowRoot.getElementById('aiSuggestion');
492
+ const aiMessage = this.shadowRoot.getElementById('aiMessage');
493
+
494
+ suggestion.classList.add('show');
495
+ aiMessage.innerHTML = `<strong>${title}</strong><br>${message}`;
496
+
497
+ setTimeout(() => {
498
+ suggestion.classList.remove('show');
499
+ }, 5000);
500
+ }
501
+
502
+ addMeal(food) {
503
+ this.showNotification(`บันทึก ${food.name} ${food.calories} แคลอรี สำเร็จ!`, 'success');
504
+
505
+ // Add to recent meals
506
+ const recentMeals = this.shadowRoot.getElementById('recentMeals');
507
+ const newMeal = document.createElement('div');
508
+ newMeal.className = 'meal-item';
509
+ newMeal.innerHTML = this.renderMealItem(food);
510
+ recentMeals.insertBefore(newMeal, recentMeals.firstChild);
511
+
512
+ // Keep only 3 items
513
+ while (recentMeals.children.length > 3) {
514
+ recentMeals.removeChild(recentMeals.lastChild);
515
+ }
516
+
517
+ // Save to localStorage
518
+ const todayMeals = JSON.parse(localStorage.getItem('todayMeals') || '[]');
519
+ todayMeals.unshift({
520
+ ...food,
521
+ timestamp: new Date().toISOString(),
522
+ mealType: this.getCurrentMealType()
523
+ });
524
+ localStorage.setItem('todayMeals', JSON.stringify(todayMeals.slice(0, 10)));
525
+
526
+ // Dispatch event
527
+ this.dispatchEvent(new CustomEvent('meal-logged', {
528
+ detail: food,
529
+ bubbles: true,
530
+ composed: true
531
+ }));
532
+ }
533
+
534
+ getCurrentMealType() {
535
+ const hour = new Date().getHours();
536
+ if (hour < 11) return 'เช้า';
537
+ if (hour < 16) return 'เที่ยง';
538
+ if (hour < 19) return 'เย็น';
539
+ return 'ดึก';
540
+ }
541
+
542
+ showNotification(message, type = 'info') {
543
+ if (window.showNotification) {
544
+ window.showNotification(message, type);
545
+ } else {
546
+ alert(message);
547
+ }
548
+ }
549
+ }
550
+
551
+ customElements.define('meal-logger-enhanced', MealLoggerEnhanced);
components/mood-logger.js ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class MoodLogger extends HTMLElement {
2
+ constructor() {
3
+ super();
4
+ this.attachShadow({ mode: 'open' });
5
+ this.moods = [
6
+ { emoji: '😊', label: 'สดชื่น', value: 'happy' },
7
+ { emoji: '😌', label: 'สงบ', value: 'calm' },
8
+ { emoji: '😐', label: 'ธรรมดา', value: 'neutral' },
9
+ { emoji: '😔', label: 'เศร้า', value: 'sad' },
10
+ { emoji: '😠', label: 'หงุดหงิด', value: 'angry' },
11
+ { emoji: '😴', label: 'ง่วง', value: 'tired' },
12
+ { emoji: '😰', label: 'เครียด', value: 'stressed' },
13
+ { emoji: '🤩', label: 'ตื่นเต้น', value: 'excited' }
14
+ ];
15
+ this.currentMood = null;
16
+ }
17
+
18
+ connectedCallback() {
19
+ this.render();
20
+ this.loadTodaysMood();
21
+ }
22
+
23
+ render() {
24
+ this.shadowRoot.innerHTML = `
25
+ <style>
26
+ :host {
27
+ display: block;
28
+ margin: 0 1rem 1rem;
29
+ }
30
+
31
+ .mood-container {
32
+ background: rgba(31, 41, 55, 0.4);
33
+ backdrop-filter: blur(10px);
34
+ border: 1px solid rgba(75, 85, 99, 0.3);
35
+ border-radius: 1rem;
36
+ padding: 1rem;
37
+ }
38
+
39
+ .mood-header {
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: space-between;
43
+ margin-bottom: 0.75rem;
44
+ }
45
+
46
+ .mood-title {
47
+ font-size: 0.85rem;
48
+ font-weight: 600;
49
+ color: #e5e7eb;
50
+ display: flex;
51
+ align-items: center;
52
+ gap: 0.5rem;
53
+ }
54
+
55
+ .streak-badge {
56
+ background: linear-gradient(135deg, #f59e0b, #f97316);
57
+ color: white;
58
+ padding: 0.25rem 0.5rem;
59
+ border-radius: 9999px;
60
+ font-size: 0.65rem;
61
+ font-weight: 600;
62
+ }
63
+
64
+ .mood-grid {
65
+ display: grid;
66
+ grid-template-columns: repeat(4, 1fr);
67
+ gap: 0.5rem;
68
+ margin-bottom: 0.75rem;
69
+ }
70
+
71
+ .mood-item {
72
+ display: flex;
73
+ flex-direction: column;
74
+ align-items: center;
75
+ padding: 0.5rem 0.25rem;
76
+ border-radius: 0.75rem;
77
+ border: 1px solid transparent;
78
+ cursor: pointer;
79
+ transition: all 0.3s ease;
80
+ background: rgba(17, 24, 39, 0.3);
81
+ }
82
+
83
+ .mood-item:hover {
84
+ border-color: rgba(52, 211, 153, 0.5);
85
+ background: rgba(52, 211, 153, 0.1);
86
+ transform: translateY(-3px);
87
+ }
88
+
89
+ .mood-item.selected {
90
+ border-color: #34d399;
91
+ background: rgba(52, 211, 153, 0.2);
92
+ box-shadow: 0 4px 12px rgba(52, 211, 153, 0.2);
93
+ }
94
+
95
+ .mood-emoji {
96
+ font-size: 1.5rem;
97
+ margin-bottom: 0.25rem;
98
+ transition: transform 0.3s ease;
99
+ }
100
+
101
+ .mood-item:hover .mood-emoji {
102
+ transform: scale(1.2);
103
+ }
104
+
105
+ .mood-label {
106
+ font-size: 0.6rem;
107
+ color: #9ca3af;
108
+ text-align: center;
109
+ font-weight: 500;
110
+ }
111
+
112
+ .mood-note {
113
+ width: 100%;
114
+ padding: 0.5rem;
115
+ background: rgba(17, 24, 39, 0.4);
116
+ border: 1px solid rgba(75, 85, 99, 0.3);
117
+ border-radius: 0.5rem;
118
+ color: #e5e7eb;
119
+ font-size: 0.75rem;
120
+ font-family: 'Prompt', sans-serif;
121
+ resize: vertical;
122
+ min-height: 60px;
123
+ margin-bottom: 0.5rem;
124
+ display: none;
125
+ }
126
+
127
+ .mood-note.show {
128
+ display: block;
129
+ }
130
+
131
+ .mood-note::placeholder {
132
+ color: #6b7280;
133
+ }
134
+
135
+ .mood-actions {
136
+ display: flex;
137
+ gap: 0.5rem;
138
+ justify-content: space-between;
139
+ }
140
+
141
+ .mood-btn {
142
+ flex: 1;
143
+ padding: 0.5rem;
144
+ border-radius: 0.5rem;
145
+ font-size: 0.75rem;
146
+ font-weight: 500;
147
+ cursor: pointer;
148
+ transition: all 0.3s ease;
149
+ border: none;
150
+ font-family: 'Prompt', sans-serif;
151
+ }
152
+
153
+ .save-btn {
154
+ background: linear-gradient(135deg, #34d399, #10b981);
155
+ color: white;
156
+ }
157
+
158
+ .save-btn:hover {
159
+ transform: translateY(-2px);
160
+ box-shadow: 0 4px 12px rgba(52, 211, 153, 0.3);
161
+ }
162
+
163
+ .history-btn {
164
+ background: rgba(107, 114, 128, 0.3);
165
+ color: #e5e7eb;
166
+ }
167
+
168
+ .history-btn:hover {
169
+ background: rgba(107, 114, 128, 0.5);
170
+ }
171
+
172
+ .mood-streak {
173
+ display: flex;
174
+ align-items: center;
175
+ gap: 0.5rem;
176
+ margin-top: 0.5rem;
177
+ padding-top: 0.5rem;
178
+ border-top: 1px solid rgba(75, 85, 99, 0.3);
179
+ }
180
+
181
+ .streak-info {
182
+ flex: 1;
183
+ font-size: 0.7rem;
184
+ color: #9ca3af;
185
+ }
186
+
187
+ .streak-count {
188
+ color: #fbbf24;
189
+ font-weight: 600;
190
+ }
191
+ </style>
192
+
193
+ <div class="mood-container">
194
+ <div class="mood-header">
195
+ <div class="mood-title">
196
+ <i data-feather="heart" class="w-4 h-4 text-pink-400"></i>
197
+ อารมณ์ประจำวัน
198
+ </div>
199
+ <div class="streak-badge" id="streakBadge">
200
+ 🔥 7 วัน
201
+ </div>
202
+ </div>
203
+
204
+ <div class="mood-grid" id="moodGrid">
205
+ ${this.moods.map(mood => `
206
+ <div class="mood-item" data-value="${mood.value}" data-emoji="${mood.emoji}" data-label="${mood.label}">
207
+ <div class="mood-emoji">${mood.emoji}</div>
208
+ <div class="mood-label">${mood.label}</div>
209
+ </div>
210
+ `).join('')}
211
+ </div>
212
+
213
+ <textarea class="mood-note" id="moodNote" placeholder="บันทึกความรู้สึกเพิ่มเติม... (ไม่บังคับ)"></textarea>
214
+
215
+ <div class="mood-actions">
216
+ <button class="mood-btn save-btn" id="saveMoodBtn">บันทึกอารมณ์</button>
217
+ <button class="mood-btn history-btn" id="historyBtn">ประวัติ</button>
218
+ </div>
219
+
220
+ <div class="mood-streak">
221
+ <div class="streak-info">
222
+ คุณบันทึกอารมณ์ติดต่อกันมา <span class="streak-count">7 วัน</span> แล้ว!
223
+ </div>
224
+ </div>
225
+ </div>
226
+ `;
227
+
228
+ this.setupEventListeners();
229
+ }
230
+
231
+ setupEventListeners() {
232
+ const moodItems = this.shadowRoot.querySelectorAll('.mood-item');
233
+ const saveBtn = this.shadowRoot.getElementById('saveMoodBtn');
234
+ const historyBtn = this.shadowRoot.getElementById('historyBtn');
235
+ const moodNote = this.shadowRoot.getElementById('moodNote');
236
+
237
+ moodItems.forEach(item => {
238
+ item.addEventListener('click', () => {
239
+ // Remove previous selection
240
+ moodItems.forEach(i => i.classList.remove('selected'));
241
+
242
+ // Select current
243
+ item.classList.add('selected');
244
+ this.currentMood = {
245
+ value: item.dataset.value,
246
+ emoji: item.dataset.emoji,
247
+ label: item.dataset.label
248
+ };
249
+
250
+ // Show note textarea
251
+ moodNote.classList.add('show');
252
+ moodNote.focus();
253
+ });
254
+ });
255
+
256
+ saveBtn.addEventListener('click', () => {
257
+ if (!this.currentMood) {
258
+ this.showNotification('กรุณาเลือกอารมณ์ก่อนบันทึก', 'warning');
259
+ return;
260
+ }
261
+
262
+ const note = moodNote.value.trim();
263
+ this.saveMood(this.currentMood, note);
264
+ });
265
+
266
+ historyBtn.addEventListener('click', () => {
267
+ this.showMoodHistory();
268
+ });
269
+ }
270
+
271
+ loadTodaysMood() {
272
+ // Simulate loading today's mood from localStorage
273
+ const savedMood = localStorage.getItem('todayMood');
274
+ if (savedMood) {
275
+ const mood = JSON.parse(savedMood);
276
+ const moodItem = this.shadowRoot.querySelector(`[data-value="${mood.value}"]`);
277
+ if (moodItem) {
278
+ moodItem.classList.add('selected');
279
+ this.currentMood = mood;
280
+ this.shadowRoot.getElementById('moodNote').value = mood.note || '';
281
+ this.shadowRoot.getElementById('moodNote').classList.add('show');
282
+ }
283
+ }
284
+ }
285
+
286
+ saveMood(mood, note) {
287
+ const data = {
288
+ ...mood,
289
+ note,
290
+ timestamp: new Date().toISOString(),
291
+ date: new Date().toLocaleDateString('th-TH')
292
+ };
293
+
294
+ // Save to localStorage
295
+ localStorage.setItem('todayMood', JSON.stringify(data));
296
+
297
+ // Add to history
298
+ const history = JSON.parse(localStorage.getItem('moodHistory') || '[]');
299
+ history.unshift(data);
300
+ localStorage.setItem('moodHistory', JSON.stringify(history.slice(0, 30)));
301
+
302
+ this.showNotification(`บันทึกอารมณ์ ${mood.emoji} ${mood.label} สำเร็จ!`, 'success');
303
+
304
+ // Update streak
305
+ this.updateStreak();
306
+
307
+ // Send event to update AI coach
308
+ this.dispatchEvent(new CustomEvent('mood-updated', {
309
+ detail: data,
310
+ bubbles: true,
311
+ composed: true
312
+ }));
313
+ }
314
+
315
+ updateStreak() {
316
+ const history = JSON.parse(localStorage.getItem('moodHistory') || '[]');
317
+ let streak = 0;
318
+ const today = new Date();
319
+
320
+ for (let i = 0; i < history.length; i++) {
321
+ const moodDate = new Date(history[i].timestamp);
322
+ const daysDiff = Math.floor((today - moodDate) / (1000 * 60 * 60 * 24));
323
+
324
+ if (daysDiff === streak) {
325
+ streak++;
326
+ } else {
327
+ break;
328
+ }
329
+ }
330
+
331
+ const streakBadge = this.shadowRoot.getElementById('streakBadge');
332
+ const streakCount = this.shadowRoot.querySelector('.streak-count');
333
+
334
+ if (streak > 1) {
335
+ streakBadge.textContent = `🔥 ${streak} วัน`;
336
+ streakCount.textContent = `${streak} วัน`;
337
+ } else {
338
+ streakBadge.textContent = 'เริ่มต้นใหม่';
339
+ streakCount.textContent = '1 วัน';
340
+ }
341
+ }
342
+
343
+ showMoodHistory() {
344
+ const history = JSON.parse(localStorage.getItem('moodHistory') || '[]');
345
+
346
+ const modal = document.createElement('div');
347
+ modal.className = 'fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4';
348
+ modal.innerHTML = `
349
+ <div class="glass-card rounded-2xl p-6 max-w-md w-full border border-gray-700/50 max-h-[80vh] overflow-y-auto">
350
+ <h3 class="text-xl font-bold mb-4">ประวัติอารมณ์</h3>
351
+ ${history.length > 0 ? `
352
+ <div class="space-y-2">
353
+ ${history.slice(0, 7).map(record => `
354
+ <div class="p-3 bg-gray-800/50 rounded-lg">
355
+ <div class="flex items-center justify-between mb-1">
356
+ <div class="flex items-center gap-2">
357
+ <span class="text-2xl">${record.emoji}</span>
358
+ <span class="font-medium">${record.label}</span>
359
+ </div>
360
+ <span class="text-xs text-gray-400">${record.date}</span>
361
+ </div>
362
+ ${record.note ? `<p class="text-sm text-gray-300">${record.note}</p>` : ''}
363
+ </div>
364
+ `).join('')}
365
+ </div>
366
+ ` : '<p class="text-gray-400 text-center py-4">ยังไม่มีประวัติการบันทึก</p>'}
367
+ <button onclick="this.closest('.fixed').remove()" class="w-full mt-4 bg-gray-700 hover:bg-gray-600 py-3 rounded-xl font-medium transition-colors">
368
+ ปิด
369
+ </button>
370
+ </div>
371
+ `;
372
+
373
+ document.body.appendChild(modal);
374
+ }
375
+
376
+ showNotification(message, type = 'info') {
377
+ if (window.showNotification) {
378
+ window.showNotification(message, type);
379
+ } else {
380
+ alert(message);
381
+ }
382
+ }
383
+ }
384
+
385
+ customElements.define('mood-logger', MoodLogger);
components/navbar.js ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class MainNavbar extends HTMLElement {
2
+ constructor() {
3
+ super();
4
+ this.currentPage = 'today';
5
+ }
6
+
7
+ connectedCallback() {
8
+ this.attachShadow({ mode: 'open' });
9
+ this.render();
10
+ this.setupEventListeners();
11
+ }
12
+
13
+ render() {
14
+ this.shadowRoot.innerHTML = `
15
+ <style>
16
+ :host {
17
+ position: fixed;
18
+ bottom: 0;
19
+ left: 0;
20
+ right: 0;
21
+ z-index: 50;
22
+ }
23
+
24
+ .navbar {
25
+ background: rgba(17, 24, 39, 0.8);
26
+ backdrop-filter: blur(20px);
27
+ -webkit-backdrop-filter: blur(20px);
28
+ border-top: 1px solid rgba(75, 85, 99, 0.3);
29
+ display: flex;
30
+ justify-content: space-around;
31
+ padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom));
32
+ }
33
+
34
+ .nav-item {
35
+ flex: 1;
36
+ display: flex;
37
+ flex-direction: column;
38
+ align-items: center;
39
+ padding: 0.5rem;
40
+ text-decoration: none;
41
+ color: #9ca3af;
42
+ transition: all 0.3s ease;
43
+ position: relative;
44
+ border-radius: 12px;
45
+ margin: 0 0.25rem;
46
+ }
47
+
48
+ .nav-item.active {
49
+ color: #34d399;
50
+ background: rgba(52, 211, 153, 0.1);
51
+ }
52
+
53
+ .nav-item:not(.active):hover {
54
+ color: #e5e7eb;
55
+ background: rgba(107, 114, 128, 0.1);
56
+ }
57
+
58
+ .nav-icon {
59
+ width: 24px;
60
+ height: 24px;
61
+ margin-bottom: 0.25rem;
62
+ stroke-width: 2;
63
+ }
64
+
65
+ .nav-label {
66
+ font-size: 0.7rem;
67
+ font-weight: 500;
68
+ font-family: 'Prompt', sans-serif;
69
+ }
70
+
71
+ .active-indicator {
72
+ position: absolute;
73
+ top: -2px;
74
+ width: 20px;
75
+ height: 3px;
76
+ background: linear-gradient(90deg, #34d399, #10b981);
77
+ border-radius: 2px;
78
+ opacity: 0;
79
+ transition: opacity 0.3s ease;
80
+ }
81
+
82
+ .nav-item.active .active-indicator {
83
+ opacity: 1;
84
+ }
85
+
86
+ @media (max-width: 640px) {
87
+ .navbar {
88
+ padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
89
+ }
90
+ }
91
+ </style>
92
+
93
+ <nav class="navbar">
94
+ <a href="#today" class="nav-item active" data-page="today">
95
+ <div class="active-indicator"></div>
96
+ <i class="nav-icon" data-feather="home"></i>
97
+ <span class="nav-label">วันนี้</span>
98
+ </a>
99
+ <a href="#sleep" class="nav-item" data-page="sleep">
100
+ <div class="active-indicator"></div>
101
+ <i class="nav-icon" data-feather="moon"></i>
102
+ <span class="nav-label">การนอน</span>
103
+ </a>
104
+ <a href="#activity" class="nav-item" data-page="activity">
105
+ <div class="active-indicator"></div>
106
+ <i class="nav-icon" data-feather="zap"></i>
107
+ <span class="nav-label">ออกกำลังกาย</span>
108
+ </a>
109
+ <a href="#nutrition" class="nav-item" data-page="nutrition">
110
+ <div class="active-indicator"></div>
111
+ <i class="nav-icon" data-feather="coffee"></i>
112
+ <span class="nav-label">โภชนาการ</span>
113
+ </a>
114
+ <a href="#profile" class="nav-item" data-page="profile">
115
+ <div class="active-indicator"></div>
116
+ <i class="nav-icon" data-feather="user"></i>
117
+ <span class="nav-label">โปรไฟล์</span>
118
+ </a>
119
+ </nav>
120
+ `;
121
+ }
122
+
123
+ setupEventListeners() {
124
+ const navItems = this.shadowRoot.querySelectorAll('.nav-item');
125
+
126
+ navItems.forEach(item => {
127
+ item.addEventListener('click', (e) => {
128
+ e.preventDefault();
129
+ const page = item.dataset.page;
130
+ this.setActivePage(page);
131
+
132
+ // Dispatch custom event
133
+ this.dispatchEvent(new CustomEvent('page-change', {
134
+ detail: { page },
135
+ bubbles: true,
136
+ composed: true
137
+ }));
138
+
139
+ // In real app, would navigate to actual page
140
+ console.log(`เปลี่ยนหน้าไปที่: ${page}`);
141
+ });
142
+ });
143
+ }
144
+
145
+ setActivePage(page) {
146
+ const navItems = this.shadowRoot.querySelectorAll('.nav-item');
147
+ navItems.forEach(item => {
148
+ if (item.dataset.page === page) {
149
+ item.classList.add('active');
150
+ } else {
151
+ item.classList.remove('active');
152
+ }
153
+ });
154
+ this.currentPage = page;
155
+ }
156
+
157
+ // Public method to set page from outside
158
+ navigate(page) {
159
+ this.setActivePage(page);
160
+ }
161
+ }
162
+
163
+ customElements.define('main-navbar', MainNavbar);
components/vital-circle.js ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class VitalCircle extends HTMLElement {
2
+ constructor() {
3
+ super();
4
+ this.attachShadow({ mode: 'open' });
5
+ }
6
+
7
+ connectedCallback() {
8
+ this.render();
9
+ this.animateValue();
10
+ }
11
+
12
+ render() {
13
+ const type = this.getAttribute('type') || 'recovery';
14
+ const value = this.getAttribute('value') || '0';
15
+ const label = this.getAttribute('label') || 'การวัด';
16
+ const color = this.getAttribute('color') || 'from-green-400 to-emerald-500';
17
+ const max = parseInt(this.getAttribute('max') || '100');
18
+
19
+ this.shadowRoot.innerHTML = `
20
+ <style>
21
+ :host {
22
+ display: block;
23
+ position: relative;
24
+ }
25
+
26
+ .vital-container {
27
+ position: relative;
28
+ width: 100%;
29
+ aspect-ratio: 1;
30
+ border-radius: 50%;
31
+ background: rgba(31, 41, 55, 0.4);
32
+ backdrop-filter: blur(10px);
33
+ border: 1px solid rgba(75, 85, 99, 0.3);
34
+ display: flex;
35
+ flex-direction: column;
36
+ align-items: center;
37
+ justify-content: center;
38
+ transition: all 0.4s ease;
39
+ cursor: pointer;
40
+ overflow: hidden;
41
+ }
42
+
43
+ .vital-container::before {
44
+ content: '';
45
+ position: absolute;
46
+ top: 0;
47
+ left: 0;
48
+ right: 0;
49
+ bottom: 0;
50
+ background: linear-gradient(135deg, ${this.getColorValues(color)});
51
+ opacity: 0.15;
52
+ border-radius: 50%;
53
+ transition: opacity 0.3s ease;
54
+ }
55
+
56
+ .vital-container:hover {
57
+ transform: translateY(-5px);
58
+ border-color: rgba(52, 211, 153, 0.5);
59
+ box-shadow: 0 8px 25px rgba(52, 211, 153, 0.15);
60
+ }
61
+
62
+ .vital-container:hover::before {
63
+ opacity: 0.25;
64
+ }
65
+
66
+ .vital-value {
67
+ font-size: 1.5rem;
68
+ font-weight: 700;
69
+ background: linear-gradient(135deg, ${this.getColorValues(color)});
70
+ -webkit-background-clip: text;
71
+ -webkit-text-fill-color: transparent;
72
+ background-clip: text;
73
+ margin-bottom: 0.25rem;
74
+ transition: all 0.5s ease;
75
+ }
76
+
77
+ .vital-label {
78
+ font-size: 0.75rem;
79
+ color: #9ca3af;
80
+ font-weight: 500;
81
+ text-align: center;
82
+ padding: 0 0.5rem;
83
+ }
84
+
85
+ .vital-icon {
86
+ position: absolute;
87
+ top: 0.5rem;
88
+ right: 0.5rem;
89
+ width: 12px;
90
+ height: 12px;
91
+ border-radius: 50%;
92
+ background: linear-gradient(135deg, ${this.getColorValues(color)});
93
+ box-shadow: 0 0 8px currentColor;
94
+ }
95
+
96
+ .progress-ring {
97
+ position: absolute;
98
+ top: -2px;
99
+ left: -2px;
100
+ right: -2px;
101
+ bottom: -2px;
102
+ border-radius: 50%;
103
+ border: 2px solid transparent;
104
+ border-top-color: ${this.getPrimaryColor(color)};
105
+ animation: spin 2s linear infinite;
106
+ opacity: 0;
107
+ transition: opacity 0.3s ease;
108
+ }
109
+
110
+ .vital-container.loading .progress-ring {
111
+ opacity: 1;
112
+ }
113
+
114
+ @keyframes spin {
115
+ 0% { transform: rotate(0deg); }
116
+ 100% { transform: rotate(360deg); }
117
+ }
118
+
119
+ .trend-indicator {
120
+ position: absolute;
121
+ bottom: 0.5rem;
122
+ left: 50%;
123
+ transform: translateX(-50%);
124
+ font-size: 0.6rem;
125
+ color: #34d399;
126
+ font-weight: 600;
127
+ }
128
+
129
+ .trend-indicator.down {
130
+ color: #f87171;
131
+ }
132
+
133
+ @media (max-width: 640px) {
134
+ .vital-value {
135
+ font-size: 1.25rem;
136
+ }
137
+ .vital-label {
138
+ font-size: 0.65rem;
139
+ }
140
+ }
141
+ </style>
142
+
143
+ <div class="vital-container" id="vitalContainer">
144
+ <div class="progress-ring"></div>
145
+ <div class="vital-icon"></div>
146
+ <div class="vital-value" id="vitalValue">${value}</div>
147
+ <div class="vital-label">${label}</div>
148
+ <div class="trend-indicator" id="trendIndicator"></div>
149
+ </div>
150
+ `;
151
+ }
152
+
153
+ getColorValues(colorClass) {
154
+ const colorMap = {
155
+ 'from-green-400 to-emerald-500': '#34d399, #10b981',
156
+ 'from-orange-400 to-red-500': '#fb923c, #ef4444',
157
+ 'from-blue-400 to-indigo-500': '#60a5fa, #6366f1',
158
+ 'from-purple-500 to-pink-600': '#a855f7, #db2777',
159
+ 'from-yellow-400 to-orange-500': '#fbbf24, #f97316'
160
+ };
161
+ return colorMap[colorClass] || colorMap['from-green-400 to-emerald-500'];
162
+ }
163
+
164
+ getPrimaryColor(colorClass) {
165
+ const colorMap = {
166
+ 'from-green-400 to-emerald-500': '#34d399',
167
+ 'from-orange-400 to-red-500': '#fb923c',
168
+ 'from-blue-400 to-indigo-500': '#60a5fa',
169
+ 'from-purple-500 to-pink-600': '#a855f7',
170
+ 'from-yellow-400 to-orange-500': '#fbbf24'
171
+ };
172
+ return colorMap[colorClass] || '#34d399';
173
+ }
174
+
175
+ animateValue() {
176
+ const valueElement = this.shadowRoot.getElementById('vitalValue');
177
+ const endValue = parseFloat(this.getAttribute('value') || '0');
178
+ const duration = 1500;
179
+ const startTime = performance.now();
180
+
181
+ const animate = (currentTime) => {
182
+ const elapsed = currentTime - startTime;
183
+ const progress = Math.min(elapsed / duration, 1);
184
+
185
+ const easeOutQuart = 1 - Math.pow(1 - progress, 4);
186
+ const currentValue = (endValue * easeOutQuart).toFixed(1);
187
+
188
+ valueElement.textContent = currentValue % 1 === 0 ? currentValue.split('.')[0] : currentValue;
189
+
190
+ if (progress < 1) {
191
+ requestAnimationFrame(animate);
192
+ } else {
193
+ this.addTrendIndicator();
194
+ }
195
+ };
196
+
197
+ requestAnimationFrame(animate);
198
+ }
199
+
200
+ addTrendIndicator() {
201
+ const trendElement = this.shadowRoot.getElementById('trendIndicator');
202
+ const trends = ['↑ 5%', '↓ 3%', '→ เท่าเดิม', '↑ 12%', '↓ 8%'];
203
+ const randomTrend = trends[Math.floor(Math.random() * trends.length)];
204
+
205
+ trendElement.textContent = randomTrend;
206
+ trendElement.className = 'trend-indicator';
207
+
208
+ if (randomTrend.includes('↓')) {
209
+ trendElement.classList.add('down');
210
+ }
211
+ }
212
+
213
+ showLoading() {
214
+ const container = this.shadowRoot.getElementById('vitalContainer');
215
+ container.classList.add('loading');
216
+ }
217
+
218
+ hideLoading() {
219
+ const container = this.shadowRoot.getElementById('vitalContainer');
220
+ container.classList.remove('loading');
221
+ }
222
+
223
+ updateValue(newValue) {
224
+ this.setAttribute('value', newValue);
225
+ this.animateValue();
226
+ }
227
+ }
228
+
229
+ customElements.define('vital-circle', VitalCircle);
index.html CHANGED
@@ -1,19 +1,242 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="th" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
+ <title>ชีพจร - แดชบอร์ดประจำวัน</title>
7
+ <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>">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <script src="https://unpkg.com/feather-icons"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
12
+ <link rel="stylesheet" href="style.css">
13
+ </head>
14
+ <body class="bg-gray-900 text-white font-sans pb-20">
15
+ <!-- Main Container -->
16
+ <div class="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900">
17
+ <!-- Header -->
18
+ <header class="px-4 pt-12 pb-6">
19
+ <div class="flex items-center justify-between">
20
+ <div>
21
+ <h1 class="text-2xl font-bold bg-gradient-to-r from-green-400 to-emerald-500 bg-clip-text text-transparent">
22
+ สวัสดี, คุณพิมพ์
23
+ </h1>
24
+ <p class="text-gray-400 text-sm mt-1">วันนี้พร้อมลุยไหม? 💪</p>
25
+ </div>
26
+ <div class="relative">
27
+ <div class="w-12 h-12 rounded-full bg-gradient-to-r from-green-400 to-emerald-500 p-0.5">
28
+ <img src="http://static.photos/people/200x200/42" alt="Profile" class="w-full h-full rounded-full object-cover border-2 border-gray-900">
29
+ </div>
30
+ <div class="absolute -bottom-1 -right-1 w-4 h-4 bg-green-400 rounded-full border-2 border-gray-900"></div>
31
+ </div>
32
+ </div>
33
+ </header>
34
+ <!-- AI Coach Summary -->
35
+ <ai-coach-card></ai-coach-card>
36
+
37
+ <!-- Hardware Status -->
38
+ <hardware-status></hardware-status>
39
+
40
+ <!-- Main Vitals Grid -->
41
+ <section class="px-4 mb-6">
42
+ <div class="grid grid-cols-3 gap-3">
43
+ <vital-circle
44
+ type="recovery"
45
+ value="82"
46
+ color="from-green-400 to-emerald-500"
47
+ label="การฟื้นตัว">
48
+ </vital-circle>
49
+ <vital-circle
50
+ type="strain"
51
+ value="14.2"
52
+ color="from-orange-400 to-red-500"
53
+ label="ความเครียด"
54
+ max="21">
55
+ </vital-circle>
56
+ <vital-circle
57
+ type="sleep"
58
+ value="78"
59
+ color="from-blue-400 to-indigo-500"
60
+ label="การนอน">
61
+ </vital-circle>
62
+ </div>
63
+ </section>
64
+
65
+ <!-- Quick Log Buttons -->
66
+ <section class="px-4 mb-6">
67
+ <div class="flex gap-3 overflow-x-auto pb-2 -mx-4 px-4">
68
+ <button class="quick-log-btn flex-shrink-0 bg-gradient-to-r from-green-500 to-emerald-600 px-4 py-3 rounded-xl flex items-center gap-2 text-sm font-medium shadow-lg" data-action="food">
69
+ <i data-feather="plus" class="w-4 h-4"></i>
70
+ บันทึกอาหารไทย
71
+ </button>
72
+ <button class="quick-log-btn flex-shrink-0 bg-gradient-to-r from-orange-500 to-red-600 px-4 py-3 rounded-xl flex items-center gap-2 text-sm font-medium shadow-lg" data-action="workout">
73
+ <i data-feather="activity" class="w-4 h-4"></i>
74
+ เริ่มออกกำลัง
75
+ </button>
76
+ <button class="quick-log-btn flex-shrink-0 bg-gradient-to-r from-blue-500 to-indigo-600 px-4 py-3 rounded-xl flex items-center gap-2 text-sm font-medium shadow-lg" data-action="mood">
77
+ <i data-feather="heart" class="w-4 h-4"></i>
78
+ บันทึกอารมณ์
79
+ </button>
80
+ <button class="quick-log-btn flex-shrink-0 bg-gradient-to-r from-purple-500 to-pink-600 px-4 py-3 rounded-xl flex items-center gap-2 text-sm font-medium shadow-lg" data-action="water">
81
+ <i data-feather="droplet" class="w-4 h-4"></i>
82
+ ดื่มน้ำ
83
+ </button>
84
+ <button class="quick-log-btn flex-shrink-0 bg-gradient-to-r from-yellow-500 to-orange-600 px-4 py-3 rounded-xl flex items-center gap-2 text-sm font-medium shadow-lg" data-action="meditation">
85
+ <i data-feather="moon" class="w-4 h-4"></i>
86
+ นั่งสมาธิ
87
+ </button>
88
+ </div>
89
+ </section>
90
+
91
+ <!-- Mood Logger -->
92
+ <mood-logger></mood-logger>
93
+ <!-- Today's Data -->
94
+ <section class="px-4 mb-6">
95
+ <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
96
+ <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
97
+ <i data-feather="activity" class="w-5 h-5 text-green-400"></i>
98
+ ข้อมูลวันนี้
99
+ </h3>
100
+
101
+ <!-- Heart Rate Chart -->
102
+ <div class="mb-6">
103
+ <div class="flex justify-between items-center mb-3">
104
+ <span class="text-sm text-gray-400">อัตราการเต้นหัวใจ</span>
105
+ <span class="text-sm font-medium">68 bpm</span>
106
+ </div>
107
+ <canvas id="hrChart" height="120"></canvas>
108
+ </div>
109
+
110
+ <!-- Stats Grid -->
111
+ <div class="grid grid-cols-2 gap-4">
112
+ <div class="stat-card bg-gray-800/50 rounded-xl p-4 border border-gray-700/30">
113
+ <div class="flex items-center justify-between">
114
+ <div>
115
+ <p class="text-gray-400 text-xs">แคลอรีทั้งหมด</p>
116
+ <p class="text-xl font-bold">1,847</p>
117
+ </div>
118
+ <i data-feather="zap" class="w-6 h-6 text-orange-400"></i>
119
+ </div>
120
+ <div class="mt-2 bg-gray-700 rounded-full h-2">
121
+ <div class="bg-gradient-to-r from-green-400 to-emerald-500 h-2 rounded-full" style="width: 73%"></div>
122
+ </div>
123
+ </div>
124
+ <div class="stat-card bg-gray-800/50 rounded-xl p-4 border border-gray-700/30">
125
+ <div class="flex items-center justify-between">
126
+ <div>
127
+ <p class="text-gray-400 text-xs">จำนวนก้าว</p>
128
+ <p class="text-xl font-bold">8,247</p>
129
+ </div>
130
+ <i data-feather="foot-print" class="w-6 h-6 text-blue-400"></i>
131
+ </div>
132
+ <div class="mt-2 bg-gray-700 rounded-full h-2">
133
+ <div class="bg-gradient-to-r from-blue-400 to-indigo-500 h-2 rounded-full" style="width: 82%"></div>
134
+ </div>
135
+ </div>
136
+ </div>
137
+ </div>
138
+ </section>
139
+ <!-- Enhanced Meal Logger -->
140
+ <meal-logger-enhanced></meal-logger-enhanced>
141
+
142
+ <!-- Activity Summary -->
143
+ <section class="px-4 mb-6">
144
+ <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
145
+ <h3 class="text-lg font-semibold mb-4 flex items-center gap-2">
146
+ <i data-feather="zap" class="w-5 h-5 text-yellow-400"></i>
147
+ กิจกรรมแนะนำวันนี้
148
+ </h3>
149
+ <div class="space-y-3">
150
+ <div class="flex items-center justify-between p-3 bg-gray-800/30 rounded-xl">
151
+ <div class="flex items-center gap-3">
152
+ <div class="w-10 h-10 bg-gradient-to-r from-red-500 to-pink-600 rounded-lg flex items-center justify-center">
153
+ <span class="text-xl">🥊</span>
154
+ </div>
155
+ <div>
156
+ <p class="font-medium text-sm">มวยไทย</p>
157
+ <p class="text-xs text-gray-400">ระดับความหนักปานกลาง • 45 นาที</p>
158
+ </div>
159
+ </div>
160
+ <div class="text-right">
161
+ <p class="text-sm font-medium text-orange-400">คาดเผาผลาญ 450 แคล</p>
162
+ <p class="text-xs text-green-400">เหมาะกับค่าฟื้นตัวของคุณ</p>
163
+ </div>
164
+ </div>
165
+ <div class="flex items-center justify-between p-3 bg-gray-800/30 rounded-xl">
166
+ <div class="flex items-center gap-3">
167
+ <div class="w-10 h-10 bg-gradient-to-r from-blue-500 to-indigo-600 rounded-lg flex items-center justify-center">
168
+ <span class="text-xl">🧘</span>
169
+ </div>
170
+ <div>
171
+ <p class="font-medium text-sm">โยคะคลายเครียด</p>
172
+ <p class="text-xs text-gray-400">ระดับเบา • 30 นาที</p>
173
+ </div>
174
+ </div>
175
+ <div class="text-right">
176
+ <p class="text-sm font-medium text-blue-400">คาดเผาผลาญ 120 แคล</p>
177
+ <p class="text-xs text-purple-400">ช่วยลดความเครียดสะสม</p>
178
+ </div>
179
+ </div>
180
+ </div>
181
+ </div>
182
+ </section>
183
+
184
+ <!-- Community & Challenges -->
185
+ <section class="px-4 mb-6">
186
+ <div class="glass-card rounded-2xl p-5 border border-gray-700/50">
187
+ <div class="flex justify-between items-center mb-4">
188
+ <h3 class="text-lg font-semibold flex items-center gap-2">
189
+ <i data-feather="users" class="w-5 h-5 text-purple-400"></i>
190
+ ทีม & ความท้าทาย
191
+ </h3>
192
+ <span class="text-xs bg-gradient-to-r from-purple-500 to-pink-600 text-white px-2 py-1 rounded-full">ใหม่</span>
193
+ </div>
194
+
195
+ <div class="space-y-3">
196
+ <div class="p-3 bg-gradient-to-r from-purple-500/20 to-pink-600/20 rounded-xl border border-purple-500/30">
197
+ <div class="flex items-center justify-between mb-2">
198
+ <p class="font-medium text-sm">ท้าทาย: นอนให้ครบ 8 ชม.</p>
199
+ <span class="text-xs text-purple-400">5 วันเหลือ</span>
200
+ </div>
201
+ <div class="flex items-center gap-2">
202
+ <div class="flex-1 bg-gray-700 rounded-full h-2">
203
+ <div class="bg-purple-400 h-2 rounded-full" style="width: 75%"></div>
204
+ </div>
205
+ <span class="text-xs font-medium">5/7</span>
206
+ </div>
207
+ <p class="text-xs text-gray-400 mt-1">ทีม: ชาวออฟฟิศสุขภาพดี</p>
208
+ </div>
209
+
210
+ <div class="p-3 bg-gray-800/30 rounded-xl">
211
+ <div class="flex items-center gap-3">
212
+ <div class="w-8 h-8 bg-gradient-to-r from-yellow-500 to-orange-500 rounded-full flex items-center justify-center text-sm font-bold">
213
+ 2
214
+ </div>
215
+ <div class="flex-1">
216
+ <p class="text-sm font-medium">อันดับในทีม</p>
217
+ <p class="text-xs text-gray-400">จาก 15 คน • Recovery เฉลี่ย 78%</p>
218
+ </div>
219
+ <div class="text-right">
220
+ <p class="text-sm font-medium text-yellow-400">1,247 คะแนน</p>
221
+ </div>
222
+ </div>
223
+ </div>
224
+ </div>
225
+ </div>
226
+ </section>
227
+ </div>
228
+
229
+ <!-- Bottom Navigation -->
230
+ <main-navbar></main-navbar>
231
+ <!-- Scripts -->
232
+ <script src="components/navbar.js"></script>
233
+ <script src="components/ai-coach-card.js"></script>
234
+ <script src="components/vital-circle.js"></script>
235
+ <script src="components/hardware-status.js"></script>
236
+ <script src="components/mood-logger.js"></script>
237
+ <script src="components/meal-logger-enhanced.js"></script>
238
+ <script src="script.js"></script>
239
+ <script>feather.replace();</script>
240
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
241
+ </body>
242
+ </html>
script.js ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Global App State
2
+ const AppState = {
3
+ currentUser: {
4
+ name: 'พิมพ์',
5
+ recovery: 78,
6
+ strain: 12.5,
7
+ sleep: 82,
8
+ heartRate: 68
9
+ },
10
+
11
+ // Mock data for chart
12
+ heartRateData: {
13
+ labels: ['00:00', '04:00', '08:00', '12:00', '16:00', '20:00', '24:00'],
14
+ datasets: [{
15
+ label: 'Heart Rate',
16
+ data: [58, 62, 75, 82, 78, 70, 62],
17
+ borderColor: '#34d399',
18
+ backgroundColor: 'rgba(52, 211, 153, 0.1)',
19
+ tension: 0.4,
20
+ fill: true,
21
+ pointRadius: 0,
22
+ pointHoverRadius: 6
23
+ }]
24
+ }
25
+ };
26
+
27
+ // Initialize Heart Rate Chart
28
+ function initHeartRateChart() {
29
+ const ctx = document.getElementById('hrChart');
30
+ if (!ctx) return;
31
+
32
+ new Chart(ctx, {
33
+ type: 'line',
34
+ data: AppState.heartRateData,
35
+ options: {
36
+ responsive: true,
37
+ maintainAspectRatio: false,
38
+ plugins: {
39
+ legend: { display: false },
40
+ tooltip: {
41
+ backgroundColor: 'rgba(17, 24, 39, 0.9)',
42
+ titleColor: '#34d399',
43
+ bodyColor: '#e5e7eb',
44
+ borderColor: '#34d399',
45
+ borderWidth: 1,
46
+ callbacks: {
47
+ label: (context) => `${context.parsed.y} bpm`
48
+ }
49
+ }
50
+ },
51
+ scales: {
52
+ x: {
53
+ grid: { display: false },
54
+ ticks: {
55
+ color: '#9ca3af',
56
+ font: { family: 'Prompt' }
57
+ }
58
+ },
59
+ y: {
60
+ grid: {
61
+ color: 'rgba(75, 85, 99, 0.3)',
62
+ borderDash: [5, 5]
63
+ },
64
+ ticks: {
65
+ color: '#9ca3af',
66
+ font: { family: 'Prompt' }
67
+ }
68
+ }
69
+ },
70
+ interaction: {
71
+ intersect: false,
72
+ mode: 'index'
73
+ }
74
+ }
75
+ });
76
+ }
77
+
78
+ // Simulate Real-time Heart Rate Updates
79
+ function simulateRealtimeHR() {
80
+ const hrElement = document.querySelector('.text-sm.font-medium');
81
+ if (!hrElement) return;
82
+
83
+ setInterval(() => {
84
+ const variation = Math.floor(Math.random() * 10) - 5;
85
+ const newHR = Math.max(55, Math.min(85, AppState.currentUser.heartRate + variation));
86
+ hrElement.textContent = `${newHR} bpm`;
87
+ }, 3000);
88
+ }
89
+
90
+ // Quick Log Button Actions
91
+ function setupQuickLogButtons() {
92
+ const buttons = document.querySelectorAll('.quick-log-btn');
93
+
94
+ buttons.forEach(button => {
95
+ button.addEventListener('click', function() {
96
+ // Add ripple effect
97
+ const ripple = document.createElement('div');
98
+ ripple.className = 'absolute inset-0 bg-white/20 rounded-xl animate-ping';
99
+ this.appendChild(ripple);
100
+
101
+ setTimeout(() => ripple.remove(), 600);
102
+
103
+ // Show Thai notification
104
+ const text = this.textContent.trim();
105
+ showNotification(`กำลังบันทึก: ${text}...`, 'success');
106
+ });
107
+ });
108
+ }
109
+
110
+ // Notification System
111
+ function showNotification(message, type = 'info') {
112
+ const notification = document.createElement('div');
113
+ notification.className = `fixed top-4 left-4 right-4 z-50 p-4 rounded-xl shadow-lg transform translate-y-[-100px] opacity-0 transition-all duration-300 ${
114
+ type === 'success' ? 'bg-green-500' :
115
+ type === 'error' ? 'bg-red-500' : 'bg-blue-500'
116
+ }`;
117
+ notification.textContent = message;
118
+
119
+ document.body.appendChild(notification);
120
+
121
+ // Animate in
122
+ setTimeout(() => {
123
+ notification.style.transform = 'translateY(0)';
124
+ notification.style.opacity = '1';
125
+ }, 100);
126
+
127
+ // Remove after 3 seconds
128
+ setTimeout(() => {
129
+ notification.style.transform = 'translateY(-100px)';
130
+ notification.style.opacity = '0';
131
+ setTimeout(() => notification.remove(), 300);
132
+ }, 3000);
133
+ }
134
+
135
+ // Animate elements on scroll
136
+ function setupScrollAnimations() {
137
+ const observer = new IntersectionObserver((entries) => {
138
+ entries.forEach(entry => {
139
+ if (entry.isIntersecting) {
140
+ entry.target.classList.add('animate-fadeInUp');
141
+ }
142
+ });
143
+ }, { threshold: 0.1 });
144
+
145
+ document.querySelectorAll('.glass-card').forEach(card => {
146
+ observer.observe(card);
147
+ });
148
+ }
149
+
150
+ // AI Coach Dynamic Messages
151
+ function updateAICoachMessage() {
152
+ const messages = [
153
+ "วันนี้คุณฟื้นตัวเต็มที่! เหมาะสำหรับการออกกำลังกายระดับกลาง-หนัก อย่าลืมทานอาหารให้คร��� 5 หมู่นะคะ",
154
+ "ค่า HRV ของคุณดีขึ้น 15% จากสัปดาห์ที่แล้ว! แสดงว่าร่างกายกำลังฟื้นตัวได้ดีมากเลยค่ะ",
155
+ "พบว่าคืนที่คุณดื่มกาแฟหลัง 3 ทุ่ม คุณภาพการนอนจะลดลง 30% ลองเลี่ยงดื่มกาแฟในช่วงบ่ายดูนะคะ",
156
+ "วันนี้ความเครียดสะสมอยู่ในระดับปานกลาง แนะนำให้นั่งสมาธิ 10 นาทีก่อนนอนเพื่อลดระดับคอร์ติซอลค่ะ"
157
+ ];
158
+
159
+ const coachCard = document.querySelector('ai-coach-card');
160
+ if (coachCard && Math.random() > 0.7) {
161
+ const randomMessage = messages[Math.floor(Math.random() * messages.length)];
162
+ coachCard.updateMessage(randomMessage);
163
+ }
164
+ }
165
+
166
+ // Hardware Pairing Simulation
167
+ function simulateHardwareConnection() {
168
+ const devices = [
169
+ { name: 'Apple Watch Series 9', connected: true },
170
+ { name: 'Oura Ring Gen 3', connected: false },
171
+ { name: 'Polar H10', connected: false }
172
+ ];
173
+
174
+ // Check if hardware is connected
175
+ const connectedDevice = devices.find(d => d.connected);
176
+ if (connectedDevice) {
177
+ console.log(`เชื่อมต่อกับ ${connectedDevice.name} เรียบร้อยแล้ว`);
178
+ }
179
+ }
180
+
181
+ // Office Syndrome Alert
182
+ function setupSedentaryAlert() {
183
+ let sittingTime = 0;
184
+
185
+ setInterval(() => {
186
+ // Simulate sedentary behavior (in real app, use accelerometer data)
187
+ const isSitting = Math.random() > 0.3;
188
+
189
+ if (isSitting) {
190
+ sittingTime += 1;
191
+
192
+ if (sittingTime >= 60) { // 1 hour
193
+ showOfficeSyndromeAlert();
194
+ sittingTime = 0;
195
+ }
196
+ } else {
197
+ sittingTime = 0;
198
+ }
199
+ }, 60000); // Check every minute
200
+ }
201
+
202
+ function showOfficeSyndromeAlert() {
203
+ const alert = document.createElement('div');
204
+ alert.className = 'fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4';
205
+ alert.innerHTML = `
206
+ <div class="glass-card rounded-2xl p-6 max-w-sm w-full border border-gray-700/50">
207
+ <div class="text-center">
208
+ <div class="w-16 h-16 bg-red-500 rounded-full mx-auto mb-4 flex items-center justify-center pulse-animation">
209
+ <i data-feather="alert-circle" class="w-8 h-8 text-white"></i>
210
+ </div>
211
+ <h3 class="text-xl font-bold mb-2">เตือนภัย Office Syndrome!</h3>
212
+ <p class="text-gray-400 mb-4">คุณนั่งนิ่งนานเกิน 1 ชั่วโมงแล้ว ลุกขึ้นมายืดเส้นยืดสายกันดีกว่าค่ะ</p>
213
+ <div class="flex gap-3">
214
+ <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-700 hover:bg-gray-600 py-3 rounded-xl font-medium transition-colors">
215
+ เลื่อนไปก่อน
216
+ </button>
217
+ <button onclick="startMicroWorkout(); this.closest('.fixed').remove()" class="flex-1 bg-gradient-to-r from-green-500 to-emerald-600 py-3 rounded-xl font-medium transition-all hover:scale-[1.02]">
218
+ เริ่มเลย!
219
+ </button>
220
+ </div>
221
+ </div>
222
+ </div>
223
+ `;
224
+
225
+ document.body.appendChild(alert);
226
+ feather.replace();
227
+
228
+ // Auto close after 30 seconds
229
+ setTimeout(() => alert.remove(), 30000);
230
+ }
231
+
232
+ function startMicroWorkout() {
233
+ showNotification('กำลังเปิดวิดีโอท่ายืดเหยียด...', 'success');
234
+ // In real app, would open video player
235
+ }
236
+
237
+ // Initialize App
238
+ document.addEventListener('DOMContentLoaded', function() {
239
+ // Set initial animations
240
+ document.querySelectorAll('section').forEach((section, index) => {
241
+ section.style.animationDelay = `${index * 0.1}s`;
242
+ section.classList.add('animate-fadeInUp');
243
+ });
244
+
245
+ // Initialize components
246
+ initHeartRateChart();
247
+ simulateRealtimeHR();
248
+ setupQuickLogButtons();
249
+ setupScrollAnimations();
250
+ simulateHardwareConnection();
251
+
252
+ // Simulate periodic updates
253
+ setInterval(updateAICoachMessage, 10000);
254
+ setTimeout(setupSedentaryAlert, 5000); // Start checking after 5 seconds
255
+
256
+ // Request permissions (in real app)
257
+ console.log('กำลังขอสิทธิ์เข้าถึงข้อมูลสุขภาพ...');
258
+
259
+ // Show welcome notification
260
+ setTimeout(() => {
261
+ showNotification('ยินดีต้อนรับสู่ ชีพจร! AI กำลังวิเคราะห์ข้อมูลของคุณ...', 'success');
262
+ }, 1000);
263
+ });
264
+
265
+ // Export for other modules
266
+ window.AppState = AppState;
267
+ window.showNotification = showNotification;
style.css CHANGED
@@ -1,28 +1,137 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
 
 
 
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Custom Thai Font */
2
+ @import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');
3
+
4
+ * {
5
+ font-family: 'Prompt', sans-serif;
6
+ }
7
+
8
+ /* Glassmorphism Effect */
9
+ .glass-card {
10
+ background: rgba(31, 41, 55, 0.4);
11
+ backdrop-filter: blur(12px);
12
+ -webkit-backdrop-filter: blur(12px);
13
+ transition: all 0.3s ease;
14
+ }
15
+
16
+ .glass-card:hover {
17
+ background: rgba(31, 41, 55, 0.6);
18
+ border-color: rgba(75, 85, 99, 0.5);
19
+ }
20
+
21
+ /* Custom Scrollbar */
22
+ ::-webkit-scrollbar {
23
+ width: 6px;
24
+ height: 6px;
25
+ }
26
+
27
+ ::-webkit-scrollbar-track {
28
+ background: rgba(17, 24, 39, 0.5);
29
+ }
30
+
31
+ ::-webkit-scrollbar-thumb {
32
+ background: linear-gradient(45deg, #34d399, #10b981);
33
+ border-radius: 10px;
34
+ }
35
+
36
+ /* Smooth Animations */
37
+ @keyframes fadeInUp {
38
+ from {
39
+ opacity: 0;
40
+ transform: translateY(30px);
41
+ }
42
+ to {
43
+ opacity: 1;
44
+ transform: translateY(0);
45
+ }
46
+ }
47
+
48
+ @keyframes pulse {
49
+ 0% { transform: scale(1); }
50
+ 50% { transform: scale(1.05); }
51
+ 100% { transform: scale(1); }
52
+ }
53
+
54
+ .animate-fadeInUp {
55
+ animation: fadeInUp 0.6s ease-out;
56
  }
57
 
58
+ .pulse-animation {
59
+ animation: pulse 2s infinite;
 
60
  }
61
 
62
+ /* Quick Log Buttons */
63
+ .quick-log-btn {
64
+ transition: all 0.3s ease;
65
+ position: relative;
66
+ overflow: hidden;
67
  }
68
 
69
+ .quick-log-btn::before {
70
+ content: '';
71
+ position: absolute;
72
+ top: 0;
73
+ left: -100%;
74
+ width: 100%;
75
+ height: 100%;
76
+ background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
77
+ transition: left 0.5s;
78
  }
79
 
80
+ .quick-log-btn:hover::before {
81
+ left: 100%;
82
  }
83
+
84
+ .quick-log-btn:active {
85
+ transform: scale(0.95);
86
+ }
87
+
88
+ /* Vital Circle Hover Effect */
89
+ vital-circle {
90
+ transition: transform 0.3s ease;
91
+ }
92
+
93
+ vital-circle:hover {
94
+ transform: translateY(-5px);
95
+ }
96
+
97
+ /* AI Coach Card Typing Effect */
98
+ .ai-typing::after {
99
+ content: '...';
100
+ animation: dots 1.5s infinite;
101
+ }
102
+
103
+ @keyframes dots {
104
+ 0%, 20% { content: '.'; }
105
+ 40% { content: '..'; }
106
+ 60%, 100% { content: '...'; }
107
+ }
108
+
109
+ /* Chart Canvas */
110
+ canvas {
111
+ max-width: 100%;
112
+ height: auto !important;
113
+ }
114
+
115
+ /* Mobile Optimizations */
116
+ @media (max-width: 640px) {
117
+ .glass-card {
118
+ border-radius: 1rem;
119
+ }
120
+
121
+ .quick-log-btn {
122
+ font-size: 0.8rem;
123
+ padding: 0.75rem 1rem;
124
+ }
125
+ }
126
+
127
+ /* Loading State */
128
+ .loading-skeleton {
129
+ background: linear-gradient(90deg, #1f2937 25%, #374151 50%, #1f2937 75%);
130
+ background-size: 200% 100%;
131
+ animation: loading 1.5s infinite;
132
+ }
133
+
134
+ @keyframes loading {
135
+ 0% { background-position: 200% 0; }
136
+ 100% { background-position: -200% 0; }
137
+ }