<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
/** @var $block \Magento\Catalog\Block\Adminhtml\Form\Renderer\Fieldset\Element */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<?php
/* @var $block \Magento\Backend\Block\Widget\Form\Renderer\Fieldset\Element */
$element = $block->getElement();
$note = $element->getNote() ?
    '<div class="note admin__field-note">' . $block->escapeHtml($element->getNote()) . '</div>' : '';
$elementBeforeLabel = $element->getExtType() == 'checkbox' || $element->getExtType() == 'radio';
$addOn = $element->getBeforeElementHtml() || $element->getAfterElementHtml();
$fieldId = ($element->getHtmlId()) ? ' id="attribute-' . $element->getHtmlId() . '-container"' : '';
$entity = $element->getEntityAttribute();
$fieldClass = "admin__field field field-{$element->getId()} {$element->getCssClass()}";
$fieldClass .= ($elementBeforeLabel) ? ' choice' : '';
$fieldClass .= ($addOn) ? ' with-addon' : '';
$fieldClass .= ($element->getRequired()) ? ' required' : '';
$fieldClass .= ($note) ? ' with-note' : '';
$fieldClass .= ($entity && $entity->getIsUserDefined()) ? ' user-defined type-' . $entity->getFrontendInput() : '';

$fieldAttributes = $fieldId . ' class="' . $block->escapeHtmlAttr($fieldClass) . '" '
    . $block->getUiId('form-field', $block->escapeHtmlAttr($element->getId()));

/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
$jsonHelper = $block->getData('jsonHelper');
?>

<?php $block->checkFieldDisable() ?>
<?php
    $elementToggleCode = $element->getToggleCode() ? $element->getToggleCode()
        : 'toggleValueElements(this, this.parentNode.parentNode.parentNode)';
?>
<?php if (!$element->getNoDisplay()):?>
    <?php if ($element->getType() == 'hidden'):?>
        <?= $element->getElementHtml() ?>
    <?php else:?>
    <div<?= /* @noEscape */ $fieldAttributes ?> data-attribute-code="<?= $element->getHtmlId() ?>"
        data-apply-to="<?= /* @noEscape */ $jsonHelper->jsonEncode($element->hasEntityAttribute() ?
            $element->getEntityAttribute()->getApplyTo() : []) ?>"
        >
        <?php if ($elementBeforeLabel):?>
            <?= $block->getElementHtml() ?>
            <?= $element->getLabelHtml('', $block->getScopeLabel()) ?>
            <?= /* @noEscape */ $note ?>
        <?php else:?>
            <?= $element->getLabelHtml('', $block->getScopeLabel()) ?>
            <div class="admin__field-control control">
                <?= ($addOn) ? '<div class="addon">' . $block->getElementHtml() . '</div>' : $block->getElementHtml() ?>
                <?= /* @noEscape */ $note ?>
            </div>
        <?php endif; ?>
        <div class="field-service">
            <?php if ($block->canDisplayUseDefault()):?>
                <label for="<?= $element->getHtmlId() ?>_default" class="choice use-default">
                    <input <?php if ($element->getReadonly()):?> disabled="disabled"<?php endif; ?>
                            type="checkbox"
                            name="use_default[]"
                            class="use-default-control"
                            id="<?= $element->getHtmlId() ?>_default"
                            <?php if ($block->usedDefault()):?> checked="checked"<?php endif; ?>
                            value="<?= $block->escapeHtmlAttr($block->getAttributeCode()) ?>"/>
                    <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
                        'onclick',
                        $elementToggleCode,
                        "#" . $element->getHtmlId() . "_default"
                    ) ?>
                    <span class="use-default-label"><?= $block->escapeHtml(__('Use Default Value')) ?></span>
                </label>
            <?php endif; ?>
        </div>
    </div>
    <?php endif; ?>
<?php endif; ?>
