<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */

$type = $element->getType();
$htmlId = $element->getHtmlId();
?>
<?php if ($type === 'fieldset'): ?>
    <fieldset>
        <legend><?= $block->escapeHtml($element->getLegend()) ?></legend><br />
        <?php foreach ($element->getElements() as $_element): ?>
            <?= /* @noEscape */ $formBlock->drawElement($_element) ?>
        <?php endforeach; ?>
    </fieldset>
<?php elseif ($type === 'hidden'): ?>
    <input type="<?= $block->escapeHtmlAttr($element->getType()) ?>"
           name="<?= $block->escapeHtmlAttr($element->getName()) ?>"
           id="<?= /* @noEscape */ $htmlId ?>"
           value="<?= $block->escapeHtmlAttr($element->getValue()) ?>">
    <?php elseif ($type === 'select'): ?>
    <span class="form_row">
        <?php if ($element->getLabel()): ?>
            <label for="<?= /* @noEscape */ $htmlId ?>"><?= $block->escapeHtml($element->getLabel()) ?>:</label>
        <?php endif; ?>
        <select name="<?= $block->escapeHtmlAttr($element->getName()) ?>"
                id="<?= /* @noEscape */ $htmlId ?>"
                class="select<?= $block->escapeHtmlAttr($element->getClass()) ?>"
                title="<?=  $block->escapeHtmlAttr($element->getTitle()) ?>">
        <?php foreach ($element->getValues() as $_value): ?>
            <option <?= /* @noEscape */ $_value->serialize() ?>
                <?php if ($_value->getValue() == $element->getValue()): ?> selected="selected"<?php endif; ?>>
                <?= $block->escapeHtml($_value->getLabel()) ?>
            </option>
        <?php endforeach; ?>
        </select>
    </span>
<?php elseif ($type === 'text' || $type === 'button' || $type === 'password'): ?>
    <span class="form_row">
        <?php if ($element->getLabel()): ?>
            <label for="<?= /* @noEscape */ $htmlId ?>" <?= /* @noEscape */ $block->getUiId('label') ?>>
                <?= $block->escapeHtml($element->getLabel()) ?>:
            </label>
        <?php endif; ?>
        <input type="<?= $block->escapeHtmlAttr($element->getType()) ?>"
               name="<?= $block->escapeHtmlAttr($element->getName()) ?>"
               id="<?= /* @noEscape */ $htmlId ?>"
               value="<?= $block->escapeHtmlAttr($element->getValue()) ?>"
               class="input-text <?= $block->escapeHtmlAttr($element->getClass()) ?>"
               title="<?= $block->escapeHtmlAttr($element->getTitle()) ?>" />
        <?php if ($listener = $element->getOnclick()): ?>
            <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag('onclick', $listener, "#{$htmlId}")  ?>
        <?php endif; ?>
    </span>
<?php elseif ($type === 'radio'): ?>
    <span class="form_row">
        <?php if ($element->getLabel()): ?>
            <label for="<?= /* @noEscape */ $htmlId ?>"><?= $block->escapeHtml($element->getLabel()) ?>:</label>
        <?php endif; ?>
        <input type="<?=  $block->escapeHtmlAttr($element->getType()) ?>"
               name="<?=  $block->escapeHtmlAttr($element->getName()) ?>"
               id="<?= /* @noEscape */ $htmlId ?>"
               value="<?=  $block->escapeHtmlAttr($element->getValue()) ?>"
               class="input-text <?= $block->escapeHtmlAttr($element->getClass()) ?>"
               title="<?=  $block->escapeHtmlAttr($element->getTitle()) ?>"/>
    </span>
<?php elseif ($type === 'radios'): ?>
    <span class="form_row">
        <label for="<?= /* @noEscape */ $htmlId ?>"><?= $block->escapeHtml($element->getLabel()) ?>:</label>
    <?php foreach ($element->getRadios() as $_radio): ?>
    <input type="radio"
           name="<?=  $block->escapeHtmlAttr($_radio->getName()) ?>"
           id="<?= $_radio->getHtmlId() ?>"
           value="<?=  $block->escapeHtmlAttr($_radio->getValue()) ?>"
           class="input-radio <?= $block->escapeHtmlAttr($_radio->getClass()) ?>"
           title="<?=  $block->escapeHtmlAttr($_radio->getTitle()) ?>"
           <?= ($_radio->getValue() == $element->getChecked()) ? 'checked="true"' : '' ?> >
        <?= $block->escapeHtml($_radio->getLabel()) ?>
    <?php endforeach; ?>
    </span>
<?php elseif ($type === 'wysiwyg'): ?>
    <span class="form_row">
      <label for="<?= /* @noEscape */ $htmlId ?>"><?= $block->escapeHtml($element->getLabel()) ?>:</label>
        <?php $scriptString = <<<script
        require([
            "wysiwygAdapter"
        ], function(tinyMCE){

            tinyMCE.init({
                mode : "exact",
                theme : "advanced",
                elements : "{$block->escapeJs($element->getName())}",
                plugins : "inlinepopups,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,"
                    + "insertdatetime,preview,zoom,media,searchreplace,print,contextmenu,paste,directionality,"
                    + "fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
                theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|"
                    + ",justifyleft,justifycenter,justifyright,justifyfull,|"
                    + ",styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|"
                    + ",outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|"
                    + ",insertdate,inserttime,preview,|,forecolor,backcolor",
                theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|"
                    + ",charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|"
                    + ",cite,abbr,acronym,del,ins,|,visualchars,nonbreaking",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_path_location : "bottom",
                extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace"
                    + "|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size"
                    + "|noshade],font[face|size|color|style],span[class|align|style]",
                theme_advanced_resize_horizontal : 'false',
                theme_advanced_resizing : 'true',
                apply_source_formatting : 'true',
                convert_urls : 'false',
                force_br_newlines : 'true',
                doctype : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
                    + ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
            });
        });
script;
        ?>
        <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
      <textarea name="<?= $block->escapeHtmlAttr($element->getName()) ?>"
                title="<?=  $block->escapeHtmlAttr($element->getTitle()) ?>"
                id="<?= /* @noEscape */ $htmlId ?>"
                class="textarea <?= $block->escapeHtmlAttr($element->getClass()) ?>"
                cols="80" rows="20">
          <?= $block->escapeHtml($element->getValue()) ?>
      </textarea>
    </span>
<?php elseif ($type === 'textarea'): ?>
            <span class="form_row">
                    <label for="<?= /* @noEscape */ $htmlId ?>"><?= $block->escapeHtml($element->getLabel()) ?>:</label>
                    <textarea name="<?= $block->escapeHtmlAttr($element->getName()) ?>"
                              title="<?=  $block->escapeHtmlAttr($element->getTitle()) ?>"
                              id="<?= /* @noEscape */ $htmlId ?>"
                              class="textarea <?= $block->escapeHtmlAttr($element->getClass()) ?>"
                              cols="15"
                              rows="2">
                        <?= $block->escapeHtml($element->getValue()) ?>
                    </textarea>
            </span>
<?php endif; ?>
<?php if ($element->getScript()): ?>
    <?php /* @noEscape */ $secureRenderer->renderTag('script', [], $element->getScript(), false) ?>
<?php endif; ?>
