<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
?>

<script type="text/javascript">
//<![CDATA[
    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.Hint({
                hint: <?php echo $this->hint ?>
            }),

            new Jsw.List({
                id: 'banned-ips-list',
                data: <?php echo Zend_Json::encode($this->bannedIpsList->fetchData()); ?>,
                dataUrl: <?php echo $this->jsEscape($this->dataUrl); ?>,
                searchFilters: <?php echo Zend_Json::encode($this->bannedIpsList->getSearchFilterConfig()); ?>,
                operations: [
                <?php if ($this->isManualBanEnabled): ?>
                {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonBanIp',
                    title: <?php echo $this->bannedIpsList->jsLmsg('buttonBanIp') ?>,
                    description: <?php echo !$this->banActive
                            ? $this->bannedIpsList->jsLmsg('hintBanIpFail2BanDisabled')
                            : (!$this->isManualJailActive
                                    ? $this->bannedIpsList->jsLmsg(
                                            'hintBanIpNoActiveManualJails',
                                            ['manualJailList' => implode(', ', array_column(Plesk\Ip\Ban\Enum\ManualJailNameEnum::cases(), 'value'))],
                                    )
                                    : $this->bannedIpsList->jsLmsg('hintBanIp'))
                    ?>,
                    addCls: 'sb-item-add',
                    href: '/server-protection/add-banned-ip',
                    <?php if (!$this->banActive || !$this->isManualJailActive): ?>
                    disabled: true,
                    <?php endif; ?>
                },
                <?php endif; ?>
                {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonMoveToTrustedIp',
                    title: <?php echo $this->bannedIpsList->jsLmsg('buttonMoveToTrustedIp') ?>,
                    description: <?php echo $this->banActive ?
                        $this->bannedIpsList->jsLmsg('hintMoveToTrustedIp') :
                        $this->bannedIpsList->jsLmsg('hintMoveToTrustedIpFail2BanDisabled')
                    ?>,
                    addCls: 'sb-move',
                    handler: function(event) {
                        Jsw.getComponent('banned-ips-list').execGroupOperation({
                            url: '/server-protection/move-to-trusted',
                            subtype: 'move',
                            skipConfirmation: true
                        });
                    },
                    <?php if (!$this->banActive): ?>
                    disabled: true,
                    <?php endif; ?>
                }, {
                    componentType: 'Jsw.bar.Separator'
                }, {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonRemoveIp',
                    title: <?php echo $this->bannedIpsList->jsLmsg('buttonRemoveIp') ?>,
                    description: <?php echo $this->banActive ?
                        $this->bannedIpsList->jsLmsg('hintRemoveIp') :
                        $this->bannedIpsList->jsLmsg('hintRemoveIpFail2BanDisabled')
                    ?>,
                    addCls: 'sb-remove-selected',
                    handler: function(event) {
                        Jsw.getComponent('banned-ips-list').execGroupOperation({
                            url: '/server-protection/delete-banned-ips',
                            subtype: 'delete',
                            skipConfirmation: true
                        });
                    },
                    <?php if (!$this->banActive): ?>
                    disabled: true,
                    <?php endif; ?>
                }
                <?php if ($this->showBanSwitchOnOffButton): ?>
                , {
                    componentType: 'Jsw.bar.Separator'
                }, {
                    componentType: 'Jsw.SmallButton',
                    <?php if ($this->banActive): ?>
                    id: 'buttonDisable',
                    attrs: { 'data-method': 'post' },
                    title: <?php echo $this->bannedIpsList->jsLmsg('buttonDisable') ?>,
                    description: <?php echo $this->bannedIpsList->jsLmsg('hintDisable') ?>,
                    addCls: 'sb-turn-off',
                    href: '/server-protection/disable'
                    <?php else: ?>
                    id: 'buttonEnable',
                    attrs: { 'data-method': 'post' },
                    title: <?php echo $this->bannedIpsList->jsLmsg('buttonEnable') ?>,
                    description: <?php echo $this->bannedIpsList->jsLmsg('hintEnable') ?>,
                    addCls: 'sb-turn-on',
                    href: '/server-protection/enable'
                    <?php endif; ?>
                }
                <?php endif; ?>
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->bannedIpsList->jsLmsg('ip');?>,
                        sortable: true,
                        dataIndex: 'ip'
                    <?php if ($this->showJailColumn): ?>
                    }, {
                        header: <?php echo $this->bannedIpsList->jsLmsg('jail');?>,
                        sortable: true,
                        dataIndex: 'jail',
                        renderer: function (item) {
                            var link = Jsw.prepareUrl('/server-protection/overview-jail/id/' +  encodeURIComponent(item.jail));
                            return '<a href="' + link + '">' + Jsw.escapeHtml(item.jail) + '</a>';
                        }
                    <?php endif; ?>
                    }
                ]
            })
        ]
    });
//]]>
</script>
