<div class="panel panel-default">
    <div class="panel-heading">{$lang.lk_updating}</div>
    <div class="panel-body">
        <div class="row">
            <form class="form-inline">
                <div class="col-xs-5 col-sm-6 text-right no-padding">
                    <label for="lk_backup_auto_update_f">{$lang.lk_auto_update}</label>
                    <span class='help_bt' h_id='lk_auto_update'></span>:
                </div>
                <div class="col-xs-5 text-left" id="lk_backup_auto_update_v">
                    <span id="lk_backup_auto_update_s">{$lang[$data.auto_update|replace:'да':'yes'|replace:'нет':'no']}</span>&nbsp;
                    <a href="#"
                       onclick="lk_change('backup', 'update', 'auto_update'); return false;">{$lang.lk_change}</a>
                </div>
                <div class="col-xs-5 text-left hidden" id="lk_backup_auto_update_e">
                    <div class="form-group">
                        <select class="form-control" id="lk_backup_auto_update_f">
                            {foreach from=$data.auto_update_edit key=key item=val}
                                <option {if $val==$data.auto_update}selected{/if}>{$lang[$val|replace:'да':'yes'|replace:'нет':'no']}</option>
                            {/foreach}
                        </select>
                        <a href="#"
                           onclick="lk_edit('backup', 'update', 'auto_update'); return false;">{$lang.lk_save}</a>
                        <span id="lk_backup_auto_update_c">&nbsp;</span>
                    </div>
                </div>
            </form>
        </div>
        <div class="row">
            <div class="no-padding col-xs-12 text-center" id="lk_manager_foto_v">
                {if isset($saas_config.configuration_revision)}
                    {if $saas_config.configuration_revision == $data.last_configuration_revision}
                        <p>{$lang.lk_using_last_revision|substr:0:-1} ({$saas_config.configuration_revision}).</p>
                    {elseif isset($saas_config.in_market_licence_table) && $saas_config.in_market_licence_table == 1}
                        <p>
                            {$lang.lk_cur_rev_configuration} {$saas_config.configuration_revision}.<br>
                            {$lang.update_to_last_conf_rev} {$data.last_configuration_revision}?<br>
                        </p>
                    {/if}
                {else}
                    {if $data.cur_version_int < $data.last_version_int || $data.cur_revision < $data.last_revision || $data.cur_revision < $data.user_last_revision}
                        <p>
                            {$lang.lk_Version_programm}: {$data.cur_version}
                            <br>
                            {$lang.Revision}: {$data.cur_revision} {$lang.revision_of} {$data.cur_date|form_local_time}
                        </p>
                    {else}
                        <p>{$lang.lk_you_use_last_version1} {$data.cur_version}
                            ({$data.cur_revision} {$lang.lk_revision})
                            {$lang.lk_you_use_last_version2}</p>
                    {/if}
                {/if}
                {if (isset($saas_config.configuration_revision) && $saas_config.configuration_revision != $data.last_configuration_revision)
                || ($data.cur_revision < $data.last_revision || $data.cur_version_int < $data.last_version_int || $data.cur_revision < $data.user_last_revision)}
                    {if ($data.cur_version_int == $data.last_version_int && $data.cur_revision < $data.last_revision) || $data.cur_revision < $data.user_last_revision}
                        <input id="lk_update_button" class="btn btn-light lk_update_button" type="button" {if $data.update_started}disabled{/if}
                               value="{if $data.update_started}{$lang.lk_update_start}{else}{$lang.lk_update_revision} {$lang.until} {$data.user_last_revision}{/if}"
                               onclick="this.disabled = true; this.value = '{$lang.lk_send_request}'; lk_edit('update', 'updateRevision', 'create_backup'); return false;">
                    {/if}
                    {if $data.cur_version_int < $data.last_version_int}
                        <input id="lk_update_button" class="btn btn-light lk_update_button" type="button" {if $data.update_started}disabled{/if}
                               value="{if $data.update_started}{$lang.lk_update_start}{else}{$lang.lk_update_version} {$lang.until} {$data.last_version}{/if}"
                               onclick="this.disabled = true; lk_edit('update', 'updateVersion', 'create_backup'); return false;">
                    {/if}
                    {if $data.cur_version_int == $data.last_version_int && $data.cur_revision == $data.last_revision && $saas_config.configuration_revision != $data.last_configuration_revision}
                        <input class="btn btn-light" type="button" value="{$lang.lk_update_revision} {$lang.until} {$data.last_configuration_revision}"
                               onclick="lk_edit('update', 'updateRevision', 'create_backup'); return false;">
                    {/if}
                    <span id="lk_update_create_backup_c"></span>
                    <p>
                        {if $data.last_backup != '0000-00-00 00:00:00'}
                            {$lang.lk_time_last_backup} {$data.last_backup|form_local_time:1}
                        {/if}
                        <label style="display: flex; align-items: center; justify-content: center;">
                            <input class="form-check-input" id="lk_update_create_backup_f" type="checkbox" value="да"
                                   name="backup" checked{if isset($saas_config.configuration_revision)} disabled{/if}>&nbsp;
                            {$lang.lk_create_backup}
                        </label>
                    </p>
                {/if}
            </div>
        </div>
    </div>
</div>
<script>
const inputFields = document.querySelectorAll('input.form-control');
for (const inputField of inputFields) {
    inputField.addEventListener('keypress', function(event) {
        if (event.key === 'Enter') {
            let items = inputField.id.split('_');
            lk_edit(items[1], 'update', items[2]);
            event.preventDefault();
        }
    });
}
</script>