<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
/** @var Zend_Form_Element $element */
$element = $this->element->getElement($this->domainNameElement);
$view = $element->getView();
$viewHelper = $view->elementPart($element);
$content = $viewHelper->content();
$error = $element->hasErrors() ? ' error' : '';
$errorStyle = $element->hasErrors() ? '' : ' style="display:none;"';
?>
<div id='<?php echo $element->getId()?>-form-row' class='form-row<?php echo $error?>'>
    <div class='field-name'><?php echo $viewHelper->label()?></div>
    <div class='field-value'>
        <?php echo $view->ltr(($this->www ? 'www.' : '') . ' ' . $content) ?>
        <span class='field-errors' <?php echo $errorStyle?>><?php echo $viewHelper->errors()?></span>
        <?php echo $viewHelper->description()?>
    </div>
</div>
<script>
    (() => {
        const domainNameEl = document.getElementById('<?= $element->getId() ?>');
        const formEl = domainNameEl.closest('form');
        ['change', 'keyup'].forEach(eventName => {
            domainNameEl.addEventListener(eventName, () => {
                formEl.dispatchEvent(new CustomEvent('domainNameChange', { detail: domainNameEl.value }));
            });
        });
    })();
</script>
