<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
?>
<?php echo $this->partial('partials/forms/radio-controls.phtml', null, $this) ?>
<?php $previewTypeId = $this->element->getElement('previewType')->getId() ?>
<script type="text/javascript">
//<![CDATA[
(function () {
    var updateControlsState = function () {
        <?php if ($this->element->getElement('sitePreviewProtection')): ?>
            var previewDefault = document.getElementById('<?php echo $previewTypeId . "-" . Domain_Preview_Helper::PREVIEW_QUICK ?>');
            var siteProtectionElement = document.getElementById('<?php echo $this->element->getElement('sitePreviewProtection')->getId() ?>');
            if (previewDefault.checked) {
                siteProtectionElement.disabled = false;
            } else {
                siteProtectionElement.disabled = true;
            }
        <?php endif ?>
        <?php if (Plesk_Mode::isDnsServiceSupported()): ?>
            var previewInternal = document.getElementById('<?php echo $previewTypeId . "-" .Domain_Preview_Helper::PREVIEW_ZONE_TYPE_INTERNAL ?>');
            <?php if ($this->element->getElement('previewZoneDomainId')): ?>
            var internalSelector = document.getElementById('<?php echo $this->element->getElement('previewZoneDomainId')->getId() ?>');
            if (previewInternal.checked) {
                internalSelector.disabled = false;
            } else {
                internalSelector.disabled = true;
            }
            <?php else: ?>
                previewInternal.disabled = true;
            <?php endif ?>
        <?php endif ?>

        var previewExternal = document.getElementById('<?php echo $previewTypeId . "-" . Domain_Preview_Helper::PREVIEW_ZONE_TYPE_EXTERNAL ?>');
        var externalText = document.getElementById('<?php echo $this->element->getElement('previewZoneDomainName')->getId() ?>');
        if (previewExternal.checked) {
            externalText.disabled = false;
        } else {
            externalText.disabled = true;
        }
    };

    document.querySelectorAll(
        '#<?php echo$previewTypeId . "-" . Domain_Preview_Helper::PREVIEW_QUICK ?>,' +
        '#<?php echo$previewTypeId . "-" . Domain_Preview_Helper::PREVIEW_ZONE_TYPE_INTERNAL ?>,' +
        '#<?php echo$previewTypeId . "-" . Domain_Preview_Helper::PREVIEW_ZONE_TYPE_EXTERNAL ?>,' +
        '#<?php echo$previewTypeId . "-" . Domain_Preview_Helper::PREVIEW_DISABLED ?>'
    ).forEach(function (el) {
        el.addEventListener('click', updateControlsState)
    });
    updateControlsState();
})();
//]]>
</script>
