<?php
// Copyright 1999-2026. WebPros International GmbH. All rights reserved.
?>
<div class='form-row'>
    <div class="field-name">
        <label for="<?php echo $this->element->getId(); ?>">
            <?php echo $this->element->getLabel(); ?>
            <?= $this->requiredMark(!$this->readOnly) ?>
        </label>
    </div>

    <div class='field-value'>
        <span>
            <img aria-hidden="true" src="<?php echo $this->skinUrl('/icons/16/plesk/website.png'); ?>"/>
            /
            <?php if ($this->readOnly): ?>
                <?php echo $this->escape($this->element->getValue()); ?>
                <?php if ($this->readOnlyHint): ?>
                    <?php echo $this->elementPart($this->element)->description(); ?>
                <?php endif; ?>
            <?php else: ?>
                <?php echo $this->elementPart($this->element)->content(); ?>
                <?php echo $this->elementPart($this->element)->description(); ?>
            <?php endif; ?>
        </span>
        <span class="field-errors" style="display: none;"></span>
    </div>
</div>
<script type="text/javascript">
//<![CDATA[
(() => {
    const generateDocRootPath = e => {
        const element = document.getElementById('hostingSettings-root');
        const docrootPattern = document.getElementById('hostingSettings-rootPattern').value;
        let docroot = e.detail.replace(/\*/g, '_');

        if (-1 !== docrootPattern.indexOf('<domain>')) {
            docroot = docrootPattern.replace('<domain>', docroot);
        }

        element.value = Jsw.toPunycode(docroot);
        Jsw.fireCustomEvent(element, 'value:change');
    };

    const docrootEl = document.getElementById('<?= $this->element->getId() ?>');
    if (docrootEl && !docrootEl.value) {
        const formEl = docrootEl.closest('form');
        formEl.addEventListener('domainNameChange', generateDocRootPath);
        ['change', 'keyup'].forEach(eventName => {
            docrootEl.addEventListener(eventName, () => {
                formEl.removeEventListener('domainNameChange', generateDocRootPath);
            });
        });
    }
})();
//]]>
</script>
