<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
?>
<div class="form-row">
    <div class="single-row">
        <?php echo $this->elementPart($this->element)->content() ?>
        <div id="<?php echo $this->escape($this->element->getId()) ?>-replace">
            <a href="#" id="<?php echo $this->escape($this->element->getId()) ?>-toggler" class="toggler">
                <?php echo $this->element->getLabel() ?>
            </a>
        </div>
        <?php echo $this->lmsg("{$this->localeSection}.ruleSetTortixHowTo") ?>
        <ol class="ol">
            <li>
                <?php echo $this->lmsg("{$this->localeSection}.ruleSetTortixBuy", [
                    '_escape' => false,
                    'linkPleskStore' => sprintf(
                        '<a href="%s" target="_blank">%s</a>',
                        $this->linkPleskStore,
                        $this->lmsg("{$this->localeSection}.ruleSetTortixLinkPleskStoreLabel")
                    ),
                    'linkDocumentation' => sprintf(
                        '<a href="%s" target="_blank">%s</a>',
                        $this->linkDocumentation,
                        $this->lmsg("{$this->localeSection}.ruleSetTortixLinkDocumentationLabel")
                    ),
                ]); ?>
            </li>
            <li>
                <?php echo $this->lmsg("{$this->localeSection}.ruleSetTortixSelect") ?>
            </li>
        </ol>
    </div>
</div>
<script type="text/javascript">
    //<![CDATA[
    Jsw.onReady(function () {
        var installHidden = document.getElementById('<?php echo $this->escape($this->element->getId()) ?>');
        var replaceHint = document.getElementById('<?php echo $this->escape($this->element->getId()) ?>-replace');
        var updateControls = function () {
            var show = false;
            if (document.getElementById('<?php echo $this->escape($this->form->getElement('ruleSet')->getId()) ?>-tortix').checked) {
                show = 'true' === installHidden.value && <?php echo $this->isTortixPro ? 'false' : 'true' ?>;
            }
            installHidden.closest('.form-row').style.display = show ? '' : 'none';
            replaceHint.style.display = !show ? '' : 'none';
        };
        updateControls();

        <?php foreach (array_keys($this->form->getElement('ruleSet')->getMultiOptions()) as $option): ?>
        document.getElementById('<?php echo $this->escape($this->form->getElement('ruleSet')->getId() . '-' . $option) ?>').addEventListener('click', updateControls);
        <?php endforeach ?>

        document.getElementById('<?php echo $this->escape($this->element->getId()) ?>-toggler').addEventListener('click', function(event) {
            event.preventDefault();
            installHidden.value = 'true';
            updateControls();
        });
    });
    //]]>
</script>
