<?php
declare(strict_types=1);

/**
ET-Chat Copyright by SEDesign | ET-Chat v3.x.x Lizenz: CCPL | Autor: Evgeni Tcherkasski (info@s-e-d.de)
ET-Chat_T-FISH-MOD Weiterentwicklungen, Optimierungen und Ergänzungen am Code sind das geistige Eigentum von Tommy (Thomas Kuhn) und Harlekin (Bernd Witte).

Die darauf folgende Optimierungen und Ergänzungen am Code sind das Geistige Eigentum von Powermen (Christian K.)
und wird unter der Namenserweiterung M.C.v.x.x.x. geführt. 
PHP 8/9 Ready, XML Parser, PDO Prepared Statements Get Set sicherheit usw.
 */

$style = $_SESSION['etchat_' . $this->_prefix . 'style'] ?? 'default';
$style = preg_replace('/[^a-zA-Z0-9_\-]/', '', (string)$style);

function e(string $v): string {
    return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
}

ob_start();
?>

<?php if (is_array($feld)): ?>

<form action="./?AdminUpdateRoom" method="post" class="user-form">

    <input type="hidden" name="csrf_token" value="<?= e($_SESSION['etchat_'.$this->_prefix.'csrf_token']); ?>">
    <input type="hidden" name="id" value="<?= e((string)$feld[0][0]); ?>">

    <label for="room">Raumname</label>
    <input type="text" name="room" id="room" value="<?= e((string)$feld[0][1]); ?>">

    <label for="room_priv">Privatsphäre</label>
    <select name="room_priv" id="room_priv">
        <option value="0"><?= $lang->room_priv[0]->tagData; ?></option>

        <?php if ($feld[0][0] > 1): ?>

            <?php if ($this->_allow_nick_registration): ?>
                <option value="4" <?= $feld[0][2] == 4 ? 'selected' : '' ?>>
                    <?= $lang->room_priv[4]->tagData; ?>
                </option>
            <?php endif; ?>

            <option value="1" <?= $feld[0][2] == 1 ? 'selected' : '' ?>>
                <?= $lang->room_priv[1]->tagData; ?>
            </option>

            <option value="2" <?= $feld[0][2] == 2 ? 'selected' : '' ?>>
                <?= $lang->room_priv[2]->tagData; ?>
            </option>

            <option value="3" <?= $feld[0][2] == 3 ? 'selected' : '' ?>>
                <?= $lang->room_priv[3]->tagData; ?>
            </option>

        <?php endif; ?>
    </select>

    <div id="roompw" class="room-pw-box" style="display:none;">
        <label for="roompw_input"><?= $lang->pass[0]->tagData; ?></label>
        <input type="text" name="roompw" id="roompw_input" value="<?= e((string)$feld[0][3]); ?>">
    </div>

    <label for="roommessage"><?= $lang->message[0]->tagData; ?></label>
    <textarea name="roommessage" id="roommessage" rows="4" class="admin-textarea-medium"><?= e((string)$feld[0][4]); ?></textarea>

    <input type="submit" value="<?= $lang->rename[0]->tagData; ?>" class="admin-button-primary">

</form>

<script>
document.addEventListener("DOMContentLoaded", function () {
    const privSelect = document.getElementById("room_priv");
    const pwDiv = document.getElementById("roompw");

    if (!privSelect || !pwDiv) return;

    function togglePassword() {
        pwDiv.style.display = (privSelect.value === "3") ? "block" : "none";
    }

    privSelect.addEventListener("change", togglePassword);
    togglePassword(); // initial state
});
</script>

<?php endif; ?>

<?php
$content = ob_get_clean();

$pageTitle  = 'Raum bearbeiten';
$backLink   = './?AdminRoomsIndex';
$footerNote = $lang->note[0]->tagData ?? '';

include __DIR__ . '/admin_master_template.php';