<?php
// Copyright 1999-2025. 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">
            <?php echo $this->lmsg("{$this->localeSection}.ruleSetComodoInstalled") ?>
            <a href="#" id="<?php echo $this->escape($this->element->getId()) ?>-toggler" class="toggler">
                <?php echo $this->lmsg("{$this->localeSection}.ruleSetComodoInstall") ?>
            </a>
        </div>
        <div id="<?php echo $this->escape($this->element->getId()) ?>-credentials">
            <?php echo $this->lmsg($this->localeSection . ('true' === $this->element->getValue()
                ? ".ruleSetComodoHowTo" : ".ruleSetComodoSwitchHowTo")) ?>
            <ol class="ol">
                <li>
                    <a href="<?php echo $this->escape($this->registerUrl) ?>" target="_blank">
                        <?php echo $this->lmsg("{$this->localeSection}.ruleSetComodoRegister") ?>
                    </a>
                </li>
                <li>
                    <?php echo $this->lmsg("{$this->localeSection}.ruleSetComodoCredentials") ?>
                </li>
            </ol>
        </div>
    </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 credentialsHint = document.getElementById('<?php echo $this->escape($this->element->getId()) ?>-credentials');
    var loginInput = document.getElementById('<?php echo $this->escape($this->form->getElement('ruleSetComodoLogin')->getId()) ?>');
    var passwordInput = document.getElementById('<?php echo $this->escape($this->form->getElement('ruleSetComodoPassword')->getId()) ?>');
    var updateControls = function () {
        var showReplace = false;
        var showCredentials = false;
        if (document.getElementById('<?php echo $this->escape($this->form->getElement('ruleSet')->getId()) ?>-comodo').checked) {
            showReplace = 'true' !== installHidden.value;
            showCredentials = !showReplace;
        }
        installHidden.closest('.form-row').style.display = (showReplace || showCredentials) ? '' : 'none';
        replaceHint.style.display = showReplace ? '' : 'none';
        credentialsHint.style.display = showCredentials ? '' : 'none';
        loginInput.closest('.form-row').style.display = showCredentials ? '' : 'none';
        passwordInput.closest('.form-row').style.display = showCredentials ? '' : '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>
