<?php
// Copyright 1999-2026. WebPros International GmbH. All rights reserved.
?>
<?php echo $this->element->getElement('logRotationEnabled')->render($this); ?>
<?php echo $this->partial('partials/forms/radio-controls.phtml', null, $this); ?>
<?php echo $this->element->getElement('maximumNumberOfFiles')->render($this); ?>
<?php echo $this->element->getElement('compress')->render($this); ?>
<?php echo $this->element->getElement('sendLogToEmail')->render($this); ?>
<?php $typeElement = $this->element->getElement($this->radio);?>
<script type="text/javascript">
//<![CDATA[
(function () {
    var updateControlsState = function () {
        let radio;
        let control;
        <?php foreach($this->indentControls as $option => $control): ?>
            radio = document.getElementById('<?php echo $typeElement->getId() . '-' . $option ?>');
            control = document.getElementById('<?php echo $this->element->getElement($control)->getId() ?>');
            if (radio.checked && !radio.disabled) {
                control.disabled = false;
            } else {
                control.disabled = true;
            }
        <?php endforeach;?>
    };

    var enableControl = function (control, value) {
        if (value) {
            control.disabled = false;
        } else {
            control.disabled = true;
        }
    };

    var updateLogRotation = function () {
        var isForced = <?= $this->isForced ?>;
        var checkbox = document.getElementById('<?= $this->element->getElement('logRotationEnabled')->getId() ?>');
        <?php foreach ($typeElement->getMultiOptions() as $option => $optionTitle): ?>
            var control = document.getElementById('<?php echo $typeElement->getId() . '-' . $option ?>');
            enableControl(control, !isForced && checkbox.checked);
        <?php endforeach;?>
        enableControl(document.getElementById('<?= $this->element->getElement('logRotationEnabled')->getId() ?>'), !isForced);
        enableControl(document.getElementById('<?= $this->element->getElement('maximumNumberOfFiles')->getId() ?>'), checkbox.checked);
        enableControl(document.getElementById('<?= $this->element->getElement('compress')->getId() ?>'), checkbox.checked);
        enableControl(document.getElementById('<?= $this->element->getElement('sendLogToEmail')->getId() ?>'), checkbox.checked);
        updateControlsState();
    };

    <?php foreach ($typeElement->getMultiOptions() as $option => $optionTitle): ?>
    document.getElementById('<?php echo $typeElement->getId() . '-' . $option ?>').addEventListener('click', updateControlsState);
    <?php endforeach;?>
    document.getElementById('<?php echo $this->element->getElement('logRotationEnabled')->getId() ?>').addEventListener('click', updateLogRotation);
    updateLogRotation();
})();
//]]>
</script>
