<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.

$automaticUpdates = $this->element->getElement('automaticUpdates');
$thirdPartyUpdates = $this->element->getElement('thirdPartyUpdates');
?>
<div class='form-row'>
    <div class='single-row'>
        <div class="indent-box">
            <?php echo $this->elementPart($automaticUpdates)->content() ?>
            <div class="indent-box-content">
                <?php echo $this->elementPart($automaticUpdates)->label() ?>
                <?php echo $this->elementPart($automaticUpdates)->description() ?>
                <?php if ($thirdPartyUpdates): ?>
                <div class="indent-box">
                    <?php echo $this->elementPart($thirdPartyUpdates)->content() ?>
                    <div class="indent-box-content">
                        <?php echo $this->elementPart($thirdPartyUpdates)->label() ?>
                        <?php echo $this->elementPart($thirdPartyUpdates)->description() ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<?php if ($thirdPartyUpdates): ?>
<script>
(function () {
    var updateControlsState = function () {
        const thirdPartyCheckbox = document.getElementById('<?php echo $thirdPartyUpdates->getId() ?>');
        const isUpdatesDisabled = !document.getElementById('<?php echo $automaticUpdates->getId() ?>').checked;

        document.querySelector('[type="hidden"][name="<?php echo $thirdPartyUpdates->getFullyQualifiedName() ?>"]').value = isUpdatesDisabled && thirdPartyCheckbox.checked ? "1" : "0";
        thirdPartyCheckbox.disabled = isUpdatesDisabled;
    }

    document.getElementById('<?php echo $automaticUpdates->getId() ?>').addEventListener('click', updateControlsState);
    updateControlsState();
})();
</script>
<?php endif; ?>
