<?php
/** @var array<string,mixed> $report */
/** @var array<int,array<string,mixed>> $catalog */
/** @var array<string,mixed> $approvedContract */
/** @var array<string,string> $filters */
/** @var array<int,string> $allowedSites */
/** @var array<int,array<string,mixed>> $exportHistory */
/** @var string $loadError */
$isAr = current_lang() === 'ar';
$tr = static function (string $en, string $ar) use ($isAr): string { return $isAr ? $ar : $en; };
$report = is_array($report ?? null) ? $report : [];
$catalog = is_array($catalog ?? null) ? $catalog : [];
$approvedContract = is_array($approvedContract ?? null) ? $approvedContract : [];
$filters = is_array($filters ?? null) ? $filters : [];
$allowedSites = is_array($allowedSites ?? null) ? $allowedSites : [];
$exportHistory = is_array($exportHistory ?? null) ? $exportHistory : [];
$loadError = (string)($loadError ?? '');
$summary = is_array($report['summary'] ?? null) ? $report['summary'] : [];
$daily = is_array($report['daily_distribution'] ?? null) ? $report['daily_distribution'] : [];
$cases = is_array($report['cases'] ?? null) ? $report['cases'] : [];
$stores = is_array($report['store_analysis'] ?? null) ? $report['store_analysis'] : [];
$movements = is_array($report['movement_analysis'] ?? null) ? $report['movement_analysis'] : [];
$items = is_array($report['item_analysis'] ?? null) ? $report['item_analysis'] : [];
$users = is_array($report['user_associations'] ?? null) ? $report['user_associations'] : [];
$stats = is_array($report['statistical_comparisons'] ?? null) ? $report['statistical_comparisons'] : [];
$snapshots = is_array($report['snapshot_library'] ?? null) ? $report['snapshot_library'] : [];
$insights = is_array($report['insights'] ?? null) ? $report['insights'] : [];
$recommendations = is_array($report['recommendations'] ?? null) ? $report['recommendations'] : [];
$monthOptions = is_array($report['month_options'] ?? null) ? $report['month_options'] : [];
$selectedMonth = (string)($report['selected_month'] ?? $filters['month'] ?? '');
$monthStatus = (string)($report['month_status'] ?? '');
$total = (int)($summary['case_count'] ?? $summary['detected_count'] ?? count($cases));
$critical = (int)($summary['critical_count'] ?? 0);
$high = (int)($summary['high_count'] ?? 0);
$medium = (int)($summary['medium_count'] ?? 0);
$cost = (float)($summary['inventory_cost_abs'] ?? 0);
$groups = (int)($summary['movement_groups_reviewed'] ?? 0);
$transactions = (int)($summary['candidate_txn_count'] ?? 0);
$lines = (int)($summary['candidate_line_count'] ?? 0);
$caseShare = $groups > 0 ? $total / $groups : 0.0;
$number = static function ($value): string { return number_format((float)$value, 0, '.', ','); };
$money = static function ($value) use ($isAr): string { return number_format((float)$value, 2, '.', ',') . ' ' . ($isAr ? 'ر.س' : 'SAR'); };
$pct = static function ($value): string { return number_format((float)$value * 100, 1) . '%'; };
$limitRows = static function (array $rows, int $limit = 30): array { return array_slice($rows, 0, $limit); };
$maxValue = static function (array $rows, string $key): float {
    $max = 0.0; foreach ($rows as $row) $max = max($max, (float)($row[$key] ?? 0)); return max(1.0, $max);
};
$dailyCasesMax = $maxValue($daily, 'cases');
$dailyCostMax = $maxValue($daily, 'cost_value');
$linePoints = static function (array $rows, string $key, float $max, float $width, float $height): string {
    $count = count($rows); if ($count === 0) return '';
    $points = [];
    foreach ($rows as $i => $row) {
        $x = $count <= 1 ? 0 : ($i / ($count - 1)) * $width;
        $y = $height - (((float)($row[$key] ?? 0) / max(1.0, $max)) * $height);
        $points[] = number_format($x, 2, '.', '') . ',' . number_format($y, 2, '.', '');
    }
    return implode(' ', $points);
};
$scopeQuery = [
    'site' => strtoupper((string)($filters['site'] ?? 'ALL')),
    'month' => $selectedMonth,
    'lang' => current_lang(),
];
$queryString = http_build_query($scopeQuery);
?>
<link rel="stylesheet" href="assets/css/diar-workspace.css?v=diar-reports">
<link rel="stylesheet" href="assets/css/diar-reports-r65.css?v=diar-6b-5-r2">

<section class="diar-r2-page" data-diar-r2-reports>
    <nav class="diar-r2-tabs" aria-label="<?= e($tr('Report center navigation', 'التنقل في مركز التقارير')) ?>">
        <button type="button" class="is-active" data-r2-tab="dashboard"><?= e($tr('Executive dashboard', 'لوحة التقرير التنفيذي')) ?></button>
        <button type="button" data-r2-tab="details"><?= e($tr('Detailed report', 'التقرير التفصيلي')) ?></button>
        <button type="button" data-r2-tab="exports"><?= e($tr('Excel & PowerPoint', 'Excel وPowerPoint')) ?></button>
        <button type="button" data-r2-tab="snapshots"><?= e($tr('Snapshots & history', 'النسخ وسجل التصدير')) ?></button>
    </nav>

    <header class="diar-r2-hero">
        <div>
            <span><?= e($tr('FROZEN EXECUTIVE REPORTING', 'تقارير تنفيذية مرتبطة بنسخ مجمدة')) ?></span>
            <h1><?= e($tr('DIAR Reports & Export Center', 'مركز تقارير وتصدير DIAR')) ?></h1>
            <p><?= e($tr(
                'Executive statistics, decision-ready charts and exact exports generated from the approved twelve-sheet workbook and the selected closed snapshot.',
                'إحصائيات تنفيذية ورسوم جاهزة للقرار وتصديرات مطابقة للمصنف المعتمد ذي الاثنتي عشرة ورقة والنسخة الشهرية المغلقة المحددة.'
            )) ?></p>
            <div class="diar-r2-tags"><span><?= e($tr('Exact approved Excel', 'Excel مطابق للتقرير المعتمد')) ?></span><span><?= e($tr('Professional 16:9 PowerPoint', 'PowerPoint احترافي 16:9')) ?></span><span><?= e($tr('No operational writes', 'لا كتابة تشغيلية')) ?></span></div>
        </div>
        <aside>
            <small><?= e($tr('Current report binding', 'ربط التقرير الحالي')) ?></small>
            <strong><?= e(strtoupper((string)($filters['site'] ?? 'ALL'))) ?></strong>
            <span><?= e($selectedMonth !== '' ? $selectedMonth : '—') ?> · <?= e($monthStatus !== '' ? $monthStatus : '—') ?></span>
            <em><?= e(substr((string)($approvedContract['sha256'] ?? ''), 0, 12)) ?>…</em>
        </aside>
    </header>

    <?php if ($loadError !== ''): ?><div class="diar-r2-alert is-error"><?= e($loadError) ?></div><?php endif; ?>

    <form method="get" action="<?= e(url_to('diar-reports')) ?>" class="diar-r2-filter">
        <input type="hidden" name="page" value="diar-reports"><input type="hidden" name="lang" value="<?= e(current_lang()) ?>">
        <label><span><?= e($tr('Hospital scope', 'نطاق المستشفى')) ?></span><select name="site">
            <?php if (count($allowedSites) >= 2): ?><option value="ALL" <?= strtoupper((string)($filters['site'] ?? 'ALL')) === 'ALL' ? 'selected' : '' ?>><?= e($tr('HMH combined — MNH + NJCH', 'HMH مجمع — MNH + NJCH')) ?></option><?php endif; ?>
            <?php foreach ($allowedSites as $site): ?><option value="<?= e($site) ?>" <?= strtoupper((string)($filters['site'] ?? 'ALL')) === $site ? 'selected' : '' ?>><?= e($site) ?></option><?php endforeach; ?>
        </select></label>
        <label><span><?= e($tr('Frozen month', 'الشهر المجمد')) ?></span><select name="month"><option value=""><?= e($tr('Latest closed month', 'أحدث شهر مغلق')) ?></option>
            <?php foreach ($monthOptions as $option): $value=(string)($option['month_key'] ?? $option['month'] ?? ''); if($value==='') continue; ?><option value="<?= e($value) ?>" <?= $selectedMonth === $value ? 'selected' : '' ?>><?= e($value) ?> · <?= e((string)($option['status_code'] ?? '')) ?></option><?php endforeach; ?>
        </select></label>
        <button type="submit"><?= e($tr('Refresh report', 'تحديث التقرير')) ?></button>
    </form>

    <section class="diar-r2-panel is-active" data-r2-panel="dashboard">
        <div class="diar-r2-kpis">
            <article><span><?= e($tr('Review cases', 'حالات المراجعة')) ?></span><strong><?= e($number($total)) ?></strong><small><?= e($pct($caseShare)) ?> <?= e($tr('of reviewed movements', 'من الحركات المراجعة')) ?></small></article>
            <article class="critical"><span><?= e($tr('Critical', 'حرجة')) ?></span><strong><?= e($number($critical)) ?></strong><small><?= e($total > 0 ? $pct($critical/$total) : '0%') ?></small></article>
            <article class="high"><span><?= e($tr('High', 'عالية')) ?></span><strong><?= e($number($high)) ?></strong><small><?= e($total > 0 ? $pct($high/$total) : '0%') ?></small></article>
            <article><span><?= e($tr('Medium', 'متوسطة')) ?></span><strong><?= e($number($medium)) ?></strong><small><?= e($total > 0 ? $pct($medium/$total) : '0%') ?></small></article>
            <article class="cost"><span><?= e($tr('Associated inventory cost', 'تكلفة المخزون المرتبطة')) ?></span><strong><?= e($money($cost)) ?></strong><small><?= e($tr('Not confirmed loss', 'ليست خسارة مؤكدة')) ?></small></article>
            <article><span><?= e($tr('Transactions', 'المعاملات')) ?></span><strong><?= e($number($transactions)) ?></strong><small><?= e($number($lines)) ?> <?= e($tr('movement lines', 'سطر حركة')) ?></small></article>
        </div>

        <div class="diar-r2-chart-grid">
            <article class="diar-r2-chart-card severity-card">
                <header><div><span><?= e($tr('PRIORITY DISTRIBUTION', 'توزيع الأولويات')) ?></span><h2><?= e($tr('Cases requiring review', 'الحالات التي تتطلب مراجعة')) ?></h2></div></header>
                <?php $criticalPct=$total>0?$critical/$total:0; $highPct=$total>0?$high/$total:0; ?>
                <div class="diar-r2-donut" style="--critical:<?= e(number_format($criticalPct*360,2,'.','')) ?>deg;--high:<?= e(number_format(($criticalPct+$highPct)*360,2,'.','')) ?>deg"><strong><?= e($number($total)) ?></strong><span><?= e($tr('total cases', 'إجمالي الحالات')) ?></span></div>
                <dl><div><i class="critical"></i><dt><?= e($tr('Critical', 'حرجة')) ?></dt><dd><?= e($number($critical)) ?></dd></div><div><i class="high"></i><dt><?= e($tr('High', 'عالية')) ?></dt><dd><?= e($number($high)) ?></dd></div><div><i class="medium"></i><dt><?= e($tr('Medium', 'متوسطة')) ?></dt><dd><?= e($number($medium)) ?></dd></div></dl>
            </article>

            <article class="diar-r2-chart-card trend-card">
                <header><div><span><?= e($tr('DAILY TREND', 'الاتجاه اليومي')) ?></span><h2><?= e($tr('Cases and associated cost', 'الحالات والتكلفة المرتبطة')) ?></h2></div></header>
                <?php if ($daily !== []): ?><svg viewBox="0 0 800 260" preserveAspectRatio="none" aria-label="<?= e($tr('Daily cases and cost chart', 'رسم الحالات والتكلفة اليومي')) ?>"><line x1="0" y1="230" x2="800" y2="230" class="axis"/><polyline points="<?= e($linePoints($daily,'cases',$dailyCasesMax,800,210)) ?>" class="cases-line"/><polyline points="<?= e($linePoints($daily,'cost_value',$dailyCostMax,800,210)) ?>" class="cost-line"/></svg><div class="trend-legend"><span class="cases"><?= e($tr('Review cases', 'حالات المراجعة')) ?></span><span class="cost"><?= e($tr('Associated cost', 'التكلفة المرتبطة')) ?></span></div><?php else: ?><div class="diar-r2-empty"><?= e($tr('No daily trend is available.', 'لا يوجد اتجاه يومي متاح.')) ?></div><?php endif; ?>
            </article>

            <article class="diar-r2-chart-card">
                <header><div><span><?= e($tr('TOP STORES', 'أعلى المخازن')) ?></span><h2><?= e($tr('By review-case concentration', 'حسب تركيز حالات المراجعة')) ?></h2></div></header>
                <div class="diar-r2-bars"><?php $maxStore=$maxValue($stores,'cases'); foreach(array_slice($stores,0,6) as $row): ?><div><header><strong><?= e((string)($row['store']??'')) ?></strong><span><?= e($number($row['cases']??0)) ?></span></header><i><b style="width:<?= e(number_format(((float)($row['cases']??0)/$maxStore)*100,2,'.','')) ?>%"></b></i><small><?= e($money($row['cost_value']??0)) ?></small></div><?php endforeach; ?></div>
            </article>

            <article class="diar-r2-chart-card">
                <header><div><span><?= e($tr('TOP MOVEMENT TYPES', 'أعلى أنواع الحركات')) ?></span><h2><?= e($tr('Review cases and direction', 'حالات المراجعة والاتجاه')) ?></h2></div></header>
                <div class="diar-r2-bars teal"><?php $maxMove=$maxValue($movements,'cases'); foreach(array_slice($movements,0,6) as $row): ?><div><header><strong><?= e((string)($row['movement_type']??'')) ?></strong><span><?= e($number($row['cases']??0)) ?></span></header><i><b style="width:<?= e(number_format(((float)($row['cases']??0)/$maxMove)*100,2,'.','')) ?>%"></b></i><small><?= e((string)($row['direction']??'')) ?> · <?= e($money($row['cost_value']??0)) ?></small></div><?php endforeach; ?></div>
            </article>
        </div>

        <div class="diar-r2-decision-grid">
            <article><span><?= e($tr('MANAGEMENT INTERPRETATION', 'التفسير الإداري')) ?></span><h2><?= e($tr('What the numbers mean', 'ماذا تعني الأرقام')) ?></h2><ol><?php foreach(array_slice($insights,0,6) as $text): ?><li><?= e((string)$text) ?></li><?php endforeach; ?></ol></article>
            <article class="actions"><span><?= e($tr('DECISION AGENDA', 'أجندة القرارات')) ?></span><h2><?= e($tr('Recommended review sequence', 'تسلسل المراجعة المقترح')) ?></h2><ol><?php foreach(array_slice($recommendations,0,5) as $text): ?><li><?= e((string)$text) ?></li><?php endforeach; ?></ol></article>
        </div>
    </section>

    <section class="diar-r2-panel" data-r2-panel="details" hidden>
        <header class="diar-r2-section-head"><div><span><?= e($tr('DETAILED REPORT PREVIEW', 'معاينة التقرير التفصيلي')) ?></span><h2><?= e($tr('Actual frozen data, not metadata', 'بيانات مجمدة فعلية وليست معلومات هيكلية')) ?></h2></div><small><?= e($tr('The Excel export contains every row.', 'يحتوي تصدير Excel على جميع الصفوف.')) ?></small></header>
        <div class="diar-r2-detail-tabs">
            <button type="button" class="is-active" data-detail-tab="daily"><?= e($tr('Daily distribution', 'التوزيع اليومي')) ?></button><button type="button" data-detail-tab="cases"><?= e($tr('All cases', 'جميع الحالات')) ?></button><button type="button" data-detail-tab="stores"><?= e($tr('Stores', 'المخازن')) ?></button><button type="button" data-detail-tab="movements"><?= e($tr('Movement types', 'أنواع الحركات')) ?></button><button type="button" data-detail-tab="items"><?= e($tr('Items', 'الأصناف')) ?></button><button type="button" data-detail-tab="users"><?= e($tr('Users', 'المستخدمون')) ?></button><button type="button" data-detail-tab="stats"><?= e($tr('Statistical comparisons', 'المقارنات الإحصائية')) ?></button>
        </div>
        <div class="diar-r2-table-panel is-active" data-detail-panel="daily"><div class="diar-r2-table-wrap"><table><thead><tr><th><?= e($tr('Date','التاريخ')) ?></th><th><?= e($tr('Groups reviewed','المجموعات المراجعة')) ?></th><th><?= e($tr('Cases','الحالات')) ?></th><th><?= e($tr('Critical','حرجة')) ?></th><th><?= e($tr('High','عالية')) ?></th><th><?= e($tr('Medium','متوسطة')) ?></th><th><?= e($tr('Cost','التكلفة')) ?></th><th><?= e($tr('Operational note','ملاحظة تشغيلية')) ?></th></tr></thead><tbody><?php foreach($limitRows($daily,40) as $row): ?><tr><td><?= e((string)($row['date']??'')) ?></td><td><?= e($number($row['movement_groups_reviewed']??0)) ?></td><td><?= e($number($row['cases']??0)) ?></td><td><?= e($number($row['critical']??0)) ?></td><td><?= e($number($row['high']??0)) ?></td><td><?= e($number($row['medium']??0)) ?></td><td><?= e($money($row['cost_value']??0)) ?></td><td><?= e((string)($row['operational_note']??'')) ?></td></tr><?php endforeach; ?></tbody></table></div></div>
        <div class="diar-r2-table-panel" data-detail-panel="cases" hidden><div class="diar-r2-table-wrap"><table><thead><tr><th>#</th><th><?= e($tr('Case','الحالة')) ?></th><th><?= e($tr('Date','التاريخ')) ?></th><th><?= e($tr('Priority','الأولوية')) ?></th><th><?= e($tr('Score','الدرجة')) ?></th><th><?= e($tr('Store','المخزن')) ?></th><th><?= e($tr('Item','الصنف')) ?></th><th><?= e($tr('Movement','الحركة')) ?></th><th><?= e($tr('Value','القيمة')) ?></th><th><?= e($tr('Reason','السبب')) ?></th></tr></thead><tbody><?php foreach($limitRows($cases,50) as $row): ?><tr><td><?= e($number($row['rank']??0)) ?></td><td><?= e((string)($row['case_id']??'')) ?></td><td><?= e((string)($row['calendar_day']??'')) ?></td><td><span class="priority <?= e(strtolower((string)($row['priority']??''))) ?>"><?= e((string)($row['priority']??'')) ?></span></td><td><?= e(number_format((float)($row['score']??0),1)) ?></td><td><?= e((string)($row['store_display']??'')) ?></td><td><?= e((string)($row['item_display']??'')) ?></td><td><?= e((string)($row['movement_display']??'')) ?></td><td><?= e($money($row['case_value']??0)) ?></td><td><?= e((string)($row['reason']??'')) ?></td></tr><?php endforeach; ?></tbody></table></div></div>
        <?php foreach(['stores'=>$stores,'movements'=>$movements,'items'=>$items,'users'=>$users] as $panel=>$rows): ?><div class="diar-r2-table-panel" data-detail-panel="<?= e($panel) ?>" hidden><div class="diar-r2-analysis-cards"><?php foreach(array_slice($rows,0,30) as $row): ?><article><strong><?= e((string)($row[$panel==='stores'?'store':($panel==='movements'?'movement_type':($panel==='items'?'item':'user'))]??'')) ?></strong><span><?= e($number($row[$panel==='users'?'unique_cases':'cases']??0)) ?> <?= e($tr('cases','حالة')) ?></span><small><?= e($money($row[$panel==='users'?'line_value':'cost_value']??0)) ?></small></article><?php endforeach; ?></div></div><?php endforeach; ?>
        <div class="diar-r2-table-panel" data-detail-panel="stats" hidden><div class="diar-r2-table-wrap"><table><thead><tr><th><?= e($tr('Case','الحالة')) ?></th><th><?= e($tr('Priority','الأولوية')) ?></th><th><?= e($tr('Observed quantity','الكمية المرصودة')) ?></th><th>P95</th><th>P99</th><th><?= e($tr('Observed cost','التكلفة المرصودة')) ?></th><th>P95</th><th>P99</th><th><?= e($tr('Transactions','المعاملات')) ?></th><th><?= e($tr('Days since activity','الأيام منذ النشاط')) ?></th></tr></thead><tbody><?php foreach($limitRows($stats,50) as $row): ?><tr><td><?= e((string)($row['case_id']??'')) ?></td><td><?= e((string)($row['priority']??'')) ?></td><td><?= e(number_format((float)($row['qty_obs']??0),2)) ?></td><td><?= e($row['qty_p95']===null?'—':number_format((float)$row['qty_p95'],2)) ?></td><td><?= e($row['qty_p99']===null?'—':number_format((float)$row['qty_p99'],2)) ?></td><td><?= e(number_format((float)($row['value_obs']??0),2)) ?></td><td><?= e($row['value_p95']===null?'—':number_format((float)$row['value_p95'],2)) ?></td><td><?= e($row['value_p99']===null?'—':number_format((float)$row['value_p99'],2)) ?></td><td><?= e(number_format((float)($row['txn_obs']??0),2)) ?></td><td><?= e(number_format((float)($row['days_since_activity']??0),0)) ?></td></tr><?php endforeach; ?></tbody></table></div></div>
    </section>

    <section class="diar-r2-panel" data-r2-panel="exports" hidden>
        <div class="diar-r2-export-hero"><div><span><?= e($tr('CONTROLLED GENERATION', 'توليد محكوم')) ?></span><h2><?= e($tr('Generate the exact Excel workbook or an executive PowerPoint', 'إنشاء ملف Excel مطابق أو PowerPoint تنفيذي')) ?></h2><p><?= e($tr('Both files use the same frozen data, totals and source identities displayed on this page.', 'يستخدم الملفان نفس البيانات المجمدة والإجماليات وهويات المصادر المعروضة في هذه الصفحة.')) ?></p></div><div class="diar-r2-export-actions"><a class="excel" href="<?= e(url_to('diar-report-excel')) ?>&amp;<?= e($queryString) ?>"><strong>Excel</strong><span><?= e($tr('Approved 12-sheet workbook', 'المصنف المعتمد من 12 ورقة')) ?></span><small><?= e($tr('Generate and download', 'إنشاء وتنزيل')) ?> →</small></a><a class="ppt" href="<?= e(url_to('diar-report-powerpoint')) ?>&amp;<?= e($queryString) ?>"><strong>PowerPoint</strong><span><?= e($tr('Professional 12-slide executive brief', 'عرض تنفيذي احترافي من 12 شريحة')) ?></span><small><?= e($tr('Generate and download', 'إنشاء وتنزيل')) ?> →</small></a></div></div>
        <section class="diar-r2-workbook-contract"><header><div><span><?= e($tr('APPROVED EXCEL CONTRACT', 'عقد Excel المعتمد')) ?></span><h2><?= e($tr('The last approved report remains the golden master', 'يبقى آخر تقرير معتمد هو القالب الذهبي')) ?></h2></div><strong>12</strong></header><div><?php foreach($catalog as $sheet): ?><article><i><?= e(str_pad((string)($sheet['order']??0),2,'0',STR_PAD_LEFT)) ?></i><strong><?= e($isAr?(string)($sheet['name_ar']??''):(string)($sheet['name_en']??'')) ?></strong><small><?= e((string)($sheet['approved_dimension']??'')) ?></small></article><?php endforeach; ?></div></section>
    </section>

    <section class="diar-r2-panel" data-r2-panel="snapshots" hidden>
        <header class="diar-r2-section-head"><div><span><?= e($tr('FROZEN SOURCE LIBRARY', 'مكتبة المصادر المجمدة')) ?></span><h2><?= e($tr('Exact snapshots used by the report', 'النسخ الدقيقة المستخدمة في التقرير')) ?></h2></div><strong><?= e($number(count($snapshots))) ?></strong></header>
        <div class="diar-r2-snapshot-grid"><?php foreach($snapshots as $row): ?><article><header><strong><?= e((string)($row['site_code']??'')) ?></strong><span><?= e((string)($row['source_db']??'')) ?></span><em><?= e((string)($row['status']??'')) ?></em></header><dl><div><dt><?= e($tr('Snapshot','النسخة')) ?></dt><dd>#<?= e((string)($row['snapshot_id']??'')) ?> · v<?= e((string)($row['version_no']??'')) ?></dd></div><div><dt><?= e($tr('Cases','الحالات')) ?></dt><dd><?= e($number($row['cases']??0)) ?></dd></div><div><dt><?= e($tr('Priority','الأولوية')) ?></dt><dd><?= e($number($row['critical']??0)) ?> / <?= e($number($row['high']??0)) ?> / <?= e($number($row['medium']??0)) ?></dd></div><div><dt><?= e($tr('Associated cost','التكلفة المرتبطة')) ?></dt><dd><?= e($money($row['associated_cost']??0)) ?></dd></div><div><dt><?= e($tr('Transactions','المعاملات')) ?></dt><dd><?= e($number($row['transactions']??0)) ?></dd></div><div><dt>SHA</dt><dd><?= e(substr((string)($row['snapshot_hash']??''),0,14)) ?>…</dd></div></dl></article><?php endforeach; ?></div>
        <section class="diar-r2-history"><header><span><?= e($tr('EXPORT HISTORY', 'سجل التصدير')) ?></span><h2><?= e($tr('Generated files and traceable manifests', 'الملفات المنشأة وبيانات التتبع')) ?></h2></header><?php if($exportHistory===[]): ?><div class="diar-r2-empty"><?= e($tr('No export has been generated yet.', 'لم يتم إنشاء أي تصدير بعد.')) ?></div><?php else: ?><div class="diar-r2-table-wrap"><table><thead><tr><th><?= e($tr('Generated at','وقت الإنشاء')) ?></th><th><?= e($tr('Type','النوع')) ?></th><th><?= e($tr('Scope','النطاق')) ?></th><th><?= e($tr('Month','الشهر')) ?></th><th><?= e($tr('Generated by','أنشأه')) ?></th><th>SHA-256</th><th></th></tr></thead><tbody><?php foreach($exportHistory as $row): ?><tr><td><?= e((string)($row['generated_at']??'')) ?></td><td><?= e((string)($row['type']??'')) ?></td><td><?= e((string)($row['scope_code']??'')) ?></td><td><?= e((string)($row['selected_month']??'')) ?></td><td><?= e((string)($row['generated_by']??'')) ?></td><td><code><?= e(substr((string)($row['file_sha256']??''),0,16)) ?>…</code></td><td><a href="<?= e(url_to('diar-report-download')) ?>&amp;token=<?= e((string)($row['token']??'')) ?>"><?= e($tr('Download','تنزيل')) ?></a></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?></section>
    </section>

    <footer class="diar-r2-boundary"><strong><?= e($tr('Interpretation boundary', 'حدود التفسير')) ?></strong><span><?= e($tr('A case deserves review compared with prior behaviour. It is not proof of theft, manipulation or confirmed financial loss.', 'الحالة تستحق المراجعة مقارنة بالسلوك السابق، ولا تمثل إثباتًا على سرقة أو تلاعب أو خسارة مالية مؤكدة.')) ?></span></footer>
</section>
<script src="assets/js/diar-reports-r65.js?v=diar-6b-5-r2" defer></script>
