<?php
use App\Core\ProfileGuard;

if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

if (!function_exists('ec_pcb_h')) {
    function ec_pcb_h($v) {
        return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
    }
}

$userId = (int)($_SESSION['user_id'] ?? 0);
$conferenceId = (int)($_SESSION['conference_id'] ?? 0);

$showProfileBanner = false;
$missingFields = [];

if ($userId > 0 && $conferenceId > 0) {
    try {
        $guard = new ProfileGuard();
        $showProfileBanner = !$guard->isComplete($userId, $conferenceId);
        $missingFields = $guard->missingFields($userId, $conferenceId);
    } catch (\Throwable $e) {
        $showProfileBanner = false;
    }
}

$guardMessage = $_SESSION['profile_guard_message'] ?? '';
unset($_SESSION['profile_guard_message']);
?>

<?php if ($showProfileBanner): ?>
    <div style="margin:14px 18px;padding:16px 18px;border-radius:18px;background:#fff7ed;border:1px solid #fed7aa;color:#7c2d12;box-shadow:0 10px 25px rgba(124,45,18,.08);">
        <div style="font-weight:900;font-size:16px;margin-bottom:4px;">
            <i class="fa fa-triangle-exclamation"></i>
            <?= $guardMessage ? ec_pcb_h($guardMessage) : 'Your academic profile is incomplete.' ?>
        </div>
        <div style="font-size:14px;">
            Missing fields:
            <strong><?= ec_pcb_h(implode(', ', $missingFields ?: ['basic profile fields'])) ?></strong>
        </div>
        <div style="margin-top:10px;">
            <a href="/easychair/profile" style="display:inline-block;background:#ea580c;color:#fff;padding:8px 16px;border-radius:999px;text-decoration:none;font-weight:800;">
                Complete Profile
            </a>
        </div>
    </div>
<?php endif; ?>
