const ProteinCalculatorExtension = { name: 'ext_protein_calculator_v2', // Changed name slightly to avoid cache issues if needed type: 'response', match: ({ trace }) => { if (!trace) return false; return ( trace.type === 'ext_protein_calculator_v2' || (trace.payload && trace.payload.name === 'ext_protein_calculator_v2') ) && trace.type !== 'typing'; }, render: ({ trace, element }) => { const container = document.createElement('div'); container.classList.add('procalc-container'); // Unique namespace // --- State Variables --- let currentStep = 1; const formData = { gender: '', age: '25', weight: '70', height: '170', activityLevel: '', goal: '' }; let result = null; let isCalculating = false; // To show loading state // --- HTML Structure --- container.innerHTML = `
أدخل معلوماتك لحساب احتياجك من البروتين.
حدد مستوى نشاطك اليومي.
اختر هدفك الرئيسي لتخصيص كمية البروتين.
حدث خطأ أثناء الحساب. يرجى التحقق من المدخلات.
"; currentStep = 4; // Still go to results step to show error updateView(); } }, 1500); // Simulate 1.5 seconds calculation time } // --- Display Results --- function displayResults() { if (!result) return; const radius = 80; // Circle radius const circumference = 2 * Math.PI * radius; // Calculate offset based on protein percentage (max 100%) const progressOffset = circumference - (Math.min(result.proteinPercentage, 100) / 100) * circumference; resultsArea.innerHTML = `