<?php
// Copyright 1999-2026. WebPros International GmbH. All rights reserved.
?>
<div class='form-row'>
    <div class='field-name'>
        <?php echo $this->elementPart($this->element->getElement($this->emailElementName))->label(); ?>
    </div>
    <div class='field-value'>
        <span>
            <?php
            echo $this->element->getElement($this->emailElementName)->readonly
                ? $this->escape($this->element->getElement($this->emailElementName)->getValue())
                : $this->elementPart($this->element->getElement($this->emailElementName))->content();
            if($this->domainName) {
                $domainElementId = str_replace('-name', '-domainName', $this->element->getElement($this->emailElementName)->getId());
                $domainName = "<span id=\"{$domainElementId}\">{$this->domainName}</span>";
            } else {
                $domainName = $this->elementPart($this->element->getElement($this->domainElementName))->content();
            }
            if ($this->isNewMail) {
                $domainName = '<b> @ ' . $domainName . '</b>';
            } else {
                $domainName = '@' . $domainName;
            }
            echo $domainName;
            ?>
        </span>
        <span class="field-errors" style="display: none;"></span>
    </div>
</div>
<?php if (isset($this->loginAsUserElementName)):?>
<?php $element = $this->element->getElement($this->loginAsUserElementName); ?>
<div class='form-row'>
    <div class="field-name" style="width: 100%;">
        <?php echo $this->elementPart($element)->content()?>
        <?php echo $this->elementPart($element)->label()?>
        <?php echo $this->elementPart($element)->inlineDescription()?>
    </div>
</div>
<?php if ($this->usernameIsChangeable):?>
<script type="text/javascript">
    //<![CDATA[
        document.getElementById('general-generalSection-name').addEventListener('change', function () {
            <?php if (1 < $this->domainsCount):?>
                var domainName = Jsw.escapeHtml(this.value) + '@' + document.getElementById('general-generalSection-domain')[document.getElementById('general-generalSection-domain').selectedIndex].text;
            <?php else: ?>
                var domainName = Jsw.escapeHtml(this.value) + '@' + '<?php echo $this->domainName;?>';
            <?php endif; ?>
            var username = <?php echo $this->jsLmsg('smb.components.forms.email-address.loginAsUserDescription')?>.replace('%%username%%', domainName);
            if (!this.value.length) {
                username = '';
            }
            document.getElementById('<?php echo $element->getId() ?>').parentNode.querySelector('.hint-inline').innerHTML = username;
        });

        <?php if (1 < $this->domainsCount):?>
        document.getElementById('general-generalSection-domain').addEventListener('change', function () {
            var domainName = document.getElementById('general-generalSection-name').value + '@' + this.options[this.selectedIndex].text;
            var username = <?php echo $this->jsLmsg('smb.components.forms.email-address.loginAsUserDescription')?>.replace('%%username%%', domainName);
            if (!document.getElementById('general-generalSection-name').value) {
                username = '';
            }
            document.getElementById('<?php echo $element->getId() ?>').parentNode.querySelector('.hint-inline').innerHTML = username;
        });
        <?php endif; ?>
    //]]>
</script>
<?php endif; ?>
<?php endif; ?>
