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

<script type="text/javascript">
    //<![CDATA[
    Jsw.namespace('AdminPanel.WebAppFirewall');
    AdminPanel.WebAppFirewall.confirmation = function () {
        const data = <?php echo json_encode($this->confirmationData) ?>;
        const {currentWebServer, currentRuleSet, isCustomized, needPresetWarning} = data;
        const messages = [];

        if (document.getElementById('ruleEngine-DetectionOnly').checked && needPresetWarning) {
            messages.push('<?php echo $this->lmsg("{$this->localeSection}.detectionOnlyAndThoroughModeWarning", ['_escape' => false]) ?>');
        }

        if (0 === messages.length) {
            return true;
        }

        let description = messages[0];
        let descriptionWrapperTag = 'p';
        let descriptionDecorator = content => content;
        if (1 < messages.length) {
            description = messages.map(description => `<li>${description}</li>`).join('');
            descriptionWrapperTag = 'ul';
        }

        Jsw.messageBox.show({
            type: Jsw.messageBox.TYPE_YESNO,
            subtype: 'confirm',
            text: <?php echo $this->jsLmsg("{$this->localeSection}.ruleSetCrsConfirmTitle") ?>,
            description: description,
            descriptionWrapperTag: descriptionWrapperTag,
            descriptionDecorator: descriptionDecorator,
            onYesClick: function () {
                const confirmation = AdminPanel.WebAppFirewall.confirmation;
                AdminPanel.WebAppFirewall.confirmation = function () {
                    AdminPanel.WebAppFirewall.confirmation = confirmation;
                    return true;
                };
                const form = document.getElementById('<?php echo $this->escape($this->form->getId()) ?>').closest('form');
                Jsw.submit(form, form.noRedirect);
            },
            buttonTitles: {
                yes: <?php echo $this->jsLmsg('components.buttons.yes') ?>,
                no: <?php echo $this->jsLmsg('components.buttons.no') ?>
            },
        });
        return false;
    };
    //]]>
</script>
