{{@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=='monitor'|isActive}}" id="nav-monitor-tab" data-toggle="tab" href="#nav-monitor"
                            role="tab" aria-controls="nav-monitor" aria-selected="true">Restarter</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=='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="bs" {{it.global.language=='bs'|isSelected}}>Bosnian</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="fa" {{it.global.language=='fa'|isSelected}}>Farsi - Persian</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="it" {{it.global.language=='it'|isSelected}}>Italian</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>. <br>
                                    {{@if(it.isZapHosting)}}
                                        <span class="font-weight-bold">Zap-Hosting warning: this path must start with <code>{{it.txDataPath}}</code>.</span>
                                    {{/if}}
                                </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 sv_enforceGameBuild 2189" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-primary">
                                    To enable the Beta In-game, add <code>+setr txEnableMenuBeta true</code> above.
                                </span>
                                <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. <br>
                                    <b>Note:</b> These commands can be set inside the <code>server.cfg</code> as well.
                                </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 48 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 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 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 -->

                    <!-- Restarter 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-restarterSchedule" class="col-sm-3 col-form-label">Scheduled Restarts</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmMonitor-restarterSchedule" 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 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="form-group row">
                            <label for="frmMonitor-restarterScheduleWarnings" class="col-sm-3 col-form-label">Restart Warnings</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="frmMonitor-restarterScheduleWarnings" value="{{it.monitor.restarterScheduleWarnings|undef}}"
                                    placeholder="30, 15, 10, 5, 4, 3, 2, 1" {{it.readOnly|isDisabled}}>
                                <span class="form-text text-muted">
                                    Minutes before restarts to trigger chat warnings <br>
                                    All the minutes must be between 1 and 360 minutes and be separated by commas. <br>
                                    <strong>Note:</strong> This will also trigger the server event <code>txAdmin:events:scheduledRestart</code> <a href="https://github.com/tabarra/txAdmin/blob/master/docs/events.md" target="_blank" rel="noopener noreferrer">(docs)</a>
                                </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>
                    <!-- /Restarter 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 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 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 Request 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 class="col-sm-3 col-form-label">
                                Wipe Pending 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 from getting 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 -->

                    <!-- 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 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 blur-input" id="frmDiscord-token" 
                                    value="{{@if(!it.readOnly)}}{{it.discord.token|undef}}{{#else}}[redacted]{{/if}}"
                                    placeholder="CXPcWbxKOHpwlUBaYKznIfkz.ExpTAB.NX-3YxfmVIGUJLGbPamViXGAEiY"
                                    maxlength="96" autocomplete="off" {{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>

<!-- Master actions -->
<div class="row justify-content-md-center">
    <div class="col-md-7 mw-col8">
        <div class="card border-danger">
            <div class="card-header text-center">
                <h5 class="d-inline">Master Actions</h5>
            </div>
            <div class="card-body">
                {{@if(it.isWebInterface && it.adminIsMaster)}}
                    <!-- Backup Database -->
                    <div class="row text-center pt-2">
                        <div class="col-lg-9 text-lg-left mb-2">
                            <h5>Backup Database</h5>
                            Download a copy of the <code>playersDB.json</code> file containing all players and actions (bans, warns and whitelists).  
                            You should do this every once in a while.
                        </div>
                        <div class="col-lg-3 text-lg-right">
                            <a class="btn btn-sm btn-outline-danger" target="_blank" href="masterActions/backupDatabase">Backup Database</a>
                        </div>
                    </div>
                    <hr class="m-1">

                    <!-- Import bans -->
                    <div class="row text-center pt-2">
                        <div class="col-lg-9 text-lg-left mb-2">
                            <h5>Import Bans</h5>
                            If you wish to migrate from another ban system, use this tool to import existing bans. <br>
                            Supported systems: EasyAdmin, BanSQL, vMenu, vRP, el_bwh.
                        </div>
                        <div class="col-lg-3 text-lg-right">
                            <a class="btn btn-sm btn-outline-danger" href="masterActions/importBans">Import Bans</a>
                        </div>
                    </div>
                    <hr class="m-1">

                    <!-- Reset FXServer -->
                    <div class="row text-center">
                        <div class="col-lg-9 text-lg-left mb-2">
                            <h5>Reset FXServer</h5>
                            In the FXServer tab you can change the server data path, but if you want to use
                            the Deployer again, you will need to use this option. <br>
                            None of your files or databases will be deleted by doing that.
                        </div>
                        <div class="col-lg-3 text-lg-right">
                            <button class="btn btn-sm btn-outline-danger" type="button" 
                                onclick="masterActionsActions('reset_fxserver');">Reset FXServer</button>
                        </div>
                    </div>
                    <!-- <hr class="m-1"> -->
                {{#else}}
                    <div class="row justify-content-center text-center d-block">
                        <h3 class="mt-3 text-secondary">Master Actions Disabled</h3>
                        <p class="text-muted">
                            {{@if(it.adminIsMaster)}}
                                Please use the web panel in your browser if you would like to backup your database, 
                                import bans, or reset FXServer settings.
                            {{#else}}
                                Only the admin master can perform actions like backup the database, import bans, or
                                reset FXServer settings.
                            {{/if}}
                        </p>
                    </div>
                {{/if}}
            </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);
    }

    //============================================== Master Actions
    function masterActionsActions(action){
        if(!window.confirm(`Are you sure you want to Reset FXServer Settings?`)){
            return;
        }
        const notify = $.notify({ message: '<p class="text-center">Executing...</p>' }, {});
        
        txAdminAPI({
            type: "POST",
            url: `/masterActions/${action}`,
            data: {},
            dataType: 'json',
            success: function (data) {
                if(action == 'reset_fxserver' && data.success == true){
                    window.location = '/setup';
                    return;
                }else{
                    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);
            }
        });
    }


    //============================================== 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) {
            return $.notify({ message: 'The fields with "*" are required.' }, { type: 'warning' });
        }
        const notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        txAdminAPI({
            type: "POST",
            url: '/settings/save/global',
            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) {
            return $.notify({ message: 'The fields with "*" are required.' }, { type: 'warning' });
        }
        const notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        txAdminAPI({
            type: "POST",
            url: '/settings/save/fxserver',
            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) {
            return $.notify({ message: 'The fields with "*" are required.' }, { type: 'warning' });
        }
        const notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        txAdminAPI({
            type: "POST",
            url: '/settings/save/playerController',
            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 = {
            restarterSchedule: $('#frmMonitor-restarterSchedule').val().trim(),
            restarterScheduleWarnings: $('#frmMonitor-restarterScheduleWarnings').val().trim(),
            disableChatWarnings: ($('#frmMonitor-chatMessages').is(':checked') === true),
        }
        const notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        txAdminAPI({
            type: "POST",
            url: '/settings/save/monitor',
            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)) {
            return $.notify({ message: 'The fields with "*" are required when the bot is enabled.' }, { type: 'warning' });
        }
        const notify = $.notify({ message: '<p class="text-center">Saving...</p>' }, {});

        txAdminAPI({
            type: "POST",
            url: '/settings/save/discord',
            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>
