<?php
/*
 * pages/characters.php
 * PHP logic: 100% INTACT din CMS original
 * HTML: design Nostalgia2 (adaptat din userpanel.blade.php)
 */

// ---- LOGICA PHP INTACT ----
$list    = characters_list();
$ranking = get_player_rank($list);

// Debug reset (exact ca in original)
if($jsondataFunctions['players-debug'] && isset($_POST['debug'])) {
    foreach($list as $player) {
        if($player['id'] == intval($_POST['debug'])) {
            echo '<div class="alert alert-success alert-dismissible fade show m-3">
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                '.$lang['debug-success'].'</div>';
            $empire = get_player_empire($_SESSION['id']);
            if($empire == 1)      { $mapindex = "0";  $x = "459770"; $y = "953980"; }
            elseif($empire == 2)  { $mapindex = "21"; $x = "52043";  $y = "166304"; }
            elseif($empire == 3)  { $mapindex = "41"; $x = "957291"; $y = "255221"; }
            reset_char($player['id'], $mapindex, $x, $y);
        }
    }
}
?>

<!-- Header -->
<nav class="navbar navbar-dark bg-news-header">
    <div class="container-fluid">
        <h4 class="h4 small m-0 text-uppercase"><?php echo strtoupper($lang['chars-list']); ?></h4>
        <div class="d-flex d-none d-md-block">
            <ul class="navbar-nav list-group-horizontal small">
                <li class="nav-item px-2">
                    <span class="text-bluevioletmutted small">
                        <?php echo htmlspecialchars(getAccountName($_SESSION['id'])); ?>
                    </span>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="account_settings_main_board_darker_background p-3">
    <?php if(count($list)) { ?>
    <table class="mx-auto" id="account_details_password_change">
        <?php foreach($list as $player) {
            $job = job_name($player['job']);
        ?>
        <tr class="account_details_row">
            <td class="account_details_category">
                <img src="<?php echo $site_url; ?>assets/img/job/<?php echo intval($player['job']); ?>.png"
                     alt="<?php echo htmlspecialchars($job); ?>" width="45">
                <?php echo htmlspecialchars($player['name']); ?>
            </td>
            <td class="account_details_category">
                <?php echo $lang['level']; ?>: <span class="text-gold"><?php echo $player['level']; ?></span>
            </td>
            <td class="account_details_category text-muted small">
                <?php echo $lang['rank-position']; ?>: #<?php echo isset($ranking[$player['name']]) ? $ranking[$player['name']] : '?'; ?>
            </td>
            <?php if($jsondataFunctions['players-debug']) { ?>
            <td class="account_details_value">
                <form action="" method="post">
                    <input type="hidden" name="debug" value="<?php echo $player['id']; ?>">
                    <button type="submit" class="my-2 sign-in-button btn bg-button small fw-bold"
                        style="width:200px;">
                        <?php echo $lang['debug']; ?>
                    </button>
                </form>
            </td>
            <?php } ?>
        </tr>
        <?php } ?>
    </table>
    <?php } else { ?>
    <h3 class="text-center text-muted py-4"><?php echo $lang['no-chars']; ?></h3>
    <?php } ?>
</div>
