<?php
$participant = $report['participant'];
$primaryArea = $report['primary_area'];
$viewLocale = current_locale();
?>

<section class="report-toolbar">
    <div>
        <p class="eyebrow"><?= e($adminMode ? trans('admin.report_view', [], $viewLocale) : trans('participant.report_complete', [], $viewLocale)) ?></p>
        <h1><?= e(trans('participant.report_heading', ['name' => $participant['full_name']], $viewLocale)) ?></h1>
        <p class="support-copy"><?= e(trans('participant.report_meta', ['reference' => $report['reference'], 'generated' => $report['generated_at']], $viewLocale)) ?></p>
    </div>
    <div class="toolbar-actions">
        <button class="ghost-button" type="button" onclick="window.print()"><?= e(trans('common.print', [], $viewLocale)) ?></button>
        <a class="primary-button" href="<?= e($adminMode ? base_url('/admin/reports/download?ref=' . urlencode($report['reference']) . '&lang=' . urlencode($viewLocale)) : base_url('/participant/report/download?lang=' . urlencode($viewLocale))) ?>"><?= e(trans('common.download_pdf', [], $viewLocale)) ?></a>
        <?php if ($adminMode): ?>
            <a class="primary-button" href="<?= e(base_url('/admin/reports')) ?>"><?= e(trans('admin.back_reports', [], $viewLocale)) ?></a>
        <?php endif; ?>
    </div>
</section>

<section class="report-grid">
    <article class="card report-summary">
        <h2><?= e(trans('participant.report_details', [], $viewLocale)) ?></h2>
        <dl class="details-grid">
            <div>
                <dt><?= e(trans('participant.full_name', [], $viewLocale)) ?></dt>
                <dd><?= e($participant['full_name']) ?></dd>
            </div>
            <div>
                <dt><?= e(trans('participant.email', [], $viewLocale)) ?></dt>
                <dd><?= e($participant['email']) ?></dd>
            </div>
            <div>
                <dt><?= e(trans('participant.phone', [], $viewLocale)) ?></dt>
                <dd><?= e($participant['phone']) ?></dd>
            </div>
            <div>
                <dt><?= e(trans('common.language', [], $viewLocale)) ?></dt>
                <dd><?= e(config('supported_languages.' . $participant['language'], strtoupper($participant['language']))) ?></dd>
            </div>
        </dl>

        <?php if (is_array($primaryArea)): ?>
            <div class="primary-area" style="--accent: <?= e($primaryArea['color']) ?>">
                <p><?= e(trans('participant.report_top_interest', [], $viewLocale)) ?></p>
                <h3><?= e($primaryArea['name']) ?></h3>
                <span><?= e($primaryArea['score'] . ' / ' . $primaryArea['max_score']) ?></span>
            </div>
        <?php endif; ?>
    </article>

    <article class="card report-chart">
        <h2><?= e(trans('participant.report_distribution', [], $viewLocale)) ?></h2>
        <p class="support-copy"><?= e(trans('participant.report_distribution_copy', [], $viewLocale)) ?></p>

        <div class="line-score-list">
            <?php foreach ($report['rankings'] as $ranking): ?>
                <?php $width = $ranking['max_score'] > 0 ? round(($ranking['score'] / $ranking['max_score']) * 100) : 0; ?>
                <div class="line-score-item">
                    <div class="line-score-label">
                        <strong><?= e($ranking['code']) ?></strong>
                        <span><?= e($ranking['name']) ?></span>
                    </div>
                    <div class="line-score-track" style="--line-color: <?= e($ranking['color']) ?>">
                        <span class="line-score-fill" style="width: <?= e((string) $width) ?>%"></span>
                        <span class="line-score-point" style="left: calc(<?= e((string) $width) ?>% - 10px)"></span>
                    </div>
                    <div class="line-score-value"><?= e($ranking['score'] . ' / ' . $ranking['max_score']) ?></div>
                </div>
            <?php endforeach; ?>
        </div>
    </article>
</section>

<section class="report-sections">
    <?php foreach ($report['rankings'] as $ranking): ?>
        <article class="card interest-card" style="--interest-accent: <?= e($ranking['color']) ?>">
            <header>
                <div>
                    <p class="eyebrow"><?= e(trans('participant.report_rank', ['rank' => $ranking['rank']], $viewLocale)) ?></p>
                    <h2><?= e($ranking['name']) ?> (<?= e($ranking['code']) ?>)</h2>
                </div>
                <span class="score-badge"><?= e($ranking['score'] . ' / ' . $ranking['max_score']) ?></span>
            </header>

            <p><?= e($ranking['description']) ?></p>

            <div class="recommendation-grid">
                <div>
                    <h3><?= e(trans('participant.career_opportunities', [], $viewLocale)) ?></h3>
                    <ul class="feature-list compact-list">
                        <?php foreach ($ranking['career_opportunities'] as $item): ?>
                            <li><?= e($item) ?></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
                <div>
                    <h3><?= e(trans('participant.suitable_programme', [], $viewLocale)) ?></h3>
                    <ul class="feature-list compact-list">
                        <?php foreach ($ranking['suitable_programmes'] as $item): ?>
                            <li><?= e($item) ?></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            </div>
        </article>
    <?php endforeach; ?>
</section>

<?php if (!$adminMode): ?>
    <section class="card note-card">
        <h2><?= e(trans('participant.important', [], $viewLocale)) ?></h2>
        <p><?= e(trans('participant.report_notice', [], $viewLocale)) ?></p>
    </section>
<?php endif; ?>