{include file="./index_top.tpl"}
{if $tariff_limits.mp_off}
<div align=center><br>{$lang.Not_supported_cur_tariff}</div>
{else}
<style>
.archive_module {
    display: none;
}
</style>
<script>
    {if $error}jalert("{$error}");{/if}
    function makePreloader() {
        const overlay = `<div class='overlay'><div>`;
        const preloader = `<div class="preloader__block" style="z-index: 10000000;">
                                        <div class="preloader">
                                            <div class="lds-css ng-scope">
                                                <div style="width:100%;height:100%" class="lds-ellipsis">
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>`;
        $('body').append(overlay);
        $('body').append(preloader);
    }

    function destroyPreloader() {
        $('.overlay').hide();
        $('.preloader__block').hide();
    }

    function show_archive() {
        $('.active_module').hide();
        $('.archive_module').show();
        $('#arc_switcher').html('<a style="font-size:14px;" href="" onclick="hide_archive(); return false;">{$lang.active}</a> / <span>{$lang.archive}</span>');
    }

    function hide_archive() {
        $('.archive_module').hide();
        $('.active_module').show();
        $('#arc_switcher').html('<span>{$lang.active}</span> / <a style="font-size:14px;" href="" onclick="show_archive(); return false;">{$lang.archive}</a>');
    }
</script>
<div align=center>
    {if $user.group_id == 1 || ($user.sub_admin_rights.addons && $user.sub_admin_rights.modules)}
        <br>
        <div style="font-size:13px">
            <a href="edit_transfer.php">{$lang.Addons}</a> / {$lang.Modules_short}
            {if $configuration_has} / <a href="edit_configuration.php">{$lang.Configuration}</a>{/if}
        </div>
    {/if}
    <br>{$cur_title}<span class='help_bt' h_id='Modules'></span><br><br>
    <div id="arc_switcher">
        <span>{$lang.active}</span> / <a style="font-size:14px;" href="" onclick="show_archive(); return false;">{$lang.archive}</a>
    </div><br>
    <!--form action="edit_modules.php" method="post">
    <input type=hidden name=csrf value={$csrf}>
    <table class='sortableTable'-->
    <table border=0 cellpadding=3>
        {foreach from=$all_modules item=one_module key=module_name}
            <tr class="{if $module_name|in_array:['livechat', 'asterisk', 'social_messages', 'api', 'cbext.clientbase.fb_lead', 'cbext.clientbase.iptel_primatel']}archive{else}active{/if}_module">
                <!--td><span class="draggableImg">&nbsp;</span><input type="hidden" name="num[{$module_name}]" value="{$one_module.num}"></td-->
                {if $one_module.old_format}
                    <td>
                        {if isset($one_module.block) && $one_module.block eq "1"}
                            <span>{$one_module.display_name} ({$one_module.version})</span>
                        {else}
                            <a id="module__{$module_name}" href="edit_modules.php?module={$module_name}" {if $one_module.status eq "1"}class="disabled" {/if}>{$one_module.display_name} ({$one_module.version})</a>
                        {/if}
                    </td>
                    <td style="display: flex;">
                        {if isset($one_module.block) && $one_module.block eq "1"}
                            {$lang.Module_configurate_proc}
                        {else}
                            {*{if $one_module.status eq "0"}{$lang.Turn_on}{else}{$lang.Turn_off}{/if}{if $one_module.trial_mode && $one_module.status eq "0"} ({$lang.Free_mode}){/if}*}
                            {if $module_name == 'telegram'}
                                {include file="modules/{$module_name}/views/{$module_name}_switch_button.tpl"}
                            {elseif $module_name == 'social_messages'}
                                {include file="modules/{$module_name}/templates/vk_switch_button.tpl"}
                            {else}
                                {include file="modules/{$module_name}/templates/{$module_name}_switch_button.tpl"}
                            {/if}
                        {/if}
                    </td>
                {else}
                    <td>
                        {if $one_module.is_active}
                            <a href="edit_modules.php?extension={$module_name}">{$one_module.display_name}</a>
                        {else}
                            <span style="cursor: default;color: #888;">{$one_module.display_name}</span>
                        {/if}
                    </td>
                    <td style="display: flex;">
                    <div class="{if $one_module.is_progress}switch-lock{/if}">
                        <div
                            class="switch-btn {if $one_module.is_active}switch-on{/if}"
                            onclick="
                                    {if $one_module.is_progress}
                                        jalert('{$one_module.is_progress}');
                                    {else}
                                    {if $one_module.is_active}
                                        jconfirm('{$lang.disabled_module_alert}', function(){ location.href='edit_modules.php?extension={$module_name}&activate=off' })
                                    
                                    {else}
                                        location.href='edit_modules.php?extension={$module_name}&activate=on'
                                    {/if}
                                    {/if}"
                        ><div></div></div>
                            {if $one_module.is_progress}
                                <div class="switch-icon-wrapper">
                                    <img src="images/icons/lock.svg" alt="Lock" class="switch-icon"/>
                                </div>
                            {/if}
                        </div>
                        
                    </td>
                {/if}
                {if $module_name|in_array:['livechat', 'asterisk', 'social_messages', 'api', 'cbext.clientbase.fb_lead', 'cbext.clientbase.iptel_primatel']}
                    <td style="padding-left: 40px; color: gray; font-style: italic;">{$lang.not_supported}</td>
                {/if}
            </tr>
        {foreachelse}
            <tr>
                <td>{$lang.no_modules}.</td>
            </tr>
        {/foreach}
    </table>
</div>
{/if}