// Advanced BI Logic for Iranian Ecommerce Intelligence Dashboard v2 // Built with Plotly.js, Vazirmatn Typography and Executive BI Layouts const bundle = window.bundle || {}; const allSources = window.allSources || []; // 1. Render Executives Intelligence Dossier function renderExecutives() { const container = document.getElementById('executives-cards-grid'); if (!container) return; container.innerHTML = (bundle.executives_dossier || []).map(exec => `
${exec.id}

${exec.name}

${exec.current_role}
${exec.tenure_in_ecom}
سوابق کلیدی: ${exec.past_roles}
موضع استراتژیک درباره فروش برندها: ${exec.stance_on_brands}
اقدامات عملیاتی در تعامل با برندها: ${exec.brand_cooperation_initiatives}
مصاحبه‌های تصویری و اسناد فکت‌چک شده:
${(exec.direct_interviews || []).map(inv => ` ${inv.title} ${inv.platform} (${inv.year}) → `).join('')}
`).join(''); } // 2. Render Brands Matrix Table function renderBrandsTable() { const tbody = document.getElementById('brands-matrix-tbody'); if (!tbody) return; tbody.innerHTML = (bundle.brands_matrix || []).map(b => ` ${b.brand_name} ${b.origin} ${b.sector} ${b.has_official_brandstore ? 'بله (VIP)' : 'خیر'} ${b.reports_sales_officially ? 'گزارش رسمی داده' : 'بدون انتشار'} ${b.cooperation_model} ${b.official_stance} ${b.conflicts_and_resolutions} مستندات `).join(''); } // 3. Render Strategic Playbook Pillars function renderPlaybook() { const p = bundle.strategic_playbook || {}; const brandContainer = document.getElementById('playbook-brands-list'); if (brandContainer && p.how_digikala_convinced_brands) { brandContainer.innerHTML = p.how_digikala_convinced_brands.map(item => `

${item.title}

${item.strategy}

نتیجه مستند: ${item.verified_result}
`).join(''); } const userContainer = document.getElementById('playbook-users-list'); if (userContainer && p.how_digikala_convinced_users) { userContainer.innerHTML = p.how_digikala_convinced_users.map(item => `

${item.title}

${item.strategy}

نتیجه مستند: ${item.verified_result}
`).join(''); } const cannibalContainer = document.getElementById('playbook-cannibal-list'); if (cannibalContainer && p.how_digikala_resolved_internal_cannibalization) { cannibalContainer.innerHTML = p.how_digikala_resolved_internal_cannibalization.map(item => `

${item.conflict_name}

ریشه تعارض داخلی: ${item.issue}
راهکار تثبیت‌شده: ${item.resolution}
دستاورد کمی: ${item.impact}
`).join(''); } } // 4. Render Deep Failures & Pivots function renderFailures() { const container = document.getElementById('failures-deep-grid'); if (!container) return; container.innerHTML = (bundle.failures_pivots || []).map(item => `
${item.id} (${item.year})

${item.title}

دسته‌بندی: ${item.category}
مستندات
علت ریشه‌ای وقوع:

${item.root_cause}

نحوه مداخله و اجرا:

${item.execution}

تبعات و شوک اولیه:

${item.consequences}

راهکار پایدار و وضعیت فعلی:

${item.resolution}

`).join(''); } // 5. Render Industry Breakdown Cards function renderIndustryBreakdown() { const container = document.getElementById('industry-breakdown-cards'); if (!container) return; container.innerHTML = (bundle.industry_breakdown || []).map(ind => `

${ind.sector}

نسبت فروش ایرانی به خارجی: ${ind.ratio_domestic_to_foreign}
اندازه بازار: ${ind.total_market_size_irr} نفوذ آنلاین: ${ind.ecommerce_share_percent}٪ سوشال کامرس: ${ind.social_commerce_share_percent}٪ نرخ قاچاق: ${ind.smuggling_rate_percent}٪
پرفروش‌ترین و پرسرچ‌ترین برندهای ایرانی:
${ind.top_searched_brands_domestic.join(' • ')}
پرفروش‌ترین و پرسرچ‌ترین برندهای خارجی:
${ind.top_searched_brands_foreign.join(' • ')}
گلوگاه‌های رگولاتوری، گمرکی و استاندارد:

${ind.regulatory_bottlenecks}

کانال‌ها و شیوه‌های ورود کالای قاچاق:

${ind.smuggling_channels}

`).join(''); } // 6. Real-time Search in 2,622 Sources Vault function searchIntelVault() { const qEl = document.getElementById('intel-search-input'); const platEl = document.getElementById('intel-platform-select'); const q = qEl ? qEl.value.toLowerCase().trim() : ''; const p = platEl ? platEl.value : 'all'; const tbody = document.getElementById('intel-sources-tbody'); if (!tbody) return; tbody.innerHTML = ''; const filtered = allSources.filter(s => { const matchQ = !q || (s.title && s.title.toLowerCase().includes(q)) || (s.summary && s.summary.toLowerCase().includes(q)) || (s.brand_or_person && s.brand_or_person.toLowerCase().includes(q)); const matchP = p === 'all' || (s.platform && s.platform.includes(p)); return matchQ && matchP; }); const counter = document.getElementById('intel-sources-counter'); if (counter) { counter.innerText = `نمایش ${filtered.length.toLocaleString('fa-IR')} از ${allSources.length.toLocaleString('fa-IR')} منبع مستند و فکت‌چک شده`; } filtered.slice(0, 150).forEach(s => { const tr = document.createElement('tr'); tr.className = "hover:bg-slate-50 transition border-b border-slate-100"; tr.innerHTML = ` ${s.id} ${s.title} ${s.platform || 'وب'} ${s.category || 'عمومی'} ${s.publication_year || '—'} ${s.brand_or_person || '—'} مشاهده `; tbody.appendChild(tr); }); if (window.lucide) lucide.createIcons(); } // 7. Initialize Executive BI Plotly Visualizations function initIntelPlotlyCharts() { if (typeof Plotly === 'undefined') return; const defaultFont = { family: 'Vazirmatn, sans-serif', size: 11, color: '#0F172A' }; const ind = bundle.industry_breakdown || []; const secNames = ind.map(d => d.sector.split('(')[0].trim()); // 1. Quadrant Scatter: Penetration vs Smuggling const xPen = ind.map(d => d.ecommerce_share_percent); const ySmug = ind.map(d => d.smuggling_rate_percent); const sizes = [42, 34, 28, 38, 52, 22]; // Market scale proportional const traceQuad = { x: xPen, y: ySmug, text: secNames, mode: 'markers+text', textposition: 'top center', textfont: { size: 11, color: '#0F172A', family: 'Vazirmatn' }, marker: { size: sizes, color: ['#2563EB', '#10B981', '#F59E0B', '#8B5CF6', '#EC4899', '#06B6D4'], opacity: 0.85, line: { width: 2, color: '#0F172A' } }, type: 'scatter' }; const layoutQuad = { font: defaultFont, paper_bgcolor: '#FFFFFF', plot_bgcolor: '#F8FAFC', margin: { l: 50, r: 40, t: 30, b: 50 }, xaxis: { title: 'نفوذ ایکامرس رسمی (درصد)', gridcolor: '#E2E8F0', range: [0, 35] }, yaxis: { title: 'نرخ تخمینی قاچاق در بازار (درصد)', gridcolor: '#E2E8F0', range: [0, 65] }, shapes: [ { type: 'line', x0: 15, x1: 15, y0: 0, y1: 65, line: { color: '#94A3B8', width: 1.5, dash: 'dash' } }, { type: 'line', x0: 0, x1: 35, y0: 25, y1: 25, line: { color: '#94A3B8', width: 1.5, dash: 'dash' } } ], annotations: [ { x: 25, y: 55, xref: 'x', yref: 'y', text: 'ناحیه ۱: نفوذ بالا / قاچاق بالا (موبایل و الکترونیک)', showarrow: false, font: { size: 10, color: '#DC2626' } }, { x: 25, y: 10, xref: 'x', yref: 'y', text: 'ناحیه ۲: نفوذ بالا / قاچاق مهارشده (کالای رسمی)', showarrow: false, font: { size: 10, color: '#059669' } }, { x: 6, y: 55, xref: 'x', yref: 'y', text: 'ناحیه ۳: قاچاق سنتی شدید (پوشاک و لوازم خانگی)', showarrow: false, font: { size: 10, color: '#D97706' } }, { x: 6, y: 10, xref: 'x', yref: 'y', text: 'ناحیه ۴: ایکامرس نوپا (FMCG و لبنیات)', showarrow: false, font: { size: 10, color: '#2563EB' } } ] }; Plotly.newPlot('plotly-quadrant-intel', [traceQuad], layoutQuad, { responsive: true, displayModeBar: false }); // 2. Channels Mix Stacked Bar const traceEcom = { x: secNames, y: ind.map(d => d.ecommerce_share_percent), name: 'ایکامرس رسمی', type: 'bar', marker: { color: '#2563EB' } }; const traceSoc = { x: secNames, y: ind.map(d => d.social_commerce_share_percent), name: 'اینستاگرام و سوشال', type: 'bar', marker: { color: '#8B5CF6' } }; const traceTrad = { x: secNames, y: ind.map(d => d.traditional_offline_share_percent), name: 'بازار سنتی فیزیکی', type: 'bar', marker: { color: '#CBD5E1' } }; const layoutChannels = { barmode: 'stack', font: defaultFont, paper_bgcolor: '#FFFFFF', plot_bgcolor: '#F8FAFC', margin: { l: 40, r: 20, t: 30, b: 40 }, legend: { orientation: 'h', y: 1.15, x: 0.5, xanchor: 'center' }, xaxis: { gridcolor: '#E2E8F0' }, yaxis: { range: [0, 100], gridcolor: '#E2E8F0', title: 'درصد از کل بازار صنعت' } }; Plotly.newPlot('plotly-channels-intel', [traceEcom, traceSoc, traceTrad], layoutChannels, { responsive: true, displayModeBar: false }); } // Global initialization document.addEventListener('DOMContentLoaded', () => { renderExecutives(); renderBrandsTable(); renderPlaybook(); renderFailures(); renderIndustryBreakdown(); searchIntelVault(); initIntelPlotlyCharts(); if (window.lucide) lucide.createIcons(); });