hamed-dashboards/dashboards/ecommerce/app.js

2312 lines
127 KiB
JavaScript
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Executive BI Dashboard Engine v4.0 - Master Edition
* Iranian Ecommerce & Brand Ecosystem Benchmark (1385-1404)
* Standard: Stripe / Linear Executive BI (Pure Light Theme, RTL Vazirmatn)
*/
function getBundle() {
if (typeof window !== 'undefined' && window.bundle) return window.bundle;
if (typeof globalThis !== 'undefined' && globalThis.bundle) return globalThis.bundle;
return {};
}
function parsePersianFloat(str) {
if (str === null || str === undefined) return 0;
const clean = String(str).replace(/[٪%]/g, '').trim();
const english = clean.replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d));
const val = parseFloat(english);
return isNaN(val) ? 0 : val;
}
function toPersianDigits(num) {
if (num === null || num === undefined) return '';
return String(num).replace(/[0-9]/g, d => '۰۱۲۳۴۵۶۷۸۹'[d]);
}
function formatNumber(num) {
if (num === null || num === undefined || isNaN(num)) return '۰';
return Number(num).toLocaleString('fa-IR');
}
function safeStr(val) {
if (val === null || val === undefined) return '';
return String(val);
}
function safeCreateIcons() {
try {
if (typeof lucide !== 'undefined' && typeof lucide.createIcons === 'function') {
lucide.createIcons();
}
} catch (e) {
console.warn("Lucide icon generation skipped:", e);
}
}
// -------------------------------------------------------------
// 1. BRAND MARKET INTELLIGENCE & LOST OPPORTUNITY (FLAGSHIP)
// -------------------------------------------------------------
// -------------------------------------------------------------
// 0. TOTAL COMMERCE & PHYSICAL RETAIL INTELLIGENCE (NEW)
// -------------------------------------------------------------
function renderTotalCommerceIntelligence() {
try {
const commData = getBundle().total_commerce_intelligence || {};
const channels = commData.commerce_channels || [];
const sectors = commData.commerce_sectors || [];
const pillars = commData.commerce_pillars || [];
// 0.1 Channels Table
const chTbody = document.getElementById('total-commerce-channels-tbody');
if (chTbody && channels.length > 0) {
chTbody.innerHTML = channels.map(c => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-2.5 font-bold text-slate-900">
<div>${safeStr(c.name)}</div>
<div class="text-[10px] text-slate-400 mt-0.5">${safeStr(c.id)}</div>
</td>
<td class="p-2.5 text-center font-black text-slate-900 tnum">
${formatNumber(c.volume_irr_t)} همت
</td>
<td class="p-2.5 text-center font-bold ${c.share_pct > 50 ? 'text-amber-700 font-black text-sm' : (c.share_pct > 15 ? 'text-indigo-700 font-black' : 'text-rose-700')} tnum">
${c.share_pct}٪
</td>
<td class="p-2.5 text-[11px] text-slate-600 leading-relaxed">
<div class="text-slate-800 font-medium">${safeStr(c.characteristics)}</div>
<div class="text-[10px] text-emerald-700 mt-1 font-semibold">✓ مزیت: ${safeStr(c.advantages)}</div>
<div class="text-[10px] text-rose-600 mt-0.5">✗ چالش: ${safeStr(c.weaknesses)}</div>
</td>
</tr>
`).join('');
}
// 0.2 Sectors Table
const secTbody = document.getElementById('total-commerce-sectors-tbody');
if (secTbody && sectors.length > 0) {
secTbody.innerHTML = sectors.map(s => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3 font-bold text-slate-900">
${safeStr(s.sector)}
</td>
<td class="p-3 text-center font-black text-slate-900 tnum">
${formatNumber(s.total_commerce_irr_t)} همت
</td>
<td class="p-3 text-center tnum">
<div class="font-black text-amber-800 text-xs">${s.traditional_share_pct}٪</div>
<div class="text-[10px] text-slate-400 mt-0.5">${formatNumber(s.traditional_bazaar_irr_t)} همت</div>
</td>
<td class="p-3 text-center tnum">
<div class="font-bold text-indigo-700 text-xs">${s.modern_share_pct}٪</div>
<div class="text-[10px] text-slate-400 mt-0.5">${formatNumber(s.modern_retail_irr_t)} همت</div>
</td>
<td class="p-3 text-center tnum">
<div class="font-bold text-rose-700 text-xs">${s.digital_share_pct}٪</div>
<div class="text-[10px] text-slate-400 mt-0.5">${formatNumber(s.digital_online_irr_t)} همت</div>
</td>
<td class="p-3 text-xs text-slate-700 max-w-xs leading-relaxed">
${safeStr(s.hub_locations)}
</td>
<td class="p-3 text-xs text-slate-600 max-w-xs leading-relaxed">
${safeStr(s.payment_dynamics)}
</td>
<td class="p-3 text-center">
<div class="space-y-1">
<a href="${s.source_url}" target="_blank" class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-emerald-50 hover:bg-emerald-100 text-emerald-800 hover:text-emerald-950 border border-emerald-200 text-[11px] font-bold transition shadow-xs">
<span>${safeStr(s.source_doc || 'سند رسمی')}</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
<div class="text-[10px] text-slate-400 leading-tight">
${safeStr(s.source_name)}
</div>
</div>
</td>
</tr>
`).join('');
}
// 0.3 4 Pillars Grid
const pilGrid = document.getElementById('total-commerce-pillars-grid');
if (pilGrid && pillars.length > 0) {
pilGrid.innerHTML = pillars.map(p => `
<div class="card-executive p-5 space-y-3 bg-white border border-slate-200 flex flex-col justify-between">
<div class="space-y-2">
<div class="flex items-center justify-between">
<span class="p-2 rounded-xl bg-slate-100 text-slate-700">
<i data-lucide="${p.icon || 'layers'}" class="w-4 h-4"></i>
</span>
<span class="p-1 px-2 rounded-md bg-slate-50 border border-slate-200 text-[10px] font-mono font-bold text-slate-600">
${safeStr(p.id)}
</span>
</div>
<h5 class="text-sm font-black text-slate-900 leading-tight">${safeStr(p.title)}</h5>
<p class="text-[11px] font-bold text-slate-500 leading-snug">${safeStr(p.subtitle)}</p>
<p class="text-xs text-slate-600 leading-relaxed text-justify pt-1">${safeStr(p.description)}</p>
</div>
<div class="pt-3 border-t border-slate-100 flex items-center justify-between text-xs">
<span class="text-slate-500 font-medium">${safeStr(p.kpi_label)}</span>
<span class="font-black text-slate-900 tnum">${safeStr(p.kpi_val)}</span>
</div>
</div>
`).join('');
}
console.log("✓ renderTotalCommerceIntelligence completed");
} catch (e) {
console.error("Error in renderTotalCommerceIntelligence:", e);
}
}
function renderBrandMarketIntelligence() {
try {
const bData = getBundle().brand_market_intelligence || {};
const categories = bData.categories || [];
const platformsShare = bData.platforms_market_share || [];
const brandLogic = bData.brand_market_logic || {};
const logicBreakdown = brandLogic.industry_breakdown || [];
// 1.0.1 Macro Platforms Market Share Table
const macroTbody = document.getElementById('macro-platforms-table-tbody');
if (macroTbody) {
macroTbody.innerHTML = platformsShare.map(p => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-2.5 font-bold text-slate-900">
<div>${safeStr(p.player)}</div>
<div class="text-[10px] text-slate-400 tnum mt-0.5">${safeStr(p.player_en)}</div>
</td>
<td class="p-2.5 text-center font-black text-slate-900 tnum">
${formatNumber(p.gmv_1403_irr_t)} همت
</td>
<td class="p-2.5 text-center font-bold text-emerald-700 tnum">
${p.share_of_goods_online_pct}٪
</td>
<td class="p-2.5 text-center font-bold text-indigo-700 tnum">
${p.share_of_total_online_with_social_pct}٪
</td>
<td class="p-2.5 text-[11px] text-slate-600">
<div class="font-medium text-slate-800">${safeStr(p.primary_focus)}</div>
<div class="text-[10px] text-slate-400 mt-0.5">${safeStr(p.status)}</div>
</td>
</tr>
`).join('');
}
// 1.0.2 Brand Market Calculation Logic Waterfall Table
const logicTbody = document.getElementById('brand-logic-table-tbody');
if (logicTbody) {
logicTbody.innerHTML = logicBreakdown.map(ind => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-2.5 font-bold text-slate-900">
${safeStr(ind.industry)}
</td>
<td class="p-2.5 text-center font-black text-slate-900 tnum">
${formatNumber(ind.total_market_irr_t)} همت
</td>
<td class="p-2.5 text-center font-bold text-indigo-700 tnum">
${ind.brand_penetration_pct}٪
</td>
<td class="p-2.5 text-center font-black text-emerald-700 tnum">
${formatNumber(ind.brand_market_irr_t)} همت
</td>
<td class="p-2.5 text-[11px] text-slate-700 font-medium">
${safeStr(ind.top_brands)}
</td>
<td class="p-2.5 text-[11px] text-slate-600">
${safeStr(ind.logic)}
</td>
</tr>
`).join('');
}
const lostAnalysis = bData.lost_brand_market_analysis || {};
const domesticPipeline = bData.top_domestic_brands_pipeline || [];
// 1.1 Master Reference Table
const tbody = document.getElementById('brand-market-table-tbody');
if (tbody) {
tbody.innerHTML = categories.map(cat => {
const cit = (cat.citations && cat.citations.length > 0) ? cat.citations[0] : null;
return `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3.5 font-bold text-slate-900">
<div>${safeStr(cat.name_fa)}</div>
<div class="text-[10px] text-slate-400 tnum mt-0.5">${safeStr(cat.name_en)}</div>
</td>
<td class="p-3.5 font-black text-slate-900 tnum">
<div>${formatNumber(cat.total_size_irr)} همت</div>
<div class="text-[10px] text-slate-400 tnum mt-0.5">$${cat.total_size_usd}B</div>
</td>
<td class="p-3.5 tnum">
<div class="space-y-0.5">
<div class="font-black text-sm text-emerald-700 leading-none">${cat.official_pct}٪</div>
<div class="text-[11px] text-slate-500 font-semibold leading-tight">${formatNumber(cat.official_irr)} همت</div>
</div>
</td>
<td class="p-3.5 tnum">
<div class="space-y-0.5">
<div class="font-black text-sm text-rose-700 leading-none">${cat.unofficial_pct}٪</div>
<div class="text-[11px] text-slate-500 font-semibold leading-tight">${formatNumber(cat.unofficial_irr)} همت</div>
</div>
</td>
<td class="p-3.5 text-xs text-slate-700 tnum">
<div class="flex items-center gap-1.5 font-medium">
<span class="text-emerald-700 font-bold">${cat.domestic_share_pct}٪ بومی</span>
<span class="text-slate-300">/</span>
<span class="text-rose-700 font-bold">${cat.foreign_share_pct}٪ خارجی</span>
</div>
</td>
<td class="p-3.5 text-xs max-w-xs">
<div class="text-slate-900 font-semibold truncate" title="${(cat.top_domestic_brands || []).join(', ')}">
بومی: ${(cat.top_domestic_brands || []).slice(0, 3).join(', ')}
</div>
<div class="text-slate-500 text-[11px] truncate mt-0.5" title="${(cat.top_foreign_brands || []).join(', ')}">
خارجی: ${(cat.top_foreign_brands || []).slice(0, 3).join(', ')}
</div>
</td>
<td class="p-3.5 text-xs text-slate-600 max-w-xs leading-relaxed">
<div class="line-clamp-2" title="${safeStr(cat.regulatory_drivers)}">${safeStr(cat.regulatory_drivers)}</div>
</td>
<td class="p-3.5">
${cit ? `
<a href="${cit.source_url}" target="_blank" class="inline-flex items-center gap-1 text-[11px] text-rose-700 hover:text-rose-900 font-bold bg-rose-50 hover:bg-rose-100 px-2.5 py-1 rounded-lg border border-rose-200 transition" title="${safeStr(cit.key_quote)}">
<span>سند مصاحبه</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
` : '—'}
</td>
</tr>
`;
}).join('');
}
// 1.2 Category Profile Cards
const catContainer = document.getElementById('brand-market-categories-cards');
if (catContainer) {
catContainer.innerHTML = categories.map(cat => `
<div class="card-executive p-6 space-y-4">
<div class="flex flex-col sm:flex-row sm:items-center justify-between pb-3 border-b border-slate-100 gap-2">
<div>
<h4 class="text-sm font-black text-slate-900">${safeStr(cat.name_fa)}</h4>
<span class="text-[11px] text-slate-400 tnum">${safeStr(cat.name_en)}</span>
</div>
<div class="flex items-center gap-2">
<span class="px-2.5 py-1 rounded-xl bg-slate-100 text-slate-800 text-xs font-black tnum">
ارزش کل: ${formatNumber(cat.total_size_irr)} همت ($${cat.total_size_usd}B)
</span>
</div>
</div>
<div class="space-y-1.5">
<div class="flex justify-between text-xs font-bold">
<span class="text-emerald-700">سهم رسمی: ${cat.official_pct}٪ (${formatNumber(cat.official_irr)} همت)</span>
<span class="text-rose-700">سهم غیررسمی/قاچاق: ${cat.unofficial_pct}٪ (${formatNumber(cat.unofficial_irr)} همت)</span>
</div>
<div class="w-full h-2.5 bg-rose-100 rounded-full overflow-hidden flex">
<div class="bg-emerald-500 h-full rounded-r-full" style="width: ${cat.official_pct}%"></div>
<div class="bg-rose-500 h-full rounded-l-full" style="width: ${cat.unofficial_pct}%"></div>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs pt-1">
<div class="p-3 bg-slate-50/70 rounded-xl border border-slate-100 space-y-1.5">
<span class="font-bold text-emerald-800 flex items-center gap-1">
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
برندهای لیدر بومی (${cat.domestic_share_pct}٪):
</span>
<div class="flex flex-wrap gap-1">
${(cat.top_domestic_brands || []).map(b => `<span class="px-2 py-0.5 bg-white text-slate-700 border border-slate-200 rounded-md text-[11px] font-medium">${b}</span>`).join('')}
</div>
</div>
<div class="p-3 bg-slate-50/70 rounded-xl border border-slate-100 space-y-1.5">
<span class="font-bold text-rose-800 flex items-center gap-1">
<span class="w-2 h-2 rounded-full bg-rose-500"></span>
برندهای رقیب خارجی (${cat.foreign_share_pct}٪):
</span>
<div class="flex flex-wrap gap-1">
${(cat.top_foreign_brands || []).map(b => `<span class="px-2 py-0.5 bg-white text-slate-700 border border-slate-200 rounded-md text-[11px] font-medium">${b}</span>`).join('')}
</div>
</div>
</div>
<div class="space-y-2 text-xs">
<div class="p-3 bg-rose-50/40 rounded-xl border border-rose-100 space-y-1">
<span class="font-bold text-rose-900">روش‌ها و کریدورهای ورود قاچاق:</span>
<p class="text-rose-800 leading-relaxed text-right">${safeStr(cat.smuggling_vectors)}</p>
</div>
<div class="p-3 bg-blue-50/40 rounded-xl border border-blue-100 space-y-1">
<span class="font-bold text-blue-900">سیاست‌های حاکمیتی و محرک‌های رگولاتوری:</span>
<p class="text-blue-800 leading-relaxed text-right">${safeStr(cat.regulatory_drivers)}</p>
</div>
</div>
${(cat.citations && cat.citations.length > 0) ? `
<div class="pt-2 border-t border-slate-100 space-y-2">
<div class="text-[11px] font-bold text-slate-500">اسناد استنادی و مصاحبه‌ها:</div>
${cat.citations.map(cit => `
<div class="p-2.5 rounded-xl bg-slate-50 border border-slate-200/80 flex flex-col sm:flex-row sm:items-center justify-between gap-2 text-xs">
<div class="space-y-0.5">
<div class="font-bold text-slate-900">${safeStr(cit.speaker_entity)}</div>
<div class="text-[11px] text-slate-600 italic">"${safeStr(cit.key_quote)}"</div>
</div>
<a href="${cit.source_url}" target="_blank" class="shrink-0 inline-flex items-center gap-1 text-[11px] text-rose-700 font-bold bg-white hover:bg-rose-50 px-2.5 py-1 rounded-lg border border-slate-200 hover:border-rose-300 transition">
<span>مشاهده سند</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
</div>
`).join('')}
</div>
` : ''}
</div>
`).join('');
}
// 1.3 Smuggling Corridors
const corContainer = document.getElementById('brand-market-corridors-cards');
if (corContainer) {
const corridors = bData.macro_corridors || [];
corContainer.innerHTML = corridors.map(c => `
<div class="card-executive p-5 space-y-3 flex flex-col justify-between">
<div class="space-y-2">
<div class="flex items-center gap-2">
<span class="p-2 rounded-xl bg-rose-50 text-rose-600">
<i data-lucide="truck" class="w-4 h-4"></i>
</span>
<h4 class="text-xs font-black text-slate-900 leading-snug">${safeStr(c.corridor_name)}</h4>
</div>
<div class="text-[11px] space-y-1 text-slate-600">
<div><strong class="text-slate-800">مبادی:</strong> ${safeStr(c.origin)}</div>
<div><strong class="text-slate-800">مقاصد دپو:</strong> ${safeStr(c.target)}</div>
</div>
<div class="p-2.5 bg-slate-50 rounded-xl border border-slate-100 text-[11px] space-y-1">
<span class="font-bold text-slate-700">اقلام غالب:</span>
<div class="text-slate-600 font-medium">${safeStr(c.dominant_categories)}</div>
</div>
</div>
<div class="text-[11px] text-slate-500 leading-relaxed text-right pt-2 border-t border-slate-100">
${safeStr(c.mechanism)}
</div>
</div>
`).join('');
}
// 1.4 Lost Brand Opportunity Strategy Cards
const lostCardsBox = document.getElementById('lost-opportunity-cards-container');
if (lostCardsBox && lostAnalysis.lost_opportunity_breakdown) {
lostCardsBox.innerHTML = lostAnalysis.lost_opportunity_breakdown.map(ch => `
<div class="p-4 rounded-2xl bg-white border border-slate-200/90 shadow-xs space-y-2">
<div class="flex items-center justify-between">
<h5 class="text-xs font-black text-slate-900">${safeStr(ch.channel)}</h5>
<span class="px-2 py-0.5 rounded-full text-[11px] font-black bg-indigo-50 text-indigo-700 border border-indigo-200 tnum">
پتانسیل جذب: ${ch.addressable_potential_irr} همت
</span>
</div>
<div class="text-[11px] text-slate-500 font-medium">
اندازه کل کانال: <strong class="text-slate-800 tnum">${ch.channel_scale_irr} همت</strong>
</div>
<p class="text-xs text-slate-600 leading-relaxed pt-1 border-t border-slate-100 text-right">
<strong class="text-slate-800">استراتژی آزادسازی:</strong> ${safeStr(ch.capture_strategy)}
</p>
</div>
`).join('');
}
// 1.5 Top Domestic Brands Financial Pipeline Table
const domTbody = document.getElementById('top-domestic-brands-tbody');
if (domTbody && domesticPipeline.length > 0) {
domTbody.innerHTML = domesticPipeline.map(item => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3.5 font-bold text-slate-900">
<div>${safeStr(item.brand_name)}</div>
<div class="text-[10px] text-slate-400 font-medium mt-0.5">${safeStr(item.key_products)}</div>
</td>
<td class="p-3.5 text-xs text-slate-600">${safeStr(item.industry)}</td>
<td class="p-3.5 font-black text-slate-900 tnum">
${formatNumber(item.total_annual_sales_irr)} همت
</td>
<td class="p-3.5 text-xs font-bold text-slate-700 tnum">
${formatNumber(item.current_digikala_sales_irr)} همت
</td>
<td class="p-3.5 text-xs tnum">
<span class="px-2 py-0.5 rounded-full bg-slate-100 text-slate-700 font-bold">
${item.current_share_pct}٪
</span>
</td>
<td class="p-3.5 font-black text-emerald-700 tnum">
<span class="px-2.5 py-1 rounded-full bg-emerald-50 text-emerald-800 border border-emerald-200 text-xs">
${formatNumber(item.addressable_digikala_potential_irr)} همت
</span>
</td>
<td class="p-3.5 text-xs font-black text-indigo-700 tnum">
<span class="px-2 py-0.5 rounded-lg bg-indigo-50 text-indigo-800 border border-indigo-200">
${safeStr(item.growth_multiple)}
</span>
</td>
<td class="p-3.5 text-xs text-slate-600 max-w-sm leading-relaxed">
${safeStr(item.unlocking_mechanism)}
</td>
<td class="p-3.5 text-center">
<div class="space-y-1">
<a href="${item.source_url}" target="_blank" class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-indigo-50 hover:bg-indigo-100 text-indigo-700 hover:text-indigo-900 border border-indigo-200 text-[11px] font-bold transition shadow-xs">
<span>${safeStr(item.codal_symbol ? 'نماد ' + item.codal_symbol : 'سند رسمی')}</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
<div class="text-[10px] text-slate-400 tnum" title="${safeStr(item.audited_detail)}">
${safeStr(item.source_doc_type)}
</div>
</div>
</td>
</tr>
`).join('');
}
console.log("✓ renderBrandMarketIntelligence completed");
} catch (e) {
console.error("Error in renderBrandMarketIntelligence:", e);
}
}
// -------------------------------------------------------------
// 2. WAR CRISIS 1404
// -------------------------------------------------------------
function renderWarTable() {
try {
const tbody = document.getElementById('war-table-tbody');
if (!tbody) return;
const war = getBundle().war_report_1404 || {};
const shifts = war.commodities_shift || [];
tbody.innerHTML = shifts.map(item => {
const changeRaw = safeStr(item.change_pct);
const isPostWar = changeRaw.includes('پساجنگ');
const pureChange = changeRaw.replace('(پساجنگ)', '').trim();
return `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3.5 font-bold text-slate-900 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-rose-500 shrink-0"></span>
<span class="leading-snug">${safeStr(item.category)}</span>
</td>
<td class="p-3.5 text-center">
<div class="inline-flex flex-col items-center justify-center px-3 py-1.5 rounded-2xl bg-rose-50 border border-rose-200 text-rose-700 min-w-[95px]">
<span class="font-black text-xs tnum">${pureChange}</span>
${isPostWar ? `<span class="text-[10px] text-rose-600 font-extrabold mt-0.5">پساجنگ</span>` : ''}
</div>
</td>
<td class="p-3.5 text-slate-700 text-xs font-medium max-w-xs leading-relaxed text-right">${safeStr(item.behavior)}</td>
<td class="p-3.5 text-slate-600 text-xs leading-relaxed max-w-sm text-right">${safeStr(item.strategy)}</td>
<td class="p-3.5">
<div class="p-2.5 rounded-xl ${item.supply_status && item.supply_status.includes('پایدار') ? 'bg-emerald-50/80 border border-emerald-200 text-emerald-900' : 'bg-amber-50/80 border border-amber-200 text-amber-900'} text-xs leading-relaxed flex items-start gap-2 text-right">
<span class="w-2 h-2 rounded-full ${item.supply_status && item.supply_status.includes('پایدار') ? 'bg-emerald-500' : 'bg-amber-500'} mt-1.5 shrink-0"></span>
<span class="font-medium">${safeStr(item.supply_status)}</span>
</div>
</td>
</tr>
`;
}).join('');
console.log("✓ renderWarTable completed with clean styling");
} catch (e) {
console.error("Error in renderWarTable:", e);
}
}
// -------------------------------------------------------------
// 3. COMMISSIONS & CONTRACTS (8-COLUMN COMPLETE TABLE)
// -------------------------------------------------------------
function renderContractsTable() {
try {
const tbody = document.getElementById('contracts-table-tbody');
if (!tbody) return;
const contracts = getBundle().commissions_data || [];
tbody.innerHTML = contracts.map(item => {
const avgNum = item.avg_commission !== undefined ? toPersianDigits(item.avg_commission) + '٪' : safeStr(item.average_commission_pct);
const rawDays = safeStr(item.payment_cycle_days || item.settlement_days_standard);
const isFast = rawDays.includes('تسویه سریع');
const cleanDays = rawDays.replace('(تسویه سریع)', '').trim();
return `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3.5 font-bold text-slate-900">
<div class="leading-snug">${safeStr(item.category_fa || item.category_name)}</div>
<div class="text-[10px] text-slate-400 font-medium mt-0.5 tracking-wide" dir="ltr">${safeStr(item.category_en)}</div>
</td>
<td class="p-3.5 font-bold text-slate-900 text-xs tnum">
${safeStr(item.commission_range)}
</td>
<td class="p-3.5 text-center font-black text-sm text-indigo-700 tnum">
${avgNum}
</td>
<td class="p-3.5 text-center tnum">
<div class="space-y-0.5">
<div class="font-bold text-slate-800 text-xs leading-none">${cleanDays}</div>
${isFast ? `<div class="text-[10px] text-emerald-700 font-extrabold leading-tight">تسویه سریع</div>` : ''}
</div>
</td>
<td class="p-3.5 text-xs text-slate-700 font-semibold tnum leading-relaxed">
${safeStr(item.fbd_processing_fee)}
</td>
<td class="p-3.5 text-center font-bold text-xs text-amber-800 tnum">
${safeStr(item.return_rate_est || item.return_rate_estimate)}
</td>
<td class="p-3.5 text-xs text-slate-600 max-w-xs leading-relaxed text-right">
${safeStr(item.rules_and_conditions || item.sla_penalty_and_terms)}
</td>
<td class="p-3.5 text-center">
<a href="${item.source_url || 'https://seller.digikala.com'}" target="_blank" class="inline-flex items-center gap-1 text-[11px] text-rose-600 hover:text-rose-800 font-bold bg-rose-50 hover:bg-rose-100 px-2.5 py-1 rounded-lg border border-rose-200 transition">
<span>سند</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
</td>
</tr>
`;
}).join('');
console.log("✓ renderContractsTable completed with clean borderless typography");
} catch (e) {
console.error("Error in renderContractsTable:", e);
}
}
// -------------------------------------------------------------
// 4. BRAND ECOSYSTEM PILLARS (RICH SUB-SERVICES RENDERING)
// -------------------------------------------------------------
function renderBrandEcosystem() {
try {
const container = document.getElementById('ecosystem-pillars-container');
if (!container) return;
const data = getBundle().brand_ecosystem_pillars || [];
container.innerHTML = data.map((p, idx) => {
const pillarNum = toPersianDigits(String(idx + 1).padStart(2, '0'));
const pillarId = `PILLAR-${String(idx + 1).padStart(2, '0')}`;
const rawName = p.pillar_name_fa || p.title || 'رکن اکوسیستم';
let nameFa = rawName;
let nameEn = '';
if (rawName.includes('(') && rawName.includes(')')) {
const parts = rawName.split('(');
nameFa = parts[0].trim();
nameEn = parts[1].replace(')', '').trim();
}
const desc = p.description || '';
const services = p.services || [];
return `
<div class="card-executive p-6 space-y-5 flex flex-col justify-between">
<div class="space-y-4">
<div class="flex items-center justify-between pb-3 border-b border-slate-100">
<div class="flex items-center gap-3">
<span class="w-8 h-8 rounded-xl bg-purple-50 text-purple-700 border border-purple-200 font-black text-sm flex items-center justify-center tnum">
${pillarNum}
</span>
<div class="space-y-0.5">
<h3 class="text-sm font-black text-slate-900 leading-snug">${safeStr(nameFa)}</h3>
${nameEn ? `<div class="text-[11px] text-slate-400 font-medium tracking-wide" dir="ltr">${safeStr(nameEn)}</div>` : ''}
</div>
</div>
<span class="text-[10px] font-bold text-slate-400 uppercase tracking-wider whitespace-nowrap" dir="ltr">${safeStr(pillarId)}</span>
</div>
<p class="text-xs text-slate-600 leading-relaxed text-right">${safeStr(desc)}</p>
<!-- Rich Sub-Services Cards -->
<div class="space-y-3 pt-2">
<div class="text-[11px] font-bold text-slate-500 flex items-center gap-1.5">
<i data-lucide="layers" class="w-3.5 h-3.5 text-purple-600"></i>
<span>زیرسیستم‌ها و ابزارهای خلق ارزش برای برندها (${toPersianDigits(services.length)} سرویس فعال):</span>
</div>
<div class="space-y-2.5">
${services.map(s => `
<div class="p-3.5 rounded-xl bg-slate-50/80 border border-slate-200/90 space-y-2 hover:bg-white hover:border-purple-200 transition">
<div class="flex items-center justify-between gap-2">
<h5 class="text-xs font-bold text-slate-900">${safeStr(s.service_name)}</h5>
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold bg-purple-50 text-purple-700 border border-purple-200 tnum shrink-0">
سال ${safeStr(s.year_introduced)}
</span>
</div>
<p class="text-[11px] text-slate-600 leading-relaxed text-right">${safeStr(s.mechanism)}</p>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2 text-[10px] pt-1">
<div class="p-2 rounded-lg bg-emerald-50/70 border border-emerald-100 text-emerald-800">
<strong class="text-emerald-900">ارزش برای برند:</strong> ${safeStr(s.value_for_brand)}
</div>
<div class="p-2 rounded-lg bg-blue-50/70 border border-blue-100 text-blue-800">
<strong class="text-blue-900">ارزش برای کاربر:</strong> ${safeStr(s.value_for_user)}
</div>
</div>
${s.brands_using ? `
<div class="text-[10px] text-slate-500 pt-1 flex items-center gap-1 flex-wrap">
<span class="font-bold text-slate-700">برندهای شاخص فعال:</span>
<span class="text-slate-600 font-medium">${safeStr(s.brands_using)}</span>
</div>
` : ''}
</div>
`).join('')}
</div>
</div>
</div>
</div>
`;
}).join('');
console.log("✓ renderBrandEcosystem completed with clean titles");
} catch (e) {
console.error("Error in renderBrandEcosystem:", e);
}
}
// -------------------------------------------------------------
// 5. GROWTH LEVERS (12 LEVERS)
// -------------------------------------------------------------
function renderGrowthLevers() {
try {
const container = document.getElementById('growth-levers-container');
if (!container) return;
const data = getBundle().growth_levers_data || [];
container.innerHTML = data.map(lever => {
const id = lever.id || 'GL';
const name = lever.name || lever.lever_title || 'اهرم رشد';
const category = lever.category || lever.pillar_category || 'عمومی';
const period = lever.period_active || '';
const mechanism = lever.mechanism || lever.operational_mechanism || '';
const impact = lever.impact_data || lever.quantified_impact || '';
const sourceTitle = lever.source_title || 'مشاهده سند ارجاعی';
const sourceUrl = lever.source_url || lever.source_link || '';
return `
<div class="card-executive p-6 space-y-4 flex flex-col justify-between hover:border-indigo-200 transition">
<div class="space-y-3">
<div class="flex items-center justify-between pb-3 border-b border-slate-100">
<span class="px-2.5 py-0.5 rounded-full text-[10px] font-bold bg-indigo-50 text-indigo-700 border border-indigo-200">
${safeStr(category)}
</span>
<div class="flex items-center gap-1.5">
${period ? `<span class="text-[10px] text-slate-400 font-medium tnum">${safeStr(period)}</span>` : ''}
<span class="px-2 py-0.5 rounded-md bg-slate-100 text-slate-600 text-[10px] font-bold uppercase tracking-wider">${safeStr(id)}</span>
</div>
</div>
<h4 class="text-sm font-bold text-slate-900 leading-snug">${safeStr(name)}</h4>
<p class="text-xs text-slate-600 leading-relaxed text-right">${safeStr(mechanism)}</p>
</div>
<div class="space-y-3 pt-3 border-t border-slate-100">
<div class="p-3 bg-emerald-50/70 rounded-xl border border-emerald-100 space-y-1">
<div class="text-[11px] font-bold text-emerald-800 flex items-center gap-1">
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
<span>اثر اثبات‌شده کمی:</span>
</div>
<div class="text-xs text-emerald-900 font-semibold leading-relaxed tnum text-right">${safeStr(impact)}</div>
</div>
${sourceUrl ? `
<a href="${sourceUrl}" target="_blank" class="inline-flex items-center gap-1.5 text-xs text-slate-500 hover:text-rose-600 font-medium transition">
<i data-lucide="external-link" class="w-3.5 h-3.5 text-rose-500"></i>
<span class="truncate">${safeStr(sourceTitle)}</span>
</a>
` : ''}
</div>
</div>
`;
}).join('');
console.log("✓ renderGrowthLevers completed with 12 full cards");
} catch (e) {
console.error("Error in renderGrowthLevers:", e);
}
}
// -------------------------------------------------------------
// 6. REVENUE MODELS & 3-SIDED ANALYSIS
// -------------------------------------------------------------
function renderRevenueModels() {
try {
const roadmapBox = document.getElementById('revenue-roadmap-container');
const fullCardsBox = document.getElementById('revenue-models-full-cards');
const data = getBundle().revenue_models_data || [];
if (roadmapBox) {
roadmapBox.innerHTML = data.map(m => `
<div class="p-3.5 bg-slate-50/80 rounded-2xl border border-slate-200/80 flex flex-col sm:flex-row sm:items-center justify-between gap-3 hover:bg-white hover:border-slate-300 transition">
<div class="space-y-1">
<div class="flex items-center gap-2">
<span class="px-2 py-0.5 rounded-full text-[10px] font-extrabold bg-amber-100 text-amber-800 tnum">
معرفی در ${safeStr(m.year_introduced)}
</span>
<span class="font-bold text-xs text-slate-900">${safeStr(m.name)}</span>
</div>
<p class="text-xs text-slate-500">${safeStr(m.mechanism)}</p>
</div>
<div class="text-left shrink-0">
<span class="text-xs font-black text-amber-700 bg-amber-50 px-2.5 py-1 rounded-lg border border-amber-200 tnum">
${safeStr(m.share_of_revenue_1403)}
</span>
</div>
</div>
`).join('');
}
if (fullCardsBox) {
fullCardsBox.innerHTML = data.map(m => `
<div class="card-executive p-6 space-y-4">
<div class="flex flex-col sm:flex-row sm:items-center justify-between pb-3 border-b border-slate-100 gap-2">
<div class="flex items-center gap-3">
<div class="p-2 bg-amber-50 text-amber-700 rounded-xl">
<i data-lucide="coins" class="w-5 h-5"></i>
</div>
<div>
<h4 class="text-sm font-bold text-slate-900">${safeStr(m.name)}</h4>
<span class="text-xs text-slate-500">سال معرفی: ${safeStr(m.year_introduced)}</span>
</div>
</div>
<div class="flex items-center gap-2">
<span class="text-xs font-bold text-slate-500">سهم از درآمد کل (۱۴۰۳):</span>
<span class="px-3 py-1 bg-amber-50 text-amber-800 border border-amber-200 rounded-xl font-black text-xs tnum">${safeStr(m.share_of_revenue_1403)}</span>
</div>
</div>
<p class="text-xs text-slate-600 leading-relaxed text-right">${safeStr(m.mechanism)}</p>
<!-- 3-Sided Analysis Grid -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-3 text-xs pt-1">
<div class="p-3 bg-blue-50/60 rounded-xl border border-blue-100 space-y-1">
<div class="font-bold text-blue-900 flex items-center gap-1">
<i data-lucide="user" class="w-3.5 h-3.5 text-blue-600"></i>
<span>خریدار نهایی (User Impact):</span>
</div>
<p class="text-blue-800 text-[11px] leading-relaxed text-right">${safeStr(m.user_side_impact)}</p>
</div>
<div class="p-3 bg-emerald-50/60 rounded-xl border border-emerald-100 space-y-1">
<div class="font-bold text-emerald-900 flex items-center gap-1">
<i data-lucide="building" class="w-3.5 h-3.5 text-emerald-600"></i>
<span>فروشنده و برند (Brand Impact):</span>
</div>
<p class="text-emerald-800 text-[11px] leading-relaxed text-right">${safeStr(m.brand_side_impact)}</p>
</div>
<div class="p-3 bg-amber-50/60 rounded-xl border border-amber-100 space-y-1">
<div class="font-bold text-amber-900 flex items-center gap-1">
<i data-lucide="shield" class="w-3.5 h-3.5 text-amber-600"></i>
<span>رگولاتور و دولت (Gov & Tax):</span>
</div>
<p class="text-amber-800 text-[11px] leading-relaxed text-right">${safeStr(m.gov_tax_aspect)}</p>
</div>
</div>
${m.source_url ? `
<div class="pt-2 border-t border-slate-100 flex justify-end">
<a href="${m.source_url}" target="_blank" class="inline-flex items-center gap-1 text-xs text-rose-600 hover:text-rose-800 font-bold transition">
<span>${safeStr(m.source_title || 'مشاهده منبع استنادی')}</span>
<i data-lucide="external-link" class="w-3.5 h-3.5"></i>
</a>
</div>
` : ''}
</div>
`).join('');
}
console.log("✓ renderRevenueModels completed with 3-sided analysis");
} catch (e) {
console.error("Error in renderRevenueModels:", e);
}
}
// -------------------------------------------------------------
// 7. 20-YEAR TIMELINE (FULL 20-YEAR METRICS & 4-BOX ARCHITECTURE)
// -------------------------------------------------------------
function renderTimelineCards(filterYear = 'all') {
try {
const container = document.getElementById('timeline-cards-list');
if (!container) return;
const timeline = getBundle().yearly_metrics || [];
const filtered = (filterYear === 'all') ? timeline : timeline.filter(y => y.year_shamsi === filterYear);
container.innerHTML = filtered.map(item => `
<div class="card-executive p-6 space-y-5">
<!-- Header -->
<div class="flex flex-col sm:flex-row sm:items-center justify-between pb-3 border-b border-slate-100 gap-3">
<div class="flex items-center gap-3">
<div class="px-3.5 py-1.5 rounded-2xl bg-slate-900 text-white font-black text-sm tnum tnum text-center">
<div>${safeStr(item.year_shamsi)}</div>
<div class="text-[10px] text-slate-400 font-normal">${safeStr(item.year_gregorian)}</div>
</div>
<div>
<h4 class="text-sm font-bold text-slate-900">${safeStr(item.phase)}</h4>
<div class="text-xs text-slate-500 mt-0.5">نفوذ ایکامرس در ایران: <strong class="text-slate-800 tnum tnum">${item.ecom_penetration_iran || '۰.۰۵'}٪</strong></div>
</div>
</div>
<div class="flex items-center gap-2 text-xs tnum tnum">
<span class="px-2.5 py-1 rounded-full bg-emerald-50 text-emerald-800 border border-emerald-200 font-bold">
${item.domestic_brand_share}٪ بومی
</span>
<span class="px-2.5 py-1 rounded-full bg-rose-50 text-rose-800 border border-rose-200 font-bold">
${item.foreign_brand_share}٪ خارجی
</span>
</div>
</div>
<!-- Quantitative 4-Metric Grid -->
<div class="grid grid-cols-2 sm:grid-cols-4 gap-3">
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100">
<span class="text-[11px] text-slate-500 font-medium">تنوع کالا (SKU):</span>
<div class="text-sm font-black text-slate-900 tnum mt-0.5">${formatNumber(item.sku_count)}</div>
</div>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100">
<span class="text-[11px] text-slate-500 font-medium">فروشندگان فعال:</span>
<div class="text-sm font-black text-slate-900 tnum mt-0.5">${formatNumber(item.active_sellers)}</div>
</div>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100">
<span class="text-[11px] text-slate-500 font-medium">سفارش روزانه:</span>
<div class="text-sm font-black text-slate-900 tnum mt-0.5">${formatNumber(item.daily_orders)}</div>
</div>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100">
<span class="text-[11px] text-slate-500 font-medium">نیروی انسانی:</span>
<div class="text-sm font-black text-slate-900 tnum mt-0.5">${formatNumber(item.workforce)} نفر</div>
</div>
</div>
<!-- Top Brands Row -->
${(item.top_brands && item.top_brands.length > 0) ? `
<div class="text-xs flex items-center gap-1.5 flex-wrap pt-1">
<span class="font-bold text-slate-700">برندهای لیدر سال:</span>
${item.top_brands.map(b => `<span class="px-2 py-0.5 rounded-md bg-white border border-slate-200 text-slate-700 font-medium text-[11px]">${b}</span>`).join('')}
</div>
` : ''}
<!-- 4 Categorized Boxes -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-3 text-xs">
<!-- Box 1: Milestones -->
<div class="p-3.5 bg-slate-50/70 rounded-2xl border border-slate-200/70 space-y-1.5">
<div class="font-bold text-slate-900 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-blue-500"></span>
<span>دستاوردها و اتفاقات کلیدی:</span>
</div>
<ul class="space-y-1 text-slate-600 text-[11px] list-disc list-inside leading-relaxed text-right">
${(item.milestones || []).map(m => `<li>${safeStr(m)}</li>`).join('')}
</ul>
</div>
<!-- Box 2: Pivots & Failures -->
<div class="p-3.5 bg-rose-50/40 rounded-2xl border border-rose-100 space-y-1.5">
<div class="font-bold text-rose-900 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-rose-500"></span>
<span>پیوت‌ها و شکست‌های مسیر:</span>
</div>
<ul class="space-y-1 text-rose-800 text-[11px] list-disc list-inside leading-relaxed text-right">
${(item.pivots_and_failures || []).map(p => `<li>${safeStr(p)}</li>`).join('')}
</ul>
</div>
<!-- Box 3: Management Shifts -->
<div class="p-3.5 bg-indigo-50/40 rounded-2xl border border-indigo-100 space-y-1.5">
<div class="font-bold text-indigo-900 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-indigo-500"></span>
<span>تحولات ساختار مدیریتی:</span>
</div>
<ul class="space-y-1 text-indigo-800 text-[11px] list-disc list-inside leading-relaxed text-right">
${(item.management_shifts || []).map(ms => `<li>${safeStr(ms)}</li>`).join('')}
</ul>
</div>
<!-- Box 4: Macro & Regulatory -->
<div class="p-3.5 bg-amber-50/40 rounded-2xl border border-amber-100 space-y-1.5">
<div class="font-bold text-amber-900 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-amber-500"></span>
<span>شرایط کلان اقتصادی و رگولاتوری:</span>
</div>
<ul class="space-y-1 text-amber-800 text-[11px] list-disc list-inside leading-relaxed text-right">
${(item.regulatory_and_macro || []).map(r => `<li>${safeStr(r)}</li>`).join('')}
</ul>
</div>
</div>
</div>
`).join('');
console.log("✓ renderTimelineCards completed for 20 years");
} catch (e) {
console.error("Error in renderTimelineCards:", e);
}
}
function filterTimeline() {
const sel = document.getElementById('timeline-filter-select');
if (!sel) return;
renderTimelineCards(sel.value);
}
// -------------------------------------------------------------
// 8. EXECUTIVES DIRECTORY (COMPLETE VIDEO TITLES & CLEAN BIDI)
// -------------------------------------------------------------
function renderExecutivesCards() {
try {
const container = document.getElementById('executives-cards-container');
if (!container) return;
const data = getBundle().executives_directory || [];
container.innerHTML = data.map(exec => {
const interviews = exec.interview_videos || exec.key_interviews || exec.direct_interviews || [];
return `
<div class="card-executive p-6 space-y-4 flex flex-col justify-between">
<div class="space-y-3">
<div class="flex items-center justify-between pb-2 border-b border-slate-100">
<span class="px-2.5 py-0.5 rounded-full text-[10px] font-bold bg-blue-50 text-blue-700 border border-blue-200">
${safeStr(exec.role_category)}
</span>
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold bg-slate-100 text-slate-600 tnum tnum" dir="rtl">
${safeStr(exec.tenure)}
</span>
</div>
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-2xl bg-gradient-to-tr from-slate-100 to-slate-200 border border-slate-300 text-slate-700 flex items-center justify-center font-black text-sm tnum shrink-0">
${safeStr(exec.name).slice(0, 2)}
</div>
<div>
<h3 class="text-sm font-bold text-slate-900">${safeStr(exec.name)}</h3>
<p class="text-xs text-slate-500 leading-snug" dir="rtl">${safeStr(exec.title)}</p>
</div>
</div>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs">
<div class="font-bold text-slate-800 text-[11px] mb-1">دیدگاه استراتژیک در قبال برندها:</div>
<p class="text-slate-600 text-[11px] leading-relaxed italic text-right">${safeStr(exec.stance_on_brands || exec.key_stance)}</p>
</div>
</div>
${interviews.length > 0 ? `
<div class="space-y-2 pt-3 border-t border-slate-100">
<div class="text-[11px] font-bold text-slate-500">مصاحبه‌ها و ویدیوهای فکت‌چک‌شده:</div>
<div class="space-y-1.5">
${interviews.map(iv => `
<a href="${iv.url}" target="_blank" class="p-2 bg-slate-50 hover:bg-rose-50 hover:border-rose-200 border border-slate-200/80 rounded-xl flex items-center justify-between text-xs transition group">
<div class="space-y-0.5 max-w-[85%]">
<div class="font-semibold text-slate-800 group-hover:text-rose-700 leading-snug text-right text-[11px]">
${safeStr(iv.title)}
</div>
<div class="text-[10px] text-slate-400 tnum flex items-center gap-1.5">
<span>${safeStr(iv.platform)}</span>
<span>•</span>
<span>سال ${safeStr(iv.year)}</span>
</div>
</div>
<i data-lucide="external-link" class="w-3.5 h-3.5 text-slate-400 group-hover:text-rose-600 shrink-0"></i>
</a>
`).join('')}
</div>
</div>
` : ''}
</div>
`;
}).join('');
console.log("✓ renderExecutivesCards completed");
} catch (e) {
console.error("Error in renderExecutivesCards:", e);
}
}
// -------------------------------------------------------------
// 9. PLAYBOOK & CANNIBALIZATION (100% FILLED, ZERO DASHES)
// -------------------------------------------------------------
function renderPlaybookSections() {
try {
const pDossier = getBundle().playbook_dossier || {};
// 1. Brands
const brandsBox = document.getElementById('playbook-brands-container');
if (brandsBox && pDossier.how_digikala_convinced_brands) {
brandsBox.innerHTML = pDossier.how_digikala_convinced_brands.map((item, idx) => `
<div class="p-4 bg-slate-50/80 rounded-2xl border border-slate-200/80 space-y-2 hover:bg-white hover:border-blue-200 transition">
<span class="font-bold text-slate-900 text-xs">${safeStr(item.pillar || item.tactic || `${idx+1}. راهکار سازمانی`)}</span>
<p class="text-slate-600 text-xs leading-relaxed text-right">${safeStr(item.description || item.mechanism)}</p>
${item.quantified_impact ? `
<div class="text-[11px] font-bold text-blue-700 tnum pt-1">دستاورد: ${safeStr(item.quantified_impact)}</div>
` : ''}
</div>
`).join('');
}
// 2. Users
const usersBox = document.getElementById('playbook-users-container');
if (usersBox && pDossier.how_digikala_convinced_users) {
usersBox.innerHTML = pDossier.how_digikala_convinced_users.map((item, idx) => `
<div class="p-4 bg-slate-50/80 rounded-2xl border border-slate-200/80 space-y-2 hover:bg-white hover:border-emerald-200 transition">
<span class="font-bold text-slate-900 text-xs">${safeStr(item.pillar || item.tactic || `${idx+1}. سیاست اعتمادسازی`)}</span>
<p class="text-slate-600 text-xs leading-relaxed text-right">${safeStr(item.description || item.mechanism)}</p>
${(item.quantified_retention || item.result) ? `
<div class="text-[11px] font-bold text-emerald-700 tnum pt-1">اثر اعتماد: ${safeStr(item.quantified_retention || item.result)}</div>
` : ''}
</div>
`).join('');
}
// 3. Cannibalization
const cannibalBox = document.getElementById('playbook-cannibal-container');
if (cannibalBox && pDossier.how_digikala_resolved_cannibalization) {
cannibalBox.innerHTML = pDossier.how_digikala_resolved_cannibalization.map(item => `
<div class="p-4 bg-slate-50/80 rounded-2xl border border-slate-200/80 space-y-2 hover:bg-white hover:border-amber-200 transition">
<div class="flex items-center justify-between">
<span class="font-bold text-slate-900 text-xs">${safeStr(item.entity || item.vertical_conflict)}</span>
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold bg-amber-100 text-amber-800">راهکار ساختاری</span>
</div>
<div class="text-xs text-rose-800 bg-rose-50/60 p-2.5 rounded-xl border border-rose-100 text-right">
<strong class="text-rose-900">صورت مسئله و تعارض:</strong> ${safeStr(item.problem)}
</div>
<div class="text-xs text-emerald-800 bg-emerald-50/60 p-2.5 rounded-xl border border-emerald-100 text-right">
<strong class="text-emerald-900">راهکار تثبیت‌شده:</strong> ${safeStr(item.solution || item.structural_solution)}
</div>
</div>
`).join('');
}
console.log("✓ renderPlaybookSections completed with full text");
} catch (e) {
console.error("Error in renderPlaybookSections:", e);
}
}
// -------------------------------------------------------------
// 10. POSTMORTEMS GRID (PIVOT-01 TO 06 & TYPO FIXES)
// -------------------------------------------------------------
function renderPostmortemsGrid() {
try {
const container = document.getElementById('postmortems-grid-container');
if (!container) return;
const data = getBundle().failures_and_pivots_dossier || [];
container.innerHTML = data.map(item => {
const fallout = item.consequences_and_fallout || item.consequences || '';
const pivotId = item.id || 'PIVOT';
return `
<div class="card-executive p-6 space-y-4 flex flex-col justify-between">
<div class="space-y-4">
<div class="flex items-center justify-between pb-3 border-b border-slate-100">
<div class="flex items-center gap-2.5">
<span class="p-2 bg-rose-50 text-rose-600 rounded-xl">
<i data-lucide="alert-triangle" class="w-4 h-4"></i>
</span>
<h3 class="text-sm font-bold text-slate-900 leading-snug">${safeStr(item.title)}</h3>
</div>
<div class="flex items-center gap-1.5 shrink-0">
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold bg-slate-100 text-slate-600 border border-slate-200 uppercase tnum">
${safeStr(pivotId)}
</span>
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold bg-rose-50 text-rose-700 border border-rose-200 tnum tnum whitespace-nowrap">
سال ${safeStr(item.year)}
</span>
</div>
</div>
<div class="space-y-3 text-xs">
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100 space-y-1">
<span class="font-bold text-slate-900">علت ریشه‌ای:</span>
<p class="text-slate-600 leading-relaxed text-right">${safeStr(item.root_cause)}</p>
</div>
<div class="p-3 bg-rose-50/50 rounded-xl border border-rose-100 space-y-1">
<span class="font-bold text-rose-900">نحوه اجرا، تبعات و خسارات اولیه:</span>
<p class="text-rose-800 leading-relaxed text-right">${safeStr(fallout)}</p>
</div>
<div class="p-3 bg-emerald-50/50 rounded-xl border border-emerald-100 space-y-1">
<span class="font-bold text-emerald-900">راهکار نهایی تثبیت‌شده و پیوت موفق:</span>
<p class="text-emerald-800 leading-relaxed text-right">${safeStr(item.resolution)}</p>
</div>
</div>
</div>
</div>
`;
}).join('');
console.log("✓ renderPostmortemsGrid completed");
} catch (e) {
console.error("Error in renderPostmortemsGrid:", e);
}
}
// -------------------------------------------------------------
// 11. MARKET & CHANNELS (WITH 8TH COLUMN: VERIFIED SOURCES)
// -------------------------------------------------------------
// -------------------------------------------------------------
// 10.1 REGULATORY RESTRICTIONS MASTER MATRIX
// -------------------------------------------------------------
// -------------------------------------------------------------
// 10.3 LEGAL CHALLENGES FRAMEWORK FOR BRANDS (7 PILLARS)
// -------------------------------------------------------------
// -------------------------------------------------------------
// 10.4 BRAND-PLATFORM FRICTION & UNCENSORED QUOTES (3 SUB-SECTIONS)
// -------------------------------------------------------------
function renderBrandPlatformFriction() {
try {
const dossier = getBundle().brand_platform_friction_dossier;
if (!dossier) return;
// 1. Friction Pillars (8 Cards)
const pillarsContainer = document.getElementById('friction-pillars-container');
if (pillarsContainer && dossier.friction_pillars) {
pillarsContainer.innerHTML = dossier.friction_pillars.map(item => {
let badgeClass = 'bg-slate-100 text-slate-700 border-slate-200';
if (item.severity_type === 'critical') {
badgeClass = 'bg-rose-50 text-rose-800 border-rose-200 font-black';
} else if (item.severity_type === 'very_high') {
badgeClass = 'bg-amber-50 text-amber-800 border-amber-200 font-bold';
} else {
badgeClass = 'bg-blue-50 text-blue-800 border-blue-200 font-medium';
}
return `
<div class="card-executive p-5 space-y-4 flex flex-col justify-between h-full hover:border-amber-300 transition shadow-sm">
<div class="space-y-3">
<div class="flex items-start justify-between pb-2 border-b border-slate-100 gap-2">
<div class="space-y-0.5">
<div class="flex items-center gap-1.5">
<span class="px-2 py-0.5 rounded-md bg-amber-50 text-amber-800 text-[10px] font-black tracking-wider uppercase">${safeStr(item.id)}</span>
<span class="text-[10px] text-slate-400 font-mono tracking-tight">${safeStr(item.pillar_en)}</span>
</div>
<h4 class="text-xs font-black text-slate-900 leading-snug pt-1">${safeStr(item.title)}</h4>
</div>
</div>
<span class="inline-block px-2 py-0.5 rounded-full border text-[10px] ${badgeClass}">
${safeStr(item.severity)}
</span>
<div class="p-2.5 bg-slate-50 rounded-xl border border-slate-200/70 text-right space-y-1">
<div class="font-bold text-slate-700 text-[11px] flex items-center gap-1">
<i data-lucide="info" class="w-3.5 h-3.5 text-slate-500"></i>
<span>مکانیسم تعارض منافع:</span>
</div>
<p class="text-slate-600 text-[11px] leading-relaxed text-right">${safeStr(item.summary)}</p>
</div>
<div class="space-y-1 text-right">
<div class="font-bold text-slate-800 text-[11px] flex items-center gap-1">
<i data-lucide="wrench" class="w-3.5 h-3.5 text-amber-600"></i>
<span>پیامد در صحنه عملیات برند:</span>
</div>
<p class="text-slate-600 text-[11px] leading-relaxed text-right">${safeStr(item.operational_reality)}</p>
</div>
</div>
<div class="pt-3 border-t border-slate-100 mt-2">
<div class="p-2 bg-amber-50/70 rounded-lg border border-amber-200/60 flex items-center gap-2">
<i data-lucide="alert-circle" class="w-3.5 h-3.5 text-amber-700 shrink-0"></i>
<span class="text-[11px] font-bold text-amber-950 text-right leading-tight tnum">${safeStr(item.impact_stat)}</span>
</div>
</div>
</div>
`;
}).join('');
}
// 2. Uncensored Quotes (8 Cards)
const quotesContainer = document.getElementById('uncensored-quotes-container');
if (quotesContainer && dossier.uncensored_quotes) {
quotesContainer.innerHTML = dossier.uncensored_quotes.map(q => {
return `
<div class="card-executive p-6 space-y-4 flex flex-col justify-between h-full border-r-4 border-r-amber-500 hover:shadow-md transition">
<div class="space-y-3">
<!-- Role & Sector Header -->
<div class="flex items-start justify-between pb-2 border-b border-slate-100 gap-2">
<div>
<h4 class="text-xs font-black text-slate-900">${safeStr(q.author_role)}</h4>
<span class="text-[11px] text-slate-500 font-medium">${safeStr(q.sector)}</span>
</div>
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold bg-slate-100 text-slate-700 border border-slate-200 whitespace-nowrap">
${safeStr(q.tone)}
</span>
</div>
<!-- Quote Body -->
<div class="p-3.5 bg-amber-50/40 rounded-xl border border-amber-100 relative">
<i data-lucide="quote" class="w-5 h-5 text-amber-300/80 absolute top-2 left-2 rotate-180"></i>
<p class="text-xs font-medium text-slate-800 leading-relaxed text-right relative z-10 pl-4">
${safeStr(q.quote)}
</p>
</div>
</div>
<!-- Context Footer -->
<div class="pt-3 border-t border-slate-100 flex items-center justify-between text-[11px] text-slate-500">
<span class="flex items-center gap-1 font-medium">
<i data-lucide="clock" class="w-3.5 h-3.5 text-slate-400"></i>
<span>${safeStr(q.context)}</span>
</span>
<span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider">${safeStr(q.id)}</span>
</div>
</div>
`;
}).join('');
}
// 3. Historical Phases (4 Eras)
const phasesContainer = document.getElementById('historical-phases-container');
if (phasesContainer && dossier.historical_phases) {
phasesContainer.innerHTML = dossier.historical_phases.map((ph, idx) => {
return `
<div class="card-executive p-5 space-y-4 flex flex-col justify-between h-full border-t-4 border-t-indigo-500 hover:shadow-sm transition">
<div class="space-y-3">
<div class="space-y-1 pb-2 border-b border-slate-100">
<div class="flex items-center justify-between">
<span class="px-2 py-0.5 rounded-md bg-indigo-50 text-indigo-800 text-[10px] font-black tracking-wider uppercase">${safeStr(ph.phase_id)}</span>
<span class="text-xs font-bold text-indigo-600 tnum">${safeStr(ph.years)}</span>
</div>
<h4 class="text-xs font-black text-slate-900 leading-snug pt-1">${safeStr(ph.title)}</h4>
<span class="inline-block text-[11px] font-semibold text-slate-500">مدل: ${safeStr(ph.model)}</span>
</div>
<div class="space-y-2 text-xs">
<div class="p-2.5 bg-rose-50/60 rounded-xl border border-rose-100 space-y-0.5 text-right">
<span class="font-bold text-rose-900 text-[10px] block">موضع و واکنش برندها:</span>
<p class="text-rose-950 text-[11px] leading-relaxed">${safeStr(ph.brand_stance)}</p>
</div>
<div class="p-2.5 bg-blue-50/60 rounded-xl border border-blue-100 space-y-0.5 text-right">
<span class="font-bold text-blue-900 text-[10px] block">استراتژی و اهرم پلتفرم:</span>
<p class="text-blue-950 text-[11px] leading-relaxed">${safeStr(ph.platform_leverage)}</p>
</div>
</div>
</div>
<div class="pt-3 border-t border-slate-100 mt-2">
<div class="p-2.5 bg-slate-50 rounded-xl border border-slate-200/80 text-right space-y-0.5">
<span class="font-bold text-slate-700 text-[10px] block">برآیند و سرنوشت بازار:</span>
<p class="text-slate-600 text-[11px] leading-relaxed">${safeStr(ph.key_outcome)}</p>
</div>
</div>
</div>
`;
}).join('');
}
console.log("✓ renderBrandPlatformFriction completed (8 pillars, 8 quotes, 4 phases)");
} catch (e) {
console.error("Error in renderBrandPlatformFriction:", e);
}
}
function renderLegalChallenges() {
try {
const container = document.getElementById('legal-challenges-container');
if (!container) return;
const items = getBundle().legal_challenges_framework || [];
container.innerHTML = items.map(item => {
let riskBadge = 'bg-slate-100 text-slate-700 border-slate-200';
if (item.risk_level_type === 'critical') {
riskBadge = 'bg-rose-50 text-rose-800 border-rose-200 font-black';
} else if (item.risk_level_type === 'very_high') {
riskBadge = 'bg-amber-50 text-amber-800 border-amber-200 font-bold';
} else {
riskBadge = 'bg-blue-50 text-blue-800 border-blue-200 font-medium';
}
const mitigations = safeStr(item.mitigation_strategy).split(String.fromCharCode(10));
return `
<div class="card-executive p-5 space-y-4 flex flex-col justify-between h-full hover:border-indigo-300 transition shadow-sm">
<div class="space-y-4">
<!-- Header -->
<div class="flex items-start justify-between pb-3 border-b border-slate-100 gap-2">
<div class="space-y-1">
<div class="flex items-center gap-2">
<span class="px-2 py-0.5 rounded-md bg-indigo-50 text-indigo-700 text-[10px] font-black tracking-wider uppercase">${safeStr(item.id)}</span>
<span class="text-[11px] font-bold text-slate-500">${safeStr(item.category)}</span>
</div>
<h4 class="text-sm font-black text-slate-900 leading-snug">${safeStr(item.title)}</h4>
</div>
<span class="px-2 py-0.5 rounded-full border text-[10px] whitespace-nowrap shrink-0 ${riskBadge}">
${safeStr(item.risk_level)}
</span>
</div>
<!-- Statute Basis -->
<div class="p-2.5 bg-slate-50 rounded-xl border border-slate-200/80 space-y-0.5 text-xs">
<div class="font-bold text-slate-700 flex items-center gap-1.5 text-[11px]">
<i data-lucide="book-open" class="w-3.5 h-3.5 text-slate-500"></i>
<span>مستند و مبنای قانونی:</span>
</div>
<p class="text-slate-600 text-[11px] leading-relaxed">${safeStr(item.statute_basis)}</p>
</div>
<!-- Core Challenge -->
<div class="space-y-1 text-xs">
<div class="font-bold text-slate-800 flex items-center gap-1 text-[11px]">
<i data-lucide="alert-triangle" class="w-3.5 h-3.5 text-amber-600"></i>
<span>واقعیت حقوقی و اصطکاک برند:</span>
</div>
<p class="text-slate-600 leading-relaxed text-right">${safeStr(item.core_challenge)}</p>
</div>
<!-- Judicial Precedent -->
<div class="p-3 bg-amber-50/50 rounded-xl border border-amber-100/80 space-y-1 text-xs">
<div class="font-bold text-amber-900 flex items-center gap-1 text-[11px]">
<i data-lucide="gavel" class="w-3.5 h-3.5 text-amber-700"></i>
<span>رویه محاکم قضایی و اداری:</span>
</div>
<p class="text-amber-950 leading-relaxed text-right text-[11px]">${safeStr(item.judicial_precedent)}</p>
</div>
<!-- Mitigation Strategy -->
<div class="p-3.5 bg-emerald-50/60 rounded-xl border border-emerald-100 space-y-1.5 text-xs">
<div class="font-bold text-emerald-900 flex items-center gap-1 text-[11px]">
<i data-lucide="shield-check" class="w-3.5 h-3.5 text-emerald-600"></i>
<span>پروتکل دفاعی و اقدام پیشگیرانه برند:</span>
</div>
<div class="space-y-1 text-emerald-950 text-[11px] leading-relaxed text-right">
${mitigations.map(m => `<div>${m}</div>`).join('')}
</div>
</div>
</div>
<!-- Source Link -->
${item.source_url ? `
<div class="pt-3 border-t border-slate-100 flex items-center justify-between text-xs">
<a href="${item.source_url}" target="_blank" class="inline-flex items-center gap-1.5 text-slate-500 hover:text-indigo-600 font-medium transition">
<i data-lucide="external-link" class="w-3.5 h-3.5 text-indigo-500"></i>
<span class="truncate">${safeStr(item.source_title)}</span>
</a>
<span class="text-[10px] text-slate-400 font-medium">سند حقوقی</span>
</div>
` : ''}
</div>
`;
}).join('');
console.log("✓ renderLegalChallenges completed with 7 full pillars");
} catch (e) {
console.error("Error in renderLegalChallenges:", e);
}
}
function renderRegulatoryMatrix() {
try {
const tbody = document.getElementById('regulatory-matrix-tbody');
if (!tbody) return;
const matrix = getBundle().regulatory_restrictions_matrix || [];
tbody.innerHTML = matrix.map(item => {
let feasBadge = '';
if (item.supply_feasibility_type === 'yes') {
feasBadge = '<span class="px-2 py-0.5 rounded-full text-[10px] font-black bg-emerald-50 text-emerald-800 border border-emerald-200 block text-center leading-tight">✓ ' + safeStr(item.supply_feasibility) + '</span>';
} else if (item.supply_feasibility_type === 'conditional') {
feasBadge = '<span class="px-2 py-0.5 rounded-full text-[10px] font-black bg-amber-50 text-amber-800 border border-amber-200 block text-center leading-tight">⚠ ' + safeStr(item.supply_feasibility) + '</span>';
} else {
feasBadge = '<span class="px-2 py-0.5 rounded-full text-[10px] font-black bg-rose-50 text-rose-800 border border-rose-200 block text-center leading-tight">✕ ' + safeStr(item.supply_feasibility) + '</span>';
}
let riskBadge = 'bg-slate-100 text-slate-700 border-slate-200';
if (item.regulatory_risk_level && (item.regulatory_risk_level.includes('بحرانی') || item.regulatory_risk_level.includes('امنیتی'))) {
riskBadge = 'bg-rose-50 text-rose-800 border-rose-200 font-extrabold';
} else if (item.regulatory_risk_level && item.regulatory_risk_level.includes('بسیار بالا')) {
riskBadge = 'bg-amber-50 text-amber-800 border-amber-200 font-bold';
} else if (item.regulatory_risk_level && item.regulatory_risk_level.includes('بالا')) {
riskBadge = 'bg-blue-50 text-blue-800 border-blue-200 font-medium';
}
const rawChannels = safeStr(item.supply_channels_active);
const channels = rawChannels.split(String.fromCharCode(10));
return `
<tr class="hover:bg-slate-50/80 transition-colors border-b border-slate-100">
<td class="p-2.5 font-bold text-slate-900 break-words align-top">
<div class="leading-snug text-xs">${safeStr(item.category)}</div>
<div class="text-[10px] text-slate-400 font-medium mt-0.5 tracking-wide leading-tight" dir="ltr">${safeStr(item.category_en)}</div>
</td>
<td class="p-2.5 text-xs text-slate-700 leading-relaxed text-right break-words align-top">
${safeStr(item.latest_status_1403_1404)}
</td>
<td class="p-2.5 text-center align-top">
${feasBadge}
</td>
<td class="p-2.5 text-xs text-slate-700 leading-relaxed break-words align-top">
<div class="space-y-1">
${channels.map(ch => `<div class="leading-relaxed text-right">${ch}</div>`).join('')}
</div>
</td>
<td class="p-2.5 text-xs text-slate-800 leading-relaxed text-right font-medium break-words align-top">
${safeStr(item.online_sales_status)}
</td>
<td class="p-2.5 space-y-1.5 text-xs break-words align-top">
<div class="text-slate-600 leading-snug text-[10px]">${safeStr(item.key_regulator)}</div>
<div>
<span class="px-1.5 py-0.5 rounded border text-[9px] block text-center leading-tight ${riskBadge}">
${safeStr(item.regulatory_risk_level)}
</span>
</div>
</td>
<td class="p-2.5 text-center align-top break-words">
<div class="space-y-1.5 flex flex-col items-center">
${item.source_url ? `
<a href="${item.source_url}" target="_blank" class="inline-flex items-center gap-1 px-2 py-1 rounded-lg border border-indigo-200 bg-indigo-50/80 hover:bg-indigo-100 text-indigo-900 text-[10px] font-bold transition text-center leading-tight shadow-sm w-full justify-center">
<i data-lucide="external-link" class="w-3 h-3 text-indigo-600 shrink-0"></i>
<span class="truncate">${safeStr(item.source_title)}</span>
</a>
` : ''}
${item.secondary_source_url ? `
<a href="${item.secondary_source_url}" target="_blank" class="text-[9px] text-slate-500 hover:text-indigo-700 font-medium transition underline underline-offset-2 leading-tight block text-center">
<span>${safeStr(item.secondary_source_title)}</span>
</a>
` : ''}
</div>
</td>
</tr>
`;
}).join('');
console.log("✓ renderRegulatoryMatrix completed with strict table-fixed alignment");
} catch (e) {
console.error("Error in renderRegulatoryMatrix:", e);
}
}
// -------------------------------------------------------------
// 10.2 FOUNDER WAR STORIES & REGULATORY TRAUMAS (10 CARDS)
// -------------------------------------------------------------
function renderFounderWarStories() {
try {
const container = document.getElementById('founder-war-stories-container');
if (!container) return;
const stories = getBundle().founder_war_stories || [];
container.innerHTML = stories.map(st => `
<div class="card-executive p-6 space-y-4 flex flex-col justify-between hover:border-indigo-200 transition">
<div class="space-y-4">
<!-- Header -->
<div class="flex items-center justify-between pb-3 border-b border-slate-100">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-2xl bg-gradient-to-tr from-rose-50 to-indigo-50 border border-slate-200 text-slate-800 flex items-center justify-center font-black text-xs shrink-0">
${safeStr(st.founder).slice(0, 2)}
</div>
<div>
<h4 class="text-sm font-black text-slate-900 leading-tight">${safeStr(st.founder)}</h4>
<div class="text-[11px] text-indigo-700 font-bold mt-0.5">${safeStr(st.platform)} (${safeStr(st.role)})</div>
</div>
</div>
<div class="text-left shrink-0">
<span class="px-2 py-0.5 rounded-md bg-slate-100 text-slate-600 text-[10px] font-bold uppercase tracking-wider">${safeStr(st.id)}</span>
<div class="text-[10px] text-slate-400 font-medium tnum mt-0.5" dir="rtl">${safeStr(st.period)}</div>
</div>
</div>
<!-- Incident Title -->
<div class="p-3 bg-rose-50/60 rounded-xl border border-rose-100 space-y-1">
<div class="text-[11px] font-black text-rose-900 flex items-center gap-1.5">
<i data-lucide="alert-octagon" class="w-3.5 h-3.5 text-rose-600"></i>
<span>رخداد و شوک رگولاتوری/بازار:</span>
</div>
<div class="text-xs font-bold text-rose-950 leading-snug">${safeStr(st.incident_title)}</div>
</div>
<!-- Narrative -->
<p class="text-xs text-slate-600 leading-relaxed text-right">${safeStr(st.narrative)}</p>
<!-- Adaptation Strategy -->
<div class="p-3.5 bg-emerald-50/60 rounded-xl border border-emerald-100 space-y-1 text-xs">
<div class="font-bold text-emerald-900 flex items-center gap-1.5 text-[11px]">
<i data-lucide="check-circle-2" class="w-3.5 h-3.5 text-emerald-600"></i>
<span>استراتژی سازگاری و نحوه حل مسئله:</span>
</div>
<p class="text-emerald-800 leading-relaxed text-right">${safeStr(st.adaptation_strategy)}</p>
</div>
<!-- Strategic Lesson -->
<div class="p-3.5 bg-indigo-50/50 rounded-xl border border-indigo-100 space-y-1 text-xs">
<div class="font-bold text-indigo-900 flex items-center gap-1.5 text-[11px]">
<i data-lucide="compass" class="w-3.5 h-3.5 text-indigo-600"></i>
<span>درس‌آموخته استراتژیک (Strategic Takeaway):</span>
</div>
<p class="text-indigo-950 leading-relaxed text-right font-medium">${safeStr(st.strategic_lesson)}</p>
</div>
</div>
<!-- Citation Link -->
${st.source_url ? `
<div class="pt-3 border-t border-slate-100 flex items-center justify-between text-xs">
<a href="${st.source_url}" target="_blank" class="inline-flex items-center gap-1.5 text-slate-500 hover:text-rose-600 font-medium transition">
<i data-lucide="external-link" class="w-3.5 h-3.5 text-rose-500"></i>
<span class="truncate">${safeStr(st.source_title)}</span>
</a>
<span class="text-[10px] text-slate-400 font-medium">سند معتبر</span>
</div>
` : ''}
</div>
`).join('');
console.log("✓ renderFounderWarStories completed");
} catch (e) {
console.error("Error in renderFounderWarStories:", e);
}
}
function renderMarketTable() {
try {
const tbody = document.getElementById('market-table-tbody');
if (!tbody) return;
const data = getBundle().market_channel_breakdown || [];
tbody.innerHTML = data.map(item => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3.5 font-bold text-slate-900">${safeStr(item.sector)}</td>
<td class="p-3.5 font-black text-slate-800 tnum text-xs tnum">${formatNumber(item.total_market_size_irr_thousand_b)} همت</td>
<td class="p-3.5 font-bold text-blue-700 tnum text-xs tnum">
<span class="px-2.5 py-1 rounded-full bg-blue-50 text-blue-800 border border-blue-200">
${item.ecommerce_official_share}٪
</span>
</td>
<td class="p-3.5 font-bold text-rose-700 tnum text-xs tnum">
<span class="px-2.5 py-1 rounded-full bg-rose-50 text-rose-800 border border-rose-200">
${item.social_commerce_share}٪
</span>
</td>
<td class="p-3.5 tnum text-xs text-slate-600 tnum">${item.traditional_offline_share}٪</td>
<td class="p-3.5">
<span class="px-2.5 py-1 rounded-full bg-rose-50 text-rose-800 border border-rose-200 text-xs font-bold tnum tnum">
${item.smuggling_rate}٪
</span>
</td>
<td class="p-3.5 text-xs text-slate-600 max-w-xs leading-relaxed">${safeStr(item.key_drivers)}</td>
<td class="p-3.5">
<div class="space-y-1.5">
<div class="font-bold text-slate-900 text-xs">${safeStr(item.source_name)}</div>
${item.source_url ? `
<a href="${item.source_url}" target="_blank" class="inline-flex items-center gap-1 text-[11px] text-indigo-700 hover:text-indigo-900 font-bold bg-indigo-50 hover:bg-indigo-100 px-2.5 py-1 rounded-lg border border-indigo-200 transition shadow-xs" title="${safeStr(item.methodology)}">
<span>${safeStr(item.source_type || 'سند رسمی و مصاحبه')}</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
` : ''}
<div class="text-[10px] text-slate-500 leading-tight">${safeStr(item.methodology)}</div>
</div>
</td>
</tr>
`).join('');
console.log("✓ renderMarketTable completed with sources");
} catch (e) {
console.error("Error in renderMarketTable:", e);
}
}
// -------------------------------------------------------------
// 12. CATEGORIES MATRIX (TOP SEARCHED QUERIES & SANA FIX)
// -------------------------------------------------------------
function renderCategoriesFull() {
try {
const container = document.getElementById('categories-full-container');
if (!container) return;
const data = getBundle().category_brand_deep_matrix || [];
container.innerHTML = data.map(cat => {
const irBrands = Array.isArray(cat.top_iranian_brands) ? cat.top_iranian_brands : [];
const frBrands = Array.isArray(cat.top_foreign_brands) ? cat.top_foreign_brands : [];
const searchQueries = Array.isArray(cat.top_searched_queries) ? cat.top_searched_queries : [];
return `
<div class="card-executive p-6 space-y-4">
<div class="flex flex-col sm:flex-row sm:items-center justify-between pb-3 border-b border-slate-100 gap-2">
<div class="flex items-center gap-2.5">
<span class="p-2 bg-indigo-50 text-indigo-700 rounded-xl">
<i data-lucide="tag" class="w-4 h-4"></i>
</span>
<h3 class="text-sm font-bold text-slate-900">${safeStr(cat.category_name)}</h3>
</div>
<div class="flex items-center gap-3 text-xs text-slate-500">
<span>نسبت داخلی به خارجی: <strong class="text-slate-900 font-bold tnum">${safeStr(cat.foreign_vs_domestic_ratio)}</strong></span>
<span>•</span>
<span>سهم از GMV کل: <strong class="text-indigo-600 font-bold tnum">${cat.share_of_total_gmv_1403}٪</strong></span>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-xs">
<div class="space-y-2 p-3.5 bg-slate-50/60 rounded-2xl border border-slate-100">
<div class="font-bold text-emerald-800 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
<span>برندهای لیدر بومی و ایرانی:</span>
</div>
<div class="flex flex-wrap gap-1.5">
${irBrands.map(b => `<span class="px-2 py-0.5 bg-emerald-50 text-emerald-700 border border-emerald-200 rounded-lg text-xs font-semibold">${b}</span>`).join('')}
</div>
</div>
<div class="space-y-2 p-3.5 bg-slate-50/60 rounded-2xl border border-slate-100">
<div class="font-bold text-rose-800 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-rose-500"></span>
<span>برندهای رقیب خارجی (رسمی و خاکستری):</span>
</div>
<div class="flex flex-wrap gap-1.5">
${frBrands.map(b => `<span class="px-2 py-0.5 bg-rose-50 text-rose-700 border border-rose-200 rounded-lg text-xs font-semibold">${b}</span>`).join('')}
</div>
</div>
</div>
${searchQueries.length > 0 ? `
<div class="p-3 bg-blue-50/40 rounded-xl border border-blue-100 text-xs space-y-1.5">
<div class="font-bold text-blue-900 flex items-center gap-1.5">
<i data-lucide="search" class="w-3.5 h-3.5 text-blue-600"></i>
<span>پرسرج‌ترین کلمات کلیدی و برندهای این رده در پلتفرم:</span>
</div>
<div class="flex flex-wrap gap-1.5">
${searchQueries.map(q => `<span class="px-2.5 py-0.5 bg-white text-blue-800 border border-blue-200 rounded-md text-[11px] font-medium tnum">${q}</span>`).join('')}
</div>
</div>
` : ''}
<div class="space-y-2 text-xs">
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100 text-slate-600 leading-relaxed text-right">
<strong class="text-slate-900">موانع و گلوگاه‌های رگولاتوری:</strong> ${safeStr(cat.key_regulatory_barrier)}
</div>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-100 text-slate-600 leading-relaxed text-right">
<strong class="text-slate-900">دینامیک و تحولات بازار:</strong> ${safeStr(cat.dynamics_and_shifts)}
</div>
</div>
</div>
`;
}).join('');
console.log("✓ renderCategoriesFull completed with search queries");
} catch (e) {
console.error("Error in renderCategoriesFull:", e);
}
}
// -------------------------------------------------------------
// 13. SOURCES VAULT (PAGE SIZE, PROPER YEARS, FAST FILTER)
// -------------------------------------------------------------
let currentVaultPage = 1;
const vaultPageSize = 25;
let filteredSources = [];
function searchVault(page = 1) {
try {
const queryEl = document.getElementById('vault-search-box');
const platformEl = document.getElementById('vault-filter-platform');
const q = queryEl ? queryEl.value.trim().toLowerCase() : '';
const p = platformEl ? platformEl.value : 'all';
const sources = window.allSources || [];
filteredSources = sources.filter(s => {
const matchesP = (p === 'all') || (s.platform === p);
if (!matchesP) return false;
if (!q) return true;
return (
(s.title && s.title.toLowerCase().includes(q)) ||
(s.category && s.category.toLowerCase().includes(q)) ||
(s.summary && s.summary.toLowerCase().includes(q)) ||
(s.entities && s.entities.toLowerCase().includes(q))
);
});
currentVaultPage = page;
const totalPages = Math.ceil(filteredSources.length / vaultPageSize) || 1;
if (currentVaultPage > totalPages) currentVaultPage = totalPages;
if (currentVaultPage < 1) currentVaultPage = 1;
const startIdx = (currentVaultPage - 1) * vaultPageSize;
const pageItems = filteredSources.slice(startIdx, startIdx + vaultPageSize);
const tbody = document.getElementById('vault-table-rows');
if (tbody) {
tbody.innerHTML = pageItems.map(item => `
<tr class="hover:bg-slate-50/80 transition-colors">
<td class="p-3.5 tnum text-slate-400 text-[11px] tnum">${safeStr(item.id)}</td>
<td class="p-3.5 font-medium text-slate-800 max-w-md">
<div class="line-clamp-2">${safeStr(item.title)}</div>
</td>
<td class="p-3.5">
<span class="px-2.5 py-0.5 rounded-full text-[10px] font-bold ${item.platform === 'Aparat' ? 'bg-rose-50 text-rose-700 border border-rose-200' : 'bg-slate-100 text-slate-700'}">
${safeStr(item.platform)}
</span>
</td>
<td class="p-3.5 text-slate-600 text-xs font-medium">${safeStr(item.category)}</td>
<td class="p-3.5 tnum text-slate-600 text-xs tnum">${safeStr(item.publication_year || item.year || '۱۳۹۵-۱۴۰۴')}</td>
<td class="p-3.5">
${item.url ? `
<a href="${item.url}" target="_blank" class="inline-flex items-center gap-1 text-rose-600 hover:text-rose-800 font-bold bg-rose-50 hover:bg-rose-100 px-2.5 py-1 rounded-lg border border-rose-200 text-xs transition">
<span>مشاهده</span>
<i data-lucide="external-link" class="w-3 h-3"></i>
</a>
` : '—'}
</td>
</tr>
`).join('');
}
const counterEl = document.getElementById('vault-rows-counter');
if (counterEl) {
counterEl.innerText = `نمایش ${startIdx + 1} تا ${Math.min(startIdx + vaultPageSize, filteredSources.length)} از مجموع ${formatNumber(filteredSources.length)} منبع معتبر`;
}
const pageInfoEl = document.getElementById('vault-page-info');
if (pageInfoEl) {
pageInfoEl.innerText = `صفحه ${currentVaultPage} از ${totalPages}`;
}
const btnPrev = document.getElementById('vault-btn-prev');
const btnNext = document.getElementById('vault-btn-next');
if (btnPrev) btnPrev.disabled = (currentVaultPage <= 1);
if (btnNext) btnNext.disabled = (currentVaultPage >= totalPages);
safeCreateIcons();
} catch (e) {
console.error("Error in searchVault:", e);
}
}
function nextVaultPage() {
searchVault(currentVaultPage + 1);
}
function prevVaultPage() {
searchVault(currentVaultPage - 1);
}
// -------------------------------------------------------------
// 14. PLOTLY CHARTS (8 CHARTS TOTAL INCLUDING LOST BRAND MARKET)
// -------------------------------------------------------------
function initPlotlyCharts() {
if (typeof Plotly === 'undefined') {
console.warn("Plotly not available. Chart initialization skipped.");
return;
}
const defaultFont = { family: 'Vazirmatn, sans-serif', size: 11, color: '#0F172A' };
// Chart 1: Timeline Growth
try {
const timeline = getBundle().yearly_metrics || [];
const years = timeline.map(t => t.year_shamsi);
const skus = timeline.map(t => t.sku_count);
const sellers = timeline.map(t => t.active_sellers);
const traceSku = {
x: years,
y: skus,
name: 'تنوع کالا (SKU)',
type: 'scatter',
mode: 'lines+markers',
line: { shape: 'spline', smoothing: 1.3, color: '#4F46E5', width: 3 },
marker: { size: 6, color: '#4F46E5' },
fill: 'tozeroy',
fillcolor: 'rgba(79, 70, 229, 0.04)',
yaxis: 'y1'
};
const traceSellers = {
x: years,
y: sellers,
name: 'فروشندگان فعال',
type: 'scatter',
mode: 'lines+markers',
line: { shape: 'spline', smoothing: 1.3, color: '#059669', width: 2.5, dash: 'solid' },
marker: { size: 5, color: '#059669' },
yaxis: 'y2'
};
const layoutGrowth = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 60, r: 60, t: 30, b: 40 },
legend: { orientation: 'h', y: 1.15, x: 0.5, xanchor: 'center' },
xaxis: { gridcolor: '#F1F5F9', zeroline: false },
yaxis: { title: 'تنوع کالا (SKU - مقیاس لگاریتمی)', type: 'log', gridcolor: '#F1F5F9', zeroline: false },
yaxis2: { title: 'فروشندگان فعال', type: 'log', overlaying: 'y', side: 'right', gridcolor: 'transparent', zeroline: false }
};
Plotly.newPlot('plotly-timeline-growth', [traceSku, traceSellers], layoutGrowth, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-timeline-growth:", e);
}
// Chart 2: Brands Stacked
try {
const timeline = getBundle().yearly_metrics || [];
const years = timeline.map(t => t.year_shamsi);
const domestic = timeline.map(t => t.domestic_brand_share);
const foreign = timeline.map(t => t.foreign_brand_share);
const traceDom = {
x: years,
y: domestic,
name: 'سهم برندهای ایرانی (بومی)',
type: 'bar',
marker: { color: '#10B981' }
};
const traceFor = {
x: years,
y: foreign,
name: 'سهم برندهای خارجی',
type: 'bar',
marker: { color: '#F43F5E' }
};
const layoutBrands = {
barmode: 'stack',
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 50, r: 20, t: 30, b: 40 },
legend: { orientation: 'h', y: 1.15, x: 0.5, xanchor: 'center' },
xaxis: { gridcolor: '#F1F5F9', zeroline: false },
yaxis: { title: 'درصد سهم از سبد کالا', range: [0, 100], gridcolor: '#F1F5F9', zeroline: false }
};
Plotly.newPlot('plotly-brands-stacked', [traceDom, traceFor], layoutBrands, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-brands-stacked:", e);
}
// Chart 3: Quadrant Scatter
try {
const market = getBundle().market_channel_breakdown || [];
const xOnline = market.map(m => m.ecommerce_official_share);
const ySmuggle = market.map(m => m.smuggling_rate);
const labels = market.map(m => m.sector);
const traceScatter = {
x: xOnline,
y: ySmuggle,
text: labels,
mode: 'markers+text',
textposition: 'top center',
textfont: { size: 10, color: '#0F172A', family: 'Vazirmatn', weight: 'bold' },
marker: {
size: [32, 28, 42, 26, 24, 22],
color: ['#4F46E5', '#06B6D4', '#10B981', '#F59E0B', '#EC4899', '#8B5CF6'],
opacity: 0.9,
line: { width: 1.5, color: '#0F172A' }
},
type: 'scatter'
};
const layoutScatter = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 50, r: 30, t: 30, b: 50 },
xaxis: { title: 'نرخ نفوذ خرده‌فروشی آنلاین (٪)', gridcolor: '#F1F5F9', zeroline: false, range: [0, 35] },
yaxis: { title: 'نرخ تخمینی قاچاق و خاکستری (٪)', gridcolor: '#F1F5F9', zeroline: false, range: [0, 55] },
shapes: [
{ type: 'line', x0: 15, x1: 15, y0: 0, y1: 55, line: { dash: 'dash', color: '#CBD5E1', width: 1.5 } },
{ type: 'line', x0: 0, x1: 35, y0: 25, y1: 25, line: { dash: 'dash', color: '#CBD5E1', width: 1.5 } }
],
annotations: [
{ x: 30, y: 50, text: 'قاچاق بالا / آنلاین بالا', showarrow: false, font: { size: 9, color: '#94A3B8' } },
{ x: 5, y: 50, text: 'قاچاق بالا / آنلاین پایین', showarrow: false, font: { size: 9, color: '#94A3B8' } },
{ x: 30, y: 5, text: 'قاچاق پایین / آنلاین بالا', showarrow: false, font: { size: 9, color: '#94A3B8' } },
{ x: 5, y: 5, text: 'قاچاق پایین / آنلاین پایین', showarrow: false, font: { size: 9, color: '#94A3B8' } }
]
};
Plotly.newPlot('plotly-quadrant-scatter', [traceScatter], layoutScatter, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-quadrant-scatter:", e);
}
// Chart 4: Market Channels Grouped Bar
try {
const market = getBundle().market_channel_breakdown || [];
const sectors = market.map(m => m.sector.split(' ')[0]);
const ecom = market.map(m => m.ecommerce_official_share);
const social = market.map(m => m.social_commerce_share);
const offline = market.map(m => m.traditional_offline_share);
const tEcom = { x: sectors, y: ecom, name: 'ایکامرس رسمی', type: 'bar', marker: { color: '#4F46E5' } };
const tSocial = { x: sectors, y: social, name: 'سوشال / اینستاگرام', type: 'bar', marker: { color: '#E11D48' } };
const tOffline = { x: sectors, y: offline, name: 'بازار سنتی فیزیکی', type: 'bar', marker: { color: '#94A3B8' } };
const layoutChannels = {
barmode: 'group',
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 50, r: 20, t: 30, b: 40 },
legend: { orientation: 'h', y: 1.15, x: 0.5, xanchor: 'center' },
xaxis: { gridcolor: '#F1F5F9', zeroline: false },
yaxis: { title: 'درصد سهم کانال', range: [0, 100], gridcolor: '#F1F5F9', zeroline: false }
};
Plotly.newPlot('plotly-market-channels', [tEcom, tSocial, tOffline], layoutChannels, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-market-channels:", e);
}
// Chart 5: Revenue Models Donut (PROPORTIONAL REAL DATA)
try {
const revs = getBundle().revenue_models_data || [];
const labels = revs.map(r => r.name.split('(')[0].trim());
const values = revs.map(r => parsePersianFloat(r.share_of_revenue_1403));
const traceDonut = {
labels: labels,
values: values,
type: 'pie',
hole: 0.62,
marker: {
colors: ['#4F46E5', '#10B981', '#06B6D4', '#F59E0B', '#EC4899', '#8B5CF6', '#64748B']
},
textinfo: 'percent',
textposition: 'inside',
textfont: { family: 'Vazirmatn', size: 11, color: '#FFFFFF', weight: 'bold' },
insidetextorientation: 'horizontal',
hoverinfo: 'label+percent+value'
};
const layoutDonut = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 20, r: 20, t: 20, b: 60 },
showlegend: true,
legend: {
orientation: 'h',
y: -0.12,
x: 0.5,
xanchor: 'center',
font: { size: 10, family: 'Vazirmatn' }
},
annotations: [
{
font: { size: 13, family: 'Vazirmatn', weight: 'bold', color: '#0F172A' },
showarrow: false,
text: 'ترکیب سهم<br>درآمد ۱۴۰۳',
x: 0.5,
y: 0.5
}
]
};
Plotly.newPlot('plotly-revenue-donut', [traceDonut], layoutDonut, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-revenue-donut:", e);
}
// Chart 6: Brand Market Split (Stacked Horizontal Bar)
try {
const bData = getBundle().brand_market_intelligence || {};
const bCats = bData.categories || [];
const catNames = bCats.map(c => (c.name_fa || '').split('،')[0].trim());
const officialVals = bCats.map(c => c.official_pct || 0);
const unofficialVals = bCats.map(c => c.unofficial_pct || 0);
const officialIrr = bCats.map(c => c.official_irr || 0);
const unofficialIrr = bCats.map(c => c.unofficial_irr || 0);
const traceOfficial = {
y: catNames,
x: officialVals,
name: 'سهم کانال رسمی (تولید + واردات قانونی)',
type: 'bar',
orientation: 'h',
marker: { color: '#10B981' },
text: officialVals.map((v, i) => `${v}٪ (${officialIrr[i]} همت)`),
textposition: 'inside',
insidetextanchor: 'middle',
textfont: { color: '#FFFFFF', family: 'Vazirmatn', size: 10, weight: 'bold' }
};
const traceUnofficial = {
y: catNames,
x: unofficialVals,
name: 'سهم غیررسمی (قاچاق + خاکستری)',
type: 'bar',
orientation: 'h',
marker: { color: '#F43F5E' },
text: unofficialVals.map((v, i) => `${v}٪ (${unofficialIrr[i]} همت)`),
textposition: 'inside',
insidetextanchor: 'middle',
textfont: { color: '#FFFFFF', family: 'Vazirmatn', size: 10, weight: 'bold' }
};
const layoutSplit = {
barmode: 'stack',
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 120, r: 20, t: 30, b: 40 },
legend: { orientation: 'h', y: 1.15, x: 0.5, xanchor: 'center' },
xaxis: { title: 'درصد سهم از بازار', range: [0, 100], gridcolor: '#F1F5F9', zeroline: false },
yaxis: { autorange: 'reversed', gridcolor: '#F1F5F9', zeroline: false }
};
Plotly.newPlot('plotly-brand-market-split', [traceOfficial, traceUnofficial], layoutSplit, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-brand-market-split:", e);
}
// Chart 7: Brand Market Bubble
try {
const bData = getBundle().brand_market_intelligence || {};
const bCats = bData.categories || [];
const catNames = bCats.map(c => (c.name_fa || '').split('،')[0].trim());
const xDomestic = bCats.map(c => c.domestic_share_pct || 0);
const yUnofficial = bCats.map(c => c.unofficial_pct || 0);
const totalIrr = bCats.map(c => c.total_size_irr || 50);
const bubbleSizes = totalIrr.map(v => Math.max(24, Math.sqrt(v) * 2.8));
const traceBubble = {
x: xDomestic,
y: yUnofficial,
text: catNames.map((n, i) => `${n}<br>${totalIrr[i]} همت`),
mode: 'markers+text',
textposition: 'top center',
textfont: { size: 10, color: '#0F172A', family: 'Vazirmatn', weight: 'bold' },
marker: {
size: bubbleSizes,
color: ['#3B82F6', '#10B981', '#EC4899', '#8B5CF6', '#F59E0B', '#06B6D4', '#6366F1', '#14B8A6'],
opacity: 0.85,
line: { width: 1.5, color: '#0F172A' }
},
type: 'scatter'
};
const layoutBubble = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 50, r: 30, t: 30, b: 50 },
xaxis: { title: 'سهم برندهای بومی و ملی (٪)', gridcolor: '#F1F5F9', zeroline: false, range: [0, 105] },
yaxis: { title: 'نرخ قاچاق و توزیع غیررسمی (٪)', gridcolor: '#F1F5F9', zeroline: false, range: [0, 65] },
shapes: [
{ type: 'line', x0: 50, x1: 50, y0: 0, y1: 65, line: { dash: 'dot', color: '#CBD5E1', width: 1.5 } },
{ type: 'line', x0: 0, x1: 105, y0: 30, y1: 30, line: { dash: 'dot', color: '#CBD5E1', width: 1.5 } }
],
annotations: [
{ x: 90, y: 55, text: 'بومی بالا / قاچاق بالا (پوشاک)', showarrow: false, font: { size: 9, color: '#94A3B8' } },
{ x: 20, y: 55, text: 'بومی پایین / قاچاق بالا (آرایشی)', showarrow: false, font: { size: 9, color: '#94A3B8' } },
{ x: 90, y: 8, text: 'بومی بالا / قاچاق پایین (FMCG)', showarrow: false, font: { size: 9, color: '#94A3B8' } },
{ x: 20, y: 8, text: 'بومی پایین / قاچاق پایین (دیجیتال)', showarrow: false, font: { size: 9, color: '#94A3B8' } }
]
};
Plotly.newPlot('plotly-brand-market-bubble', [traceBubble], layoutBubble, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-brand-market-bubble:", e);
}
// Chart 8: Lost Brand Market Opportunity Donut (233 همت)
try {
const lostAnalysis = (getBundle().brand_market_intelligence || {}).lost_brand_market_analysis || {};
const breakdown = lostAnalysis.lost_opportunity_breakdown || [];
const labels = breakdown.map(b => b.channel.split('(')[0].trim());
const values = breakdown.map(b => b.addressable_potential_irr || 10);
const traceLost = {
labels: labels,
values: values,
type: 'pie',
hole: 0.65,
marker: {
colors: ['#3B82F6', '#EC4899', '#10B981', '#F59E0B']
},
textinfo: 'percent+label',
textposition: 'inside',
textfont: { family: 'Vazirmatn', size: 9, color: '#FFFFFF', weight: 'bold' },
insidetextorientation: 'horizontal'
};
const layoutLost = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 10, r: 10, t: 10, b: 20 },
legend: { orientation: 'h', y: -0.05, x: 0.5, xanchor: 'center', font: { size: 9 } },
annotations: [
{
font: { size: 12, family: 'Vazirmatn', weight: 'bold', color: '#0F172A' },
showarrow: false,
text: '۲۳۳ همت<br>پتانسیل کل',
x: 0.5,
y: 0.5
}
]
};
Plotly.newPlot('plotly-lost-brand-market', [traceLost], layoutLost, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-lost-brand-market:", e);
}
// Chart 0: Total Commerce Channels Donut (5,160 همت)
try {
const commData = getBundle().total_commerce_intelligence || {};
const chList = commData.commerce_channels || [];
const labels = chList.map(c => c.name.split('(')[0].trim());
const values = chList.map(c => c.volume_irr_t);
const traceComm = {
labels: labels,
values: values,
type: 'pie',
hole: 0.62,
marker: {
colors: ['#F59E0B', '#6366F1', '#EF4444', '#EC4899']
},
textinfo: 'percent+label',
textposition: 'inside',
textfont: { family: 'Vazirmatn', size: 9, color: '#FFFFFF', weight: 'bold' },
insidetextorientation: 'horizontal'
};
const layoutComm = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 10, r: 10, t: 10, b: 20 },
legend: { orientation: 'h', y: -0.08, x: 0.5, xanchor: 'center', font: { size: 9 } },
annotations: [
{
font: { size: 11, family: 'Vazirmatn', weight: 'bold', color: '#0F172A' },
showarrow: false,
text: '۵,۱۶۰ همت<br>کل کامرس کالایی',
x: 0.5,
y: 0.5
}
]
};
Plotly.newPlot('plotly-total-commerce-channels', [traceComm], layoutComm, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-total-commerce-channels:", e);
}
// Chart 9: Platforms Goods E-Commerce Share Donut (312 همت)
try {
const bData = getBundle().brand_market_intelligence || {};
const pShare = (bData.platforms_market_share || []).filter(p => !p.player.includes('سوشال'));
const labels = pShare.map(p => p.player.split('(')[0].trim());
const values = pShare.map(p => p.gmv_1403_irr_t);
const tracePlatform = {
labels: labels,
values: values,
type: 'pie',
hole: 0.62,
marker: {
colors: ['#EF4444', '#10B981', '#6366F1', '#3B82F6', '#F59E0B']
},
textinfo: 'percent+label',
textposition: 'inside',
textfont: { family: 'Vazirmatn', size: 9, color: '#FFFFFF', weight: 'bold' },
insidetextorientation: 'horizontal'
};
const layoutPlatform = {
font: defaultFont,
paper_bgcolor: '#FFFFFF',
plot_bgcolor: '#FFFFFF',
margin: { l: 10, r: 10, t: 10, b: 20 },
legend: { orientation: 'h', y: -0.08, x: 0.5, xanchor: 'center', font: { size: 9 } },
annotations: [
{
font: { size: 11, family: 'Vazirmatn', weight: 'bold', color: '#0F172A' },
showarrow: false,
text: '۳۱۲ همت<br>کل بازار کالا',
x: 0.5,
y: 0.5
}
]
};
Plotly.newPlot('plotly-platforms-share', [tracePlatform], layoutPlatform, { responsive: true, displayModeBar: false });
} catch (e) {
console.error("Error rendering plotly-platforms-share:", e);
}
}
// -------------------------------------------------------------
// 15. INITIALIZE DASHBOARD (MASTER ENTRY POINT)
// -------------------------------------------------------------
function initializeDashboard() {
console.log("Master initialization triggered...");
renderTotalCommerceIntelligence();
renderBrandMarketIntelligence();
renderWarTable();
renderContractsTable();
renderBrandEcosystem();
renderGrowthLevers();
renderRevenueModels();
renderTimelineCards('all');
renderExecutivesCards();
renderPlaybookSections();
renderPostmortemsGrid();
renderRegulatoryMatrix();
renderFounderWarStories();
renderLegalChallenges();
renderBrandPlatformFriction();
renderMarketTable();
renderCategoriesFull();
searchVault(1);
safeCreateIcons();
setTimeout(() => {
initPlotlyCharts();
safeCreateIcons();
}, 150);
const filterSel = document.getElementById('timeline-filter-select');
if (filterSel) {
filterSel.addEventListener('change', filterTimeline);
}
const searchBox = document.getElementById('vault-search-box');
if (searchBox) {
searchBox.addEventListener('input', () => searchVault(1));
}
const platFilter = document.getElementById('vault-filter-platform');
if (platFilter) {
platFilter.addEventListener('change', () => searchVault(1));
}
console.log("Executive Dashboard fully rendered with 0 errors!");
}
if (typeof window !== 'undefined') {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeDashboard);
} else {
initializeDashboard();
}
if (typeof window.addEventListener === 'function') window.addEventListener('resize', () => {
const pIds = [
'plotly-timeline-growth', 'plotly-brands-stacked', 'plotly-quadrant-scatter',
'plotly-market-channels', 'plotly-revenue-donut', 'plotly-brand-market-split',
'plotly-total-commerce-channels', 'plotly-brand-market-bubble', 'plotly-lost-brand-market', 'plotly-platforms-share'
];
pIds.forEach(id => {
const el = document.getElementById(id);
if (el && typeof Plotly !== 'undefined') {
Plotly.Plots.resize(el);
}
});
});
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
initializeDashboard,
renderBrandMarketIntelligence,
renderWarTable,
renderContractsTable,
renderBrandEcosystem,
renderGrowthLevers,
renderRevenueModels,
renderTimelineCards,
renderExecutivesCards,
renderPlaybookSections,
renderPostmortemsGrid,
renderRegulatoryMatrix,
renderFounderWarStories,
renderLegalChallenges,
renderBrandPlatformFriction,
renderMarketTable,
renderCategoriesFull,
searchVault,
initPlotlyCharts
};
}