{{@include("header", it)/}}


<div class="text-center mb-4">
    <h2>Settings</h2>
</div>


<div class="row justify-content-md-center">
    <div class="col-md-7 mw-col8">

        <!-- Settings Card -->
        <div class="card card-accent-danger">
            <div class="card-header font-weight-bold" style="border-bottom: 0px;">
                <ul class="nav nav-tabs card-header-tabs">
                    <li class="nav-item">
                        <a class="nav-item nav-link {{it.activeTab=='global'|isActive}}" id="nav-global-tab" data-toggle="tab" href="#nav-global"
                            role="tab" aria-controls="nav-global" aria-selected="true">Global</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item nav-link {{it.activeTab=='fxserver'|isActive}}" id="nav-fxserver-tab" data-toggle="tab" href="#nav-fxserver"
                            role="tab" aria-controls="nav-fxserver" aria-selected="true">FXServer</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item nav-link {{it.activeTab=='playerManager'|isActive}}" id="nav-playerManager-tab" data-toggle="tab" href="#nav-playerManager"
                            role="tab" aria-controls="nav-playerManager" aria-selected="true">Player Manager</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item nav-link {{it.activeTab=='monitor'|isActive}}" id="nav-monitor-tab" data-toggle="tab" href="#nav-monitor"
                            role="tab" aria-controls="nav-monitor" aria-selected="true">Monitor/Restarter</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-item nav-link {{it.activeTab=='discord'|isActive}}" id="nav-discord-tab" data-toggle="tab" href="#nav-discord"
                            role="tab" aria-controls="nav-discord" aria-selected="true">Discord</a>
                    </li>
                </ul>
            </div>

            <div class="card-body settings-card">
                <div class="tab-content" id="nav-tabContent">

                    <!-- Global Tab -->
                    <div class="tab-pane fade {{it.activeTab=='global'|isActive|tShow}}" id="nav-global" role="tabpanel"
                        aria-labelledby="nav-global-tab">
                        <div class="form-group row">
                            <label for="frmGlobal-serverName" class="col-sm-3 col-form-label">
                                Server Name
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmGlobal-serverName"
                                    value="{{it.global.serverName|undef}}" maxlength="24" placeholder="server name" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    A <strong>short</strong> server name to be used in txAdmin interface and Chat/Discord messages.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmGlobal-language" class="col-sm-3 col-form-label">
                                Language
                            </label>
                            <div class="col-sm-9">
                                <select class="form-control" id="frmGlobal-language" {{it.readOnly|isDisabled}}>
                                    <option value="en" {{it.global.language=='en'|isSelected}}>English (default)</option>

                                    <option value="ar" {{it.global.language=='ar'|isSelected}}>Arabic</option>
                                    <option value="cs" {{it.global.language=='cs'|isSelected}}>Czech</option>
                                    <option value="da" {{it.global.language=='da'|isSelected}}>Danish</option>
                                    <option value="de" {{it.global.language=='de'|isSelected}}>German</option>
                                    <option value="el" {{it.global.language=='el'|isSelected}}>Greek</option>
                                    <option value="es" {{it.global.language=='es'|isSelected}}>Spanish</option>
                                    <option value="fi" {{it.global.language=='fi'|isSelected}}>Finnish</option>
                                    <option value="fr" {{it.global.language=='fr'|isSelected}}>French</option>
                                    <option value="hu" {{it.global.language=='hu'|isSelected}}>Hungarian</option>
                                    <option value="lt" {{it.global.language=='lt'|isSelected}}>Lithuanian</option>
                                    <option value="lv" {{it.global.language=='lv'|isSelected}}>Latvian</option>
                                    <option value="nl" {{it.global.language=='nl'|isSelected}}>Dutch</option>
                                    <option value="no" {{it.global.language=='no'|isSelected}}>Norwegian</option>
                                    <option value="pl" {{it.global.language=='pl'|isSelected}}>Polish</option>
                                    <option value="pt_BR" {{it.global.language=='pt_BR'|isSelected}}>Portuguese (Brazil)</option>
                                    <option value="pt_PT" {{it.global.language=='pt_PT'|isSelected}}>Portuguese (Portugal)</option>
                                    <option value="ro" {{it.global.language=='ro'|isSelected}}>Romanian</option>
                                    <option value="ru" {{it.global.language=='ru'|isSelected}}>Russian</option>
                                    <option value="sv" {{it.global.language=='sv'|isSelected}}>Swedish</option>
                                    <option value="th" {{it.global.language=='th'|isSelected}}>Thai</option>
                                    <option value="tr" {{it.global.language=='tr'|isSelected}}>Turkish</option>
                                    <option value="zh" {{it.global.language=='zh'|isSelected}}>Chinese</option>

                                    <option value="custom" {{it.global.language=='custom'|isSelected}}>Custom (read the documentation)</option>
                                </select>
                                <span class="form-text text-muted">
                                    The language to use on Chat/Discord messages. <br>
                                    <b>Note:</b> For the Custom option, read the documentation.
                                </span>
                            </div>
                        </div>

                        <div class="text-center mt-4">
                            <button class="btn btn-sm btn-primary" type="submit" id="frmGlobal-save" {{it.readOnly|isDisabled}}>
                                <i class="icon-check"></i> Save Global Settings
                            </button>
                        </div>
                    </div>
                    <!-- /Global Tab -->

                    <!-- FXServer Tab -->
                    <div class="tab-pane fade {{it.activeTab=='fxserver'|isActive|tShow}}" id="nav-fxserver" role="tabpanel" aria-labelledby="nav-fxserver-tab">
                        <div class="form-group row">
                            <label for="frmFXServer-serverDataPath" class="col-sm-3 col-form-label">Server Data Folder
                                <span class="text-danger">*</span></label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmFXServer-serverDataPath" value="{{it.fxserver.serverDataPath|undef}}"
                                    placeholder="C:/Users/Admin/Desktop/server01" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    The folder that <strong>contains</strong> the <code>resources</code> and
                                    <code>cache</code> folders, usually it's where you put your
                                    <code>server.cfg</code>.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmFXServer-cfgPath" class="col-sm-3 col-form-label">CFG File Path
                                <span class="text-danger">*</span></label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmFXServer-cfgPath" value="{{it.fxserver.cfgPath|undef}}"
                                    placeholder="C:/Users/Admin/Desktop/server01/server.cfg" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    The path to your server config file, usually named <code>server.cfg</code>. <br>
                                    This can either be absolute, or relative to the Server Data folder.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmFXServer-commandLine" class="col-sm-3 col-form-label">
                                Additional Arguments
                            </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmFXServer-commandLine" value="{{it.fxserver.commandLine|undef}}"
                                    placeholder="+set onesync_population false" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    Additional command-line arguments to pass to the FXServer instance. <br>
                                    For example, you can add <code>+set</code> and <code>+exec</code> commands.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmFXServer-onesync" class="col-sm-3 col-form-label">OneSync</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="frmFXServer-onesync" {{it.readOnly|isDisabled}}>
                                    <option value="off" {{it.fxserver.onesync=='off'|isSelected}}>Off (default)</option>
                                    <option value="legacy" {{it.fxserver.onesync=='legacy'|isSelected}}>Legacy (without infinity)</option>
                                    <option value="on" {{it.fxserver.onesync=='on'|isSelected}}>On (with infinity)</option>
                                </select>
                                <span class="form-text text-muted">
                                    Required if your server has more than 32 slots. <br>
                                    <b>Note:</b> Setting to <code>on</code> will override <code>onesync_enableInfinity</code> if set as an Additional Argument above.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmFXServer-autostart" class="col-sm-3 col-form-label">Autostart</label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmFXServer-autostart"
                                        {{it.fxserver.autostart|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    Start the server automatically after <strong>txAdmin</strong> starts.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmFXServer-quiet" class="col-sm-3 col-form-label">Quiet</label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmFXServer-quiet"
                                        {{it.fxserver.quiet|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    Do not print FXServer's output to the terminal. <br>
                                    You will still be able to use the Live Console.
                                </span>
                            </div>
                        </div>

                        <div class="text-center mt-4">
                            <button class="btn btn-sm btn-primary" type="submit" id="frmFXServer-save" {{it.readOnly|isDisabled}}>
                                <i class="icon-check"></i> Save FXServer Settings
                            </button>
                        </div>
                    </div>
                    <!-- /FXServer Tab -->
                    
                    <!-- Player Manager Tab -->
                    <div class="tab-pane fade {{it.activeTab=='playerManager'|isActive|tShow}}" id="nav-playerManager" role="tabpanel" aria-labelledby="nav-playerManager-tab">
                        <div class="form-group row">
                            <label for="frmPlayerManager-onJoinCheckBan" class="col-sm-3 col-form-label">
                                Enable Banlist
                            </label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmPlayerManager-onJoinCheckBan"
                                        {{it.playerController.onJoinCheckBan|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    Enable checking for <strong>Ban</strong> status on player join. <br>
                                    Bans will not work if this option is disabled.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmPlayerManager-onJoinCheckWhitelist" class="col-sm-3 col-form-label">
                                Enable Whitelist
                            </label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmPlayerManager-onJoinCheckWhitelist"
                                        {{it.playerController.onJoinCheckWhitelist|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    Enable checking for <strong>Whitelist</strong> status on player join. <br>
                                    Whitelists will not work if this option is disabled.
                                </span>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label for="frmPlayerManager-minSessionTime" class="col-sm-3 col-form-label">
                                Minimum <br>
                                Session Time
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="frmPlayerManager-minSessionTime"
                                    value="{{it.playerController.minSessionTime|undef}}" placeholder="15" min="1" max="60" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    The minimum amount of minutes a player needs to be in the server before it gets saved to the database. <br>
                                    This is done to prevent the database from getting too big. <br>
                                    This number must be between <code>1</code> and <code>60</code> minutes.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmPlayerManager-whitelistRejectionMessage" class="col-sm-3 col-form-label">
                                Whitelist <br>Rejection Message
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-sm-9">
                                <textarea class="form-control" id="frmPlayerManager-whitelistRejectionMessage" rows="4" 
                                    placeholder="You are not yet whitelisted in this server.&#10;Please join http://discord.gg/example.&#10;Your ID: &lt;id&gt;" 
                                    maxlength="256" {{it.readOnly|isDisabled}}>{{it.playerController.whitelistRejectionMessage|undef}}</textarea>
                                <span class="form-text text-muted">
                                    The message that will be returned to the player if he is not whitelisted. <br>
                                    Use <code>&lt;id&gt;&#10;</code> as a placeholder for the whitelist request ID.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmPlayerManager-wipePendingWLOnStart" class="col-sm-3 col-form-label">
                                Wipe Whitelist <br>
                                On txAdmin Start
                            </label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmPlayerManager-wipePendingWLOnStart"
                                        {{it.playerController.wipePendingWLOnStart|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    When enabled, the pending whitelist will be wiped every time txAdmin starts <br>
                                    This is done to prevent the database to get too big.
                                </span>
                            </div>
                        </div>

                        <div class="text-center mt-4">
                            <button class="btn btn-sm btn-primary" type="submit" id="frmPlayerManager-save" {{it.readOnly|isDisabled}}>
                                <i class="icon-check"></i> Save Player Manager Settings
                            </button>
                        </div>
                    </div>
                    <!-- /Player Manager Tab -->

                    <!-- Monitor Tab -->
                    <div class="tab-pane fade {{it.activeTab=='monitor'|isActive|tShow}}" id="nav-monitor" role="tabpanel" aria-labelledby="nav-monitor-tab">
                        <div class="form-group row">
                            <label for="frmMonitor-schedule" class="col-sm-3 col-form-label">Scheduled Restarts</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmMonitor-schedule" value="{{it.monitor.restarterSchedule|undef}}"
                                    placeholder="05:00, 13:00" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-danger" id="frmMonitor-timezoneAlert"></span>
                                <span class="form-text text-muted">
                                    At which times of day to restart the server. Leave it blank to disable this feature. <br>
                                    The time MUST be in the 24-hour format with two digits for hours as well as
                                    minutes (<code>HH:MM</code>) and the times should be separated by commas. <br>
                                    <strong>Note:</strong> Make sure your schedule matches your server time and not your local time.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmMonitor-chatMessages" class="col-sm-3 col-form-label">
                                Disable Chat Warnings
                            </label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmMonitor-chatMessages"
                                        {{it.monitor.disableChatWarnings|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    Check this if you want to disable broadcast chat warning messages in game before each scheduled restart.
                                </span>
                            </div>
                        </div>

                        <div class="text-center mt-4">
                            <button class="btn btn-sm btn-primary" type="submit" id="frmMonitor-save" {{it.readOnly|isDisabled}}>
                                <i class="icon-check"></i> Save Monitor/Restarter Settings
                            </button>
                        </div>
                    </div>
                    <!-- /Monitor Tab -->

                    <!-- Discord Tab -->
                    <div class="tab-pane fade {{it.activeTab=='discord'|isActive|tShow}}" id="nav-discord" role="tabpanel" aria-labelledby="nav-discord-tab">
                        <div class="form-group row">
                            <label for="frmDiscord-enabled" class="col-sm-3 col-form-label">Enable Bot</label>
                            <div class="col-sm-9">
                                <label class="c-switch c-switch-label c-switch-pill c-switch-success fix-pill-form">
                                    <input class="c-switch-input" type="checkbox" id="frmDiscord-enabled"
                                        {{it.discord.enabled|undef}} {{it.readOnly|isDisabled}}>
                                    <span class="c-switch-slider" data-checked="On" data-unchecked="Off"></span>
                                </label>
                                <span class="form-text text-muted">
                                    Enable Discord Integration.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmDiscord-token" class="col-sm-3 col-form-label">Token <span
                                    class="text-danger">*</span></label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmDiscord-token" 
                                    value="{{@if(!it.readOnly)}}{{it.discord.token|undef}}{{#else}}[redacted]{{/if}}"
                                    placeholder="CXPcWbxKOHpwlUBaYKznIfkz.ExpTAB.NX-3YxfmVIGUJLGbPamViXGAEiY"
                                    maxlength="96" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    To get a token and the bot to join your server, follow these two guides:
                                    <a href="https://discordjs.guide/preparations/setting-up-a-bot-application.html"
                                        target="_blank" rel="noopener noreferrer">Setting up a bot application</a> and
                                    <a href="https://discordjs.guide/preparations/adding-your-bot-to-servers.html"
                                        target="_blank" rel="noopener noreferrer">Adding your bot to servers</a>.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmDiscord-announceChannel" class="col-sm-3 col-form-label">Announcements <br>Channel ID</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="frmDiscord-announceChannel"
                                    value="{{it.discord.announceChannel|undef}}" 
                                    placeholder="578045190955335691" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    The ID of the channel to send Announcements (eg server restarts). <br>
                                    Leave it blank to disable this feature. <br>
                                    To get the channel ID, go to Discord's settings and
                                    <a href="https://support.discordapp.com/hc/article_attachments/115002742731/mceclip0.png"
                                    target="_blank" > enable developer mode</a>, then right-click on the channel name and select "Copy ID".
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmDiscord-prefix" class="col-sm-3 col-form-label">
                                Command Prefix
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmDiscord-prefix" value="{{it.discord.prefix|undef}}"
                                    placeholder="/" maxlength="1" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    The prefix for all commands.
                                </span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="frmDiscord-statusMessage" class="col-sm-3 col-form-label">
                                Status Command Message
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-sm-9">
                                <textarea class="form-control" id="frmDiscord-statusMessage" rows="4" 
                                    placeholder="**IP:** `connect cfx.re/join/xxxxxx`&#10;**Players:** &lt;players&gt;&#10;**Uptime:** &lt;uptime&gt;" {{it.readOnly|isDisabled}}>{{it.discord.statusMessage|undef}}</textarea>
                                <span class="form-text text-muted">
                                    The response to the <code>/status</code> command. <br>
                                    Supported placeholders: <code>players</code>, <code>port</code>, <code>uptime</code>.
                                </span>
                            </div>
                        </div>


                        <div class="text-center mt-4">
                            <button class="btn btn-sm btn-primary" type="submit" id="frmDiscord-save" {{it.readOnly|isDisabled}}>
                                <i class="icon-check"></i> Save Discord Settings
                            </button>
                        </div>
                    </div>
                    <!-- /Discord Tab -->

                </div>
            </div>


        </div>

    </div>
</div>


{{@include("footer", it)/}}


<script>
    //============================================== General
    let serverTimezone = "{{it.serverTimezone}}";
    let browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
    if(serverTimezone !== browserTimezone){
        let msg = `Server's timezone: <b>${serverTimezone}</b> <br>
            Your timezone: <b>${browserTimezone}</b> <br>
            Make sure to adjust the times to match your expectations.`;
        $('#frmMonitor-timezoneAlert').html(msg);
    }


    //============================================== Global Settings
    $('#frmGlobal-save').click(function () {
        let data = {
            serverName: $('#frmGlobal-serverName').val().trim(),
            language: $('#frmGlobal-language').val(),
            verbose: $('#frmGlobal-verbose').is(':checked')
        }
        if (!data.serverName.length) {
            var notify = $.notify({ message: 'The fields with "*" are required.' }, { type: 'warning' });
            return;
        }
        var notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        $.ajax({
            type: "POST",
            url: '/settings/save/global',
            timeout: timeoutMedium,
            data: data,
            dataType: 'json',
            success: function (data) {
                notify.update('progress', 0);
                notify.update('type', data.type);
                notify.update('message', data.message);
            },
            error: function (xmlhttprequest, textstatus, message) {
                notify.update('progress', 0);
                notify.update('type', 'danger');
                notify.update('message', message);
            }
        });
    });


    //============================================== FXServer Settings
    $('#frmFXServer-save').click(function () {
        let data = {
            serverDataPath: $('#frmFXServer-serverDataPath').val().trim(),
            cfgPath: $('#frmFXServer-cfgPath').val().trim(),
            commandLine: $('#frmFXServer-commandLine').val().trim(),
            onesync: $('#frmFXServer-onesync').val(),
            autostart: $('#frmFXServer-autostart').is(':checked'),
            quiet: $('#frmFXServer-quiet').is(':checked')
        }
        if (!data.serverDataPath.length || !data.cfgPath.length) {
            var notify = $.notify({ message: 'The fields with "*" are required.' }, { type: 'warning' });
            return;
        }
        var notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        $.ajax({
            type: "POST",
            url: '/settings/save/fxserver',
            timeout: timeoutMedium,
            data: data,
            dataType: 'json',
            success: function (data) {
                notify.update('progress', 0);
                notify.update('type', data.type);
                notify.update('message', data.message);
            },
            error: function (xmlhttprequest, textstatus, message) {
                notify.update('progress', 0);
                notify.update('type', 'danger');
                notify.update('message', message);
            }
        });
    });


    //============================================== Player Manager Settings
    $('#frmPlayerManager-save').click(function () {
        let data = {
            onJoinCheckBan: $('#frmPlayerManager-onJoinCheckBan').is(':checked'),
            onJoinCheckWhitelist: $('#frmPlayerManager-onJoinCheckWhitelist').is(':checked'),
            minSessionTime: $('#frmPlayerManager-minSessionTime').val().trim(),
            whitelistRejectionMessage: $('#frmPlayerManager-whitelistRejectionMessage').val().trim(),
            wipePendingWLOnStart: $('#frmPlayerManager-wipePendingWLOnStart').is(':checked'),
        }
        if (!data.minSessionTime.length || !data.whitelistRejectionMessage.length) {
            var notify = $.notify({ message: 'The fields with "*" are required.' }, { type: 'warning' });
            return;
        }
        var notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        $.ajax({
            type: "POST",
            url: '/settings/save/playerController',
            timeout: timeoutMedium,
            data: data,
            dataType: 'json',
            success: function (data) {
                notify.update('progress', 0);
                notify.update('type', data.type);
                notify.update('message', data.message);
            },
            error: function (xmlhttprequest, textstatus, message) {
                notify.update('progress', 0);
                notify.update('type', 'danger');
                notify.update('message', message);
            }
        });
    });


    //============================================== Monitor Settings
    $('#frmMonitor-save').click(function () {
        let data = {
            schedule: $('#frmMonitor-schedule').val().trim(),
            disableChatWarnings: ($('#frmMonitor-chatMessages').is(':checked') === true)
        }
        var notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        $.ajax({
            type: "POST",
            url: '/settings/save/monitor',
            timeout: timeoutMedium,
            data: data,
            dataType: 'json',
            success: function (data) {
                notify.update('progress', 0);
                notify.update('type', data.type);
                notify.update('message', data.message);
            },
            error: function (xmlhttprequest, textstatus, message) {
                notify.update('progress', 0);
                notify.update('type', 'danger');
                notify.update('message', message);
            }
        });
    });


    //============================================== Discord Settings
    $('#frmDiscord-save').click(function () {
        let data = {
            enabled: ($('#frmDiscord-enabled').is(':checked') === true),
            token: $('#frmDiscord-token').val().trim(),
            announceChannel: $('#frmDiscord-announceChannel').val().trim(),
            prefix: $('#frmDiscord-prefix').val().trim(),
            statusMessage: $('#frmDiscord-statusMessage').val().trim()
        };
        if (data.enabled && (!data.token.length || !data.prefix.length || !data.statusMessage.length)) {
            var notify = $.notify({ message: 'The fields with "*" are required when the bot is enabled.' }, { type: 'warning' });
            return;
        }
        var notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        $.ajax({
            type: "POST",
            url: '/settings/save/discord',
            timeout: timeoutMedium,
            data: data,
            dataType: 'json',
            success: function (data) {
                notify.update('progress', 0);
                notify.update('type', data.type);
                notify.update('message', data.message);
            },
            error: function (xmlhttprequest, textstatus, message) {
                notify.update('progress', 0);
                notify.update('type', 'danger');
                notify.update('message', message);
            }
        });
    });

</script>
