<?php

declare(strict_types=1);

require __DIR__ . '/app/bootstrap.php';

$destination = current_user() ? 'dashboard.php' : 'login.php';
if (current_user()) {
    try {
        $ready = !app_update_pending();
        if (!$ready && has_role('super_admin')) {
            $destination = 'system_setup.php?tab=updates';
        } elseif ($ready && actual_role() === 'dentist') {
            $destination = 'clinical_day.php';
        }
    } catch (Throwable) {
        $destination = 'dashboard.php';
    }
}
header('Location: ' . (function_exists('dental_clean_url') ? dental_clean_url($destination) : $destination));
exit;
