<?php
#################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 ##
## --------------------------------------------------------------------------- ##
##  Filename       : editUser.tpl                                              ##
##  Type           : Admin Panel Frontend                                      ##
## --------------------------------------------------------------------------- ##
##  Developed by   : Dzoki (Original)                                          ##
##  Refactored by  : Shadow                                                    ##
##  Redesign by    : Shadow                                                    ##
## --------------------------------------------------------------------------- ##
##  Contact        : cata7007@gmail.com                                        ##
##  Project        : TravianZ                                                  ##
##  GitHub         : https://github.com/Shadowss/TravianZ                      ##
## --------------------------------------------------------------------------- ##
##  License        : TravianZ Project                                          ##
##  Copyright      : TravianZ (c) 2010-2025. All rights reserved.              ##
## --------------------------------------------------------------------------- ##
#################################################################################

$id = (int)$_GET['uid'];
if(isset($id) && $id > 0) {
    $varray = $database->getProfileVillages($id);
    $varmedal = $database->getProfileMedal($id);
    $uid = $id;
?>
<style>
.editUser-wrap { max-width:1100px; margin:0 auto; font-family:system-ui; }
.editUser-head {
    background: linear-gradient(135deg,#66CCFF,#66CCCC); color:#fff;
    padding:10px 14px; margin-bottom:12px;
    border-radius:10px; display:flex; align-items:center; justify-content:space-between;
}
.editUser-head h2 { margin:0; font-size:16px; }
.editUser-head h2 a { color:#86efac; text-decoration:none; }
.editUser-head .meta { font-size:12px; color:#cbd5e1; }
@media(max-width:900px){ .editUser-grid{grid-template-columns:1fr;} }

.card { background:#fff; border:1px solid #e5e7eb; border-radius:10px; overflow:hidden; margin-bottom:12px; box-shadow:0 1px 3px rgba(0,0,0,.04); }
.card h3 { margin:0; padding:9px 12px; background:#f8fafc; border-bottom:1px solid #e5e7eb; font-size:12px; text-transform:uppercase; color:#475569; letter-spacing:.5px; }
.card .body { padding:12px; }

.form-row { display:flex; margin-bottom:10px; align-items:center; }
.form-row label { width:110px; font-size:12px; color:#333; font-weight:bold; }
.form-row input.fm, .form-row select.dropdown { flex:1; border:1px solid #bbb; padding:5px 6px; font-size:12px; border-radius:3px; background:#fff; }
.form-row input.fm:focus, select.dropdown:focus { border-color:#71D000; outline:none; box-shadow:0 0 3px rgba(113,208,0,.4); }
select.dropdown { width:100%; }

.username-row { background:#f9fff0; border:1px solid #d4edaa; border-radius:3px; padding:8px; margin-bottom:12px; }
.username-row .form-row { margin-bottom:0; }
.btn-mini { background:linear-gradient(#7ed321,#5eae0f); border:1px solid #4a8a0c; color:#fff; padding:5px 10px; font-size:11px; font-weight:bold; border-radius:3px; cursor:pointer; margin-left:6px; }
.btn-mini:hover { filter:brightness(1.05); }

.desc-box textarea { width:100%; box-sizing:border-box; border:1px solid #cbd5e1; border-radius:6px; padding:8px; font-family:system-ui; font-size:13px; resize:vertical; }
.desc-box textarea:focus { border-color:#71D000; outline:none; }

.medals-table { width:100%; border-collapse:collapse; font-size:12px; }
.medals-table th { background:#f5f5f5; padding:6px; border:1px solid #ddd; text-align:left; }
.medals-table td { padding:6px; border:1px solid #eee; }
.medals-table tr:nth-child(even){ background:#fafafa; }
.badge { display:inline-block; padding:2px 6px; border-radius:3px; font-size:11px; color:#fff; }
.badge.att { background:#c00; } .badge.def { background:#069; } .badge.climb { background:#e67e00; } .badge.rob { background:#6a0dad; }

.actions { margin-top:14px; text-align:center; }
.btn-save { background:linear-gradient(#7ed321,#5eae0f); border:1px solid #4a8a0c; color:#fff; padding:8px 24px; font-size:14px; font-weight:bold; border-radius:4px; cursor:pointer; text-shadow:0 -1px 0 rgba(0,0,0,.2); }
.btn-save:hover { filter:brightness(1.05); }
.back-link { font-size:12px; margin-left:12px; }
.back-link a { color:#0066cc; text-decoration:none; }
.back-link a:hover { text-decoration:underline; }
</style>

<div class="editUser-wrap">
    <div class="editUser-head">
        <h2><?php echo ADM_EDIT_PLAYER; ?><a href="admin.php?p=player&uid=<?php echo $user['id']; ?>"><?php echo htmlspecialchars($user['username']); ?></a></h2>
        <div class="meta">ID: <?php echo $id; ?> | Villages: <?php echo count($varray); ?> | Gold: <?php echo $user['gold']; ?> <img src="../img/x.gif" class="gold" style="vertical-align:-2px;"></div>
    </div>

    <div class="editUser-grid">
        <!-- LEFT: DETAILS -->
        <div class="card">
            <h3><?php echo ADM_ACCOUNT_DETAILS; ?></h3>
            <div class="body">
                
                <!-- USERNAME EDIT - NOU -->
                <div class="username-row">
                    <form action="../GameEngine/Admin/Mods/editUsername.php" method="POST">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="admid" value="<?php echo $_SESSION['id']; ?>">
                        <input type="hidden" name="uid" value="<?php echo $uid; ?>">
                        <div class="form-row">
                            <label><?php echo ADM_USERNAME_2; ?></label>
                            <input class="fm" name="username" value="<?php echo htmlspecialchars($user['username']); ?>" style="flex:1;">
                            <button type="submit" class="btn-mini" title="<?php echo ADM_CHANGE_USERNAME; ?>"><?php echo ADM_SAVE_2; ?></button>
                        </div>
                    </form>
                </div>

                <!-- RESTUL FORMULUI PRINCIPAL -->
                <form action="../GameEngine/Admin/Mods/editUser.php" method="POST">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="admid" value="<?php echo $_SESSION['id']; ?>">
                    <input type="hidden" name="uid" value="<?php echo $uid; ?>" />
                    <input type="hidden" name="id" value="<?php echo $id; ?>" />

                    <div class="form-row">
                        <label><?php echo ADM_TRIBE_2; ?></label>
                        <select name="tribe" class="dropdown">
                            <option value="1" <?php if($user['tribe']==1)echo"selected"; ?>><?php echo ADM_1_ROMAN; ?></option>
                            <option value="2" <?php if($user['tribe']==2)echo"selected"; ?>><?php echo ADM_2_TEUTON; ?></option>
                            <option value="3" <?php if($user['tribe']==3)echo"selected"; ?>><?php echo ADM_3_GAUL; ?></option>
							<option value="4" <?php if($user['tribe']==4)echo"selected"; ?>><?php echo ADM_4_NATURE; ?></option>
							<option value="5" <?php if($user['tribe']==5)echo"selected"; ?>><?php echo ADM_5_NATARS; ?></option>
							<option value="6" <?php if($user['tribe']==6)echo"selected"; ?>><?php echo ADM_6_HUN; ?></option>
							<option value="7" <?php if($user['tribe']==7)echo"selected"; ?>><?php echo ADM_7_EGYPTIAN; ?></option>
							<option value="8" <?php if($user['tribe']==8)echo"selected"; ?>><?php echo ADM_8_SPARTAN; ?></option>
							<option value="9" <?php if($user['tribe']==9)echo"selected"; ?>><?php echo ADM_9_VIKING; ?></option>
                        </select>
                    </div>
                    <div class="form-row">
                        <label><?php echo ADM_LOCATION; ?></label>
                        <input class="fm" name="location" value="<?php echo htmlspecialchars($user['location']); ?>">
                    </div>
                    <div class="form-row">
                        <label><?php echo ADM_E_MAIL; ?></label>
                        <input class="fm" name="email" value="<?php echo htmlspecialchars($user['email']); ?>">
                    </div>
                    <div class="form-row">
                        <label><?php echo ADM_QUEST; ?></label>
                        <input class="fm" name="quest" value="<?php echo (int)$user['quest']; ?>">
                    </div>

                    <div style="margin-top:14px; border-top:1px dashed #ddd; padding-top:10px;">
                        <label style="font-weight:bold; font-size:12px; display:block; margin-bottom:4px;"><?php echo ADM_PROFILE_DESCRIPTION_LEFT; ?></label>
                        <div class="desc-box">
                            <textarea name="desc1" rows="10"><?php echo htmlspecialchars($user['desc1']); ?></textarea>
                        </div>
                    </div>
                
            </div>
        </div>

        <!-- RIGHT: DESCRIPTION -->
        <div class="card">
            <h3><?php echo ADM_PROFILE_DESCRIPTION_RIGHT; ?></h3>
            <div class="body desc-box">
                <textarea name="desc2" rows="22"><?php echo htmlspecialchars($user['desc2']); ?></textarea>
                <div style="font-size:11px; color:#777; margin-top:4px;"><?php echo ADM_SUPORT_BBCODE_FOLOSE_TE_ENTER_PENTRU_LINII_N; ?></div>
            </div>
        </div>
    </div>

    <!-- MEDALS -->
    <div class="card" style="margin-top:12px;">
        <h3><?php echo ADM_MEDALS; ?></h3>
        <div class="body" style="padding:0;">
            <table class="medals-table">
                <thead>
                    <tr>
                        <th style="width:35%;"><?php echo ADM_CATEGORY; ?></th>
                        <th style="width:15%;"><?php echo ADM_RANK; ?></th>
                        <th style="width:15%;"><?php echo ADM_WEEK; ?></th>
                        <th><?php echo ADM_BB_CODE; ?></th>
                    </tr>
                </thead>
                <tbody>
                <?php
                foreach($varmedal as $medal){
                    $titel="Bonus"; $class=""; $icon="⭐";
                    switch($medal['categorie']){
                        case "1": $titel="Attacker of the Week"; $class="att"; $icon="⚔️"; break;
                        case "2": $titel="Defender of the Week"; $class="def"; $icon="🛡️"; break;
                        case "3": $titel="Climber of the Week"; $class="climb"; $icon="📈"; break;
                        case "4": $titel="Robber of the Week"; $class="rob"; $icon="💰"; break;
                    }
                    echo "<tr>
                        <td><span class='badge $class'>$icon</span> $titel</td>
                        <td>#".$medal['plaats']."</td>
                        <td>".$medal['week']."</td>
                        <td><code>[#".$medal['id']."]</code></td>
                    </tr>";
                }
                ?>
                <tr>
                    <td><span class="badge" style="background:#999;">🔰</span><?php echo ADM_BEGINNERS_PROTECTION; ?></td>
                    <td>-</td><td>-</td><td><code>[#0]</code></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

    <div class="actions">
        </form> <!-- închidem form-ul principal aici -->
        <button type="submit" form="dummy" onclick="document.querySelector('form[action*=\'editUser.php\']').submit()" class="btn-save"><?php echo ADM_SAVE_CHANGES_2; ?></button>
        <span class="back-link"><a href="?p=player&uid=<?php echo $user['id']; ?>"><?php echo ADM_GO_BACK_TO_PLAYER; ?></a></span>
    </div>
</div>
<?php
} else {
    echo "<div style='padding:20px; text-align:center;'>❌ Player not found. <a href=\"javascript:history.go(-1)\">Go Back</a></div>";
}
?>