// Tab switching functionality function switchTab(tabName) { // Hide all tab contents const tabContents = document.querySelectorAll('.tab-content'); tabContents.forEach(content => { content.classList.add('hidden'); }); // Show selected tab const selectedTab = document.getElementById(tabName); if (selectedTab) { selectedTab.classList.remove('hidden'); } // Update tab button colors const tabButtons = document.querySelectorAll('.tab-btn'); tabButtons.forEach(btn => { btn.classList.remove('text-green-600'); btn.classList.add('text-gray-600'); }); // Highlight active tab button const activeBtn = document.querySelector(`button[onclick="switchTab('${tabName}')"]`); if (activeBtn) { activeBtn.classList.remove('text-gray-600'); activeBtn.classList.add('text-green-600'); } // Re-initialize feather icons feather.replace(); // Initialize chart if graph tab is selected if (tabName === 'graph') { setTimeout(() => initChart(), 100); } } // Chart functionality let healthChart = null; function initChart() { const canvas = document.getElementById('healthChart'); if (!canvas) return; const ctx = canvas.getContext('2d'); // Sample data for 7 days const labels = ['จ.', 'อ.', 'พ.', 'พฤ.', 'ศ.', 'ส.', 'อา.']; const fatData = [29.1, 28.9, 28.8, 28.7, 28.6, 28.5, 28.4]; const muscleData = [30.2, 30.4, 30.5, 30.8, 30.9, 31.0, 31.2]; const weightData = [67.0, 66.8, 66.7, 66.6, 66.5, 66.4, 66.4]; // Simple line chart drawing drawLineChart(ctx, canvas.width, canvas.height, labels, [ { data: fatData, color: '#3B82F6', label: 'ไขมัน %' }, { data: muscleData, color: '#10B981', label: 'กล้ามเนื้อ kg' }, { data: weightData, color: '#8B5CF6', label: 'น้ำหนัก kg' } ]); } function drawLineChart(ctx, width, height, labels, datasets) { // Clear canvas ctx.clearRect(0, 0, width, height); const padding = 40; const graphWidth = width - padding * 2; const graphHeight = height - padding * 2; const dataPoints = labels.length; // Draw axes ctx.strokeStyle = '#E5E7EB'; ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(padding, padding); ctx.lineTo(padding, height - padding); ctx.lineTo(width - padding, height - padding); ctx.stroke(); // Draw grid lines ctx.strokeStyle = '#F3F4F6'; for (let i = 0; i <= 5; i++) { const y = padding + (graphHeight / 5) * i; ctx.beginPath(); ctx.moveTo(padding, y); ctx.lineTo(width - padding, y); ctx.stroke(); } // Draw labels ctx.fillStyle = '#6B7280'; ctx.font = '12px Prompt'; labels.forEach((label, i) => { const x = padding + (graphWidth / (dataPoints - 1)) * i; ctx.fillText(label, x - 10, height - padding + 20); }); // Draw data lines datasets.forEach(dataset => { ctx.strokeStyle = dataset.color; ctx.lineWidth = 2; ctx.beginPath(); dataset.data.forEach((value, i) => { const x = padding + (graphWidth / (dataPoints - 1)) * i; const normalizedValue = (value - Math.min(...dataset.data)) / (Math.max(...dataset.data) - Math.min(...dataset.data)); const y = height - padding - (normalizedValue * graphHeight * 0.8 + graphHeight * 0.1); if (i === 0) { ctx.moveTo(x, y); } else { ctx.lineTo(x, y); } }); ctx.stroke(); // Draw data points dataset.data.forEach((value, i) => { const x = padding + (graphWidth / (dataPoints - 1)) * i; const normalizedValue = (value - Math.min(...dataset.data)) / (Math.max(...dataset.data) - Math.min(...dataset.data)); const y = height - padding - (normalizedValue * graphHeight * 0.8 + graphHeight * 0.1); ctx.fillStyle = dataset.color; ctx.beginPath(); ctx.arc(x, y, 3, 0, Math.PI * 2); ctx.fill(); }); }); } // Update graph based on time range function updateGraph(days) { // Update button styles const buttons = document.querySelectorAll('[onclick^="updateGraph"]'); buttons.forEach(btn => { btn.classList.remove('bg-green-500', 'text-white'); btn.classList.add('bg-gray-200', 'text-gray-700'); }); event.target.classList.remove('bg-gray-200', 'text-gray-700'); event.target.classList.add('bg-green-500', 'text-white'); // Re-initialize chart with new data initChart(); } // Add to cart functionality function addToCart(productName, price) { // Create notification const notification = document.createElement('div'); notification.className = 'fixed top-20 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg z-50'; notification.textContent = `เพิ่ม ${productName} ลงตะกร้าแล้ว`; document.body.appendChild(notification); // Animate in notification.style.animation = 'slideIn 0.3s ease-out'; // Remove after 2 seconds setTimeout(() => { notification.style.animation = 'slideOut 0.3s ease-out'; setTimeout(() => { document.body.removeChild(notification); }, 300); }, 2000); } // Buy now functionality function buyNow(productName, price) { // Create confirmation modal const modal = document.createElement('div'); modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50'; modal.innerHTML = `

ยืนยันการสั่งซื้อ

คุณต้องการสั่งซื้อ ${productName} ในราคา ${price} ใช่หรือไม่?

`; document.body.appendChild(modal); } function confirmPurchase(productName) { // Remove modal document.querySelector('.fixed.inset-0').remove(); // Show success notification const notification = document.createElement('div'); notification.className = 'fixed top-20 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg z-50'; notification.textContent = `สั่งซื้อ ${productName} สำเร็จแล้ว`; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 3000); } // Contact coach functionality function contactCoach() { const modal = document.createElement('div'); modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50'; modal.innerHTML = `

ติดต่อโค้ชแนต

คุณสามารถติดต่อโค้ชได้ผ่านช่องทางต่อไปนี้:

LINE: @wpcoach
โทร: 099-123-4567
Email: coach@wpwellnet.com
`; document.body.appendChild(modal); feather.replace(); } // Animation styles const style = document.createElement('style'); style.textContent = ` @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } } @keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } } `; document.head.appendChild(style); // Initialize on page load document.addEventListener('DOMContentLoaded', function() { feather.replace(); // Add click handlers to product buttons const addButtons = document.querySelectorAll('button:not([onclick])'); addButtons.forEach(btn => { if (btn.textContent.includes('เพิ่มลงตะกร้า')) { const card = btn.closest('.bg-white'); const productName = card.querySelector('h3')?.textContent || 'สินค้า'; btn.onclick = () => addToCart(productName); } else if (btn.textContent.includes('ซื้อทันที')) { const card = btn.closest('.bg-white'); const productName = card.querySelector('h3')?.textContent || 'สินค้า'; const price = card.querySelector('.text-green-600')?.textContent || '฿0'; btn.onclick = () => buyNow(productName, price); } else if (btn.textContent.includes('ปรึกษา')) { btn.onclick = contactCoach; } else if (btn.textContent.includes('ซื้อซ้ำ')) { const product = btn.closest('.flex').querySelector('p.font-medium')?.textContent || 'สินค้า'; btn.onclick = () => buyNow(product, 'ราคาพิเศษ'); } }); // Mission toggle functionality const missionItems = document.querySelectorAll('.flex.items-center.justify-between.p-4'); missionItems.forEach(item => { if (item.textContent.includes('ไม่สำเร็จ')) { item.style.cursor = 'pointer'; item.onclick = function() { if (confirm('ต้องการทำภารกิจนี้ใหม่ใช่หรือไม่?')) { location.reload(); } }; } }); // Subscription reminder buttons const reminderButtons = document.querySelectorAll('.bg-blue-50 button'); reminderButtons.forEach(btn => { btn.onclick = function() { reminderButtons.forEach(b => { b.classList.remove('bg-green-500', 'text-white'); b.classList.add('bg-white'); }); this.classList.remove('bg-white'); this.classList.add('bg-green-500', 'text-white'); const notification = document.createElement('div'); notification.className = 'fixed top-20 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg z-50'; notification.textContent = `ตั้งเตือน ${this.textContent} แล้ว`; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 2000); }; }); });
W
WP WELLNET
ก

ยินดีต้อนรับกลับมา

คุณมีเป้าหมาย: ลดไขมัน 3% ใน 60 วัน

ข้อมูลวันนี้

ไขมัน

28.5%

เป้าหมาย: 25%

กล้ามเนื้อ

31.2 กก.

ตามเป้าหมาย

น้ำหนัก

66.4 กก.

BMR

1,540 kcal

สถานะวันนี้

🔋

เผาผลาญแล้ว

เป้าหมาย 2,000 kcal

1,830 kcal
🏃‍♀️

เดินแล้ว

เป้าหมาย 8,000 ก้าว

6,200 ก้าว

Meal Plan วันนี้

เช้า กลางวัน เย็น