<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
?>
<script type="text/javascript">
//<![CDATA[
    new Jsw.Hint({
        renderTo: 'main',
        hint: <?php echo Zend_Json::encode($this->pageHint); ?>
    });

    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'subscriptions-list',
                searchFilters: <?php echo Zend_Json::encode($this->subscriptionsList->getSearchFilterConfig()); ?>,
                searchOveral: 'subscriptionName',
                data: <?php echo Zend_Json::encode($this->subscriptionsList->fetchData()); ?>,
                dataUrl: '/business-model-upgrade/subscriptions-target-data/solutions/<?php echo $this->solutions?>',
                columns: [
                    {
                        header: <?php echo $this->subscriptionsList->jsLmsg('subscriptionName');?>,
                        sortable: true,
                        dataIndex: 'subscriptionName',
                        <?php if ($this->showOwner): ?>cls: 'name',
                        <?php endif; ?>renderer: function (item, isDisabled) {
                            return (
                                '<a href="' + Jsw.prepareUrl('/subscription/overview/id/' + item.id) + '">' +
                                    Jsw.escapeHtml(item.subscriptionName) +
                                '</a>'
                            );
                        }
                    },
                    <?php if ($this->showOwner): ?>
                    {
                        header: <?php echo $this->subscriptionsList->jsLmsg('ownerName');?>,
                        sortable: true,
                        dataIndex: 'ownerName',
                        renderer: function (item, isDisabled) {
                            var linkHref = null;
                            if ('client' == item.ownerType) {
                                linkHref = 'customer';
                            } else if ('reseller' == item.ownerType) {
                                linkHref = 'reseller';
                            }
                            var link =
                                (linkHref ? '<a href="' + Jsw.prepareUrl('/' + linkHref + '/overview/id/' + item.ownerId) + '">' : '')
                                    + Jsw.escapeHtml(item.ownerName) +
                                (linkHref ? '</a>' : '') +
                                (item.ownerCompanyName ? ', ' + Jsw.escapeHtml(item.ownerCompanyName) : '');
                            return link;
                        }
                    },
                    <?php endif?>
                    {
                        header: '',
                        sortable: false,
                        cls: 'min',
                        renderer: function (item, isDisabled) {
                            return Jsw.getControlPanelLoginHtml(item.id, {
                                'openInNew': 'admin' != item.ownerType,
                                <?php if ($this->layout()->isClassicMode): ?>
                                    'label': <?php echo $this->subscriptionsList->jsLmsg('admin.components.lists.subscriptions.buttonLoginClassicMode') ?>,
                                    'hint': <?php echo $this->subscriptionsList->jsLmsg('admin.components.lists.subscriptions.hintLoginClassicMode'); ?>,
                                <?php else: ?>
                                    'label': <?php echo $this->subscriptionsList->jsLmsg('admin.components.lists.subscriptions.buttonLogin') ?>,
                                    'hint': 'admin' == item.ownerType ? <?php echo $this->subscriptionsList->jsLmsg('admin.components.lists.subscriptions.hintAdminLogin'); ?> : <?php echo $this->subscriptionsList->jsLmsg('admin.components.lists.subscriptions.hintLogin'); ?>,
                                <?php endif; ?>
                                'returnUrl': 'admin' == item.ownerType ? '/business-model-upgrade/admin-subscriptions-target-list/solutions/<?php echo $this->solutions ?>' : null,
                                'isClassicUi': <?php echo $this->layout()->isClassicMode ? 'true' : 'false' ?>
                            });
                        }
                    }
                ],
                onRedraw: function () {
                    document.querySelectorAll('span.hint.hint-info').forEach(function (hintElement) {
                        new Jsw.DynamicPopupHint.Instance({
                            title: <?php echo $this->jsLmsg('admin.components.lists.subscriptions.hintTitle'); ?>,
                            waitMsg: <?php echo $this->jsLmsg('admin.components.lists.subscriptions.hintWaitMessage'); ?>,
                            url: '/subscription/stats-hint/domainId/' + hintElement.id.replace('hint-item-', ''),
                            placement: 'right',
                            target: hintElement.id
                        });
                    });
                }
            })
        ]
    });
//]]>
</script>
