/** * UI Rendering — all DOM construction and manipulation */ (function () { 'use strict'; var App = window.BenchmarkApp; var TIER_COLORS = { A: { bg: '#E8F5E9', text: '#4CAF50', border: '#4CAF50' }, B: { bg: '#FFF3E0', text: '#FF9800', border: '#FF9800' }, C: { bg: '#FFEBEE', text: '#F44336', border: '#F44336' } }; var SUB_TIER_LABELS = ['C-', 'C', 'C+', 'B-', 'B', 'B+', 'A-', 'A', 'A+']; // Map sub-tier index from thresholds (0=A+, 8=C-) to scale position (0=C-, 8=A+) function subTierToScalePosition(thresholdIndex) { return 8 - thresholdIndex; } // --- Fallback Screen --- App.renderFallbackScreen = function () { var app = document.getElementById('app'); app.innerHTML = '
' + '
' + '' + '' + '' + '
' + '

Benchmark Report Unavailable

' + '

Please fill out the benchmark form first to generate your personalized report.

' + 'Go to Benchmark Form' + '
'; }; // --- Tier Block --- App.renderTierBlock = function (scoring, params) { var section = document.getElementById('tier-section'); var tier = scoring.tier; var colors = TIER_COLORS[tier]; var industryLabel = App.INDUSTRY_LABELS[params.industry]; var scalePos = subTierToScalePosition(scoring.subTierIndex); // Build scale segments HTML var scaleHtml = ''; // YOU marker var markerLeft = ((scalePos + 0.5) / 9 * 100).toFixed(1); var markerHtml = '
' + '
' + 'YOU' + '
' + '
' + '
'; // Metrics summary var metricsHtml = '
'; var metricDisplays = [ { key: 'revenue', label: 'Revenue', displayValue: App.REVENUE_LABELS[params.revenue] }, { key: 'budget', label: 'Marketing Budget', displayValue: App.BUDGET_LABELS[params.budget] }, { key: 'asins', label: 'ASINs', displayValue: params.asins.toLocaleString() }, { key: 'growth', label: 'YoY Growth', displayValue: App.GROWTH_LABELS[params.growth] } ]; for (var j = 0; j < metricDisplays.length; j++) { var m = metricDisplays[j]; var mData = scoring.metrics[m.key]; var mColors = TIER_COLORS[mData.tierLetter]; metricsHtml += '
' + '' + m.label + '' + '' + m.displayValue + '' + '' + mData.subTier + '' + '
'; } metricsHtml += '
'; section.innerHTML = '
' + '
' + '

' + params.company + ' in ' + industryLabel + '

' + '
' + '
' + '' + tier + '' + '
' + '
' + '' + scoring.subTier + '' + 'Score: ' + scoring.weightedScore.toFixed(2) + '' + '
' + '
' + '
' + '
' + markerHtml + scaleHtml + '
' + metricsHtml + '
'; }; // --- Recommendation Cards --- App.renderRecommendationCards = function (recommendations, tier) { var section = document.getElementById('recommendations-section'); var leverOrder = ['ppc', 'listing', 'seo', 'account']; // Sort by rank leverOrder.sort(function (a, b) { return recommendations[a].rank - recommendations[b].rank; }); var html = '

Growth Recommendations

'; for (var i = 0; i < leverOrder.length; i++) { var key = leverOrder[i]; var rec = recommendations[key]; var config = App.LEVER_CONFIG[key]; var desc = App.LEVER_DESCRIPTIONS[key][tier]; var fillPct = Math.min(100, (rec.score / 0.75 * 100)).toFixed(0); var priorityClass = 'priority-' + rec.priority.toLowerCase(); html += '
' + '
' + '#' + rec.rank + '' + '' + rec.priority + '' + '
' + '

' + config.label + '

' + '

' + desc + '

' + '
' + '
' + '
' + '
'; } html += '
'; section.innerHTML = html; }; // --- Placeholder Shimmer Tables --- App.renderPlaceholderTables = function () { var section = document.getElementById('top3-section'); var tiers = ['A', 'B', 'C']; var html = ''; for (var t = 0; t < tiers.length; t++) { var colors = TIER_COLORS[tiers[t]]; html += '
' + '

Segment ' + tiers[t] + ' — Top Players

' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; } section.innerHTML = html; }; // --- Email Gate Overlay --- App.renderEmailGate = function () { var container = document.getElementById('gate-overlay'); container.innerHTML = ''; }; // --- Top-3 Tables (real data) --- App.renderTop3Tables = function (topCompanies, userCompany) { var section = document.getElementById('top3-section'); var tiers = ['A', 'B', 'C']; var html = ''; for (var t = 0; t < tiers.length; t++) { var tierKey = tiers[t]; var companies = topCompanies[tierKey] || []; var colors = TIER_COLORS[tierKey]; html += '
' + '

Segment ' + tierKey + ' — Top Players

' + '
' + '' + '' + '' + ''; for (var r = 0; r < companies.length; r++) { var c = companies[r]; var isUser = userCompany && c.brand.toLowerCase() === userCompany.toLowerCase(); html += '' + '' + '' + '' + '' + '' + '' + ''; } html += '
#BrandRevenueASINsYoY GrowthAd Budget
' + c.rank + '' + c.brand + (c.parent ? ' (' + c.parent + ')' : '') + (isUser ? ' YOU' : '') + '' + c.revenue + '' + c.asins + '' + c.yoy + '' + c.budget + '
'; } section.innerHTML = html; }; // --- Blur Control --- App.applyBlur = function () { var gated = document.getElementById('gated-content'); gated.classList.add('blurred'); document.getElementById('gate-overlay').classList.add('visible'); }; App.removeBlur = function () { var gated = document.getElementById('gated-content'); gated.classList.remove('blurred'); document.getElementById('gate-overlay').classList.remove('visible'); document.querySelector('.gated-wrapper').classList.add('unlocked'); }; // --- Loading Spinner --- App.showSpinner = function () { var btn = document.getElementById('gate-submit'); btn.disabled = true; btn.innerHTML = ' Unlocking...'; }; App.hideSpinner = function () { var btn = document.getElementById('gate-submit'); btn.disabled = false; btn.textContent = 'Unlock Full Report'; }; // --- Gate Error Message --- App.showGateError = function (msg) { document.getElementById('gate-error').textContent = msg; }; App.clearGateError = function () { document.getElementById('gate-error').textContent = ''; }; // --- Fallback message for failed webhook --- App.showFallbackMessage = function (email) { var section = document.getElementById('top3-section'); section.innerHTML = '
' + '

Your full report with industry leaders will be sent to ' + email + ' shortly.

' + '
'; }; })();