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

?>
<?php if ($block->hasMethods()) : ?>
<div id="order-billing_method_form">
    <dl class="admin__payment-methods">
    <?php
        $_methods = $block->getMethods();
        $_methodsCount = count($_methods);
        $_counter = 0;
        $currentSelectedMethod = $block->getSelectedMethodCode();
    ?>
    <?php foreach ($_methods as $_method) :
        $_code = $_method->getCode();
        $_counter++;
        ?>
        <dt class="admin__field-option">
        <?php if ($_methodsCount > 1) : ?>
            <input id="p_method_<?= $block->escapeHtml($_code); ?>"
                   value="<?= $block->escapeHtml($_code); ?>"
                   type="radio" name="payment[method]"
                   title="<?= $block->escapeHtml($_method->getTitle()); ?>"
                   onclick="payment.switchMethod('<?= $block->escapeHtml($_code); ?>')"
                    <?php if ($currentSelectedMethod == $_code) : ?>
                    checked="checked"
                    <?php endif; ?>
                    <?php $className = ($_counter == $_methodsCount) ? ' validate-one-required-by-name' : ''; ?>
                   class="admin__control-radio<?= $block->escapeHtml($className); ?>"/>
        <?php else :?>
            <span class="no-display">
                <input id="p_method_<?= $block->escapeHtml($_code); ?>"
                       value="<?= $block->escapeHtml($_code); ?>"
                       type="radio"
                       name="payment[method]" class="admin__control-radio"
                       checked="checked"/>
            </span>
        <?php endif;?>

            <label class="admin__field-label" for="p_method_<?= $block->escapeHtml($_code); ?>">
                <?= $block->escapeHtml($_method->getTitle()) ?>
            </label>
        </dt>
        <dd class="admin__payment-method-wrapper">
            <?= /* @noEscape */ $block->getChildHtml('payment.method.' . $_code) ?>
        </dd>
    <?php endforeach; ?>
    </dl>
</div>
    <script>
        require([
            'mage/apply/main',
            'Magento_Sales/order/create/form'
        ], function(mage) {
            mage.apply();
        <?php if ($_methodsCount !== 1) : ?>
            order.setPaymentMethod('<?= $block->escapeHtml($currentSelectedMethod); ?>');
        <?php else : ?>
            payment.switchMethod('<?= $block->escapeHtml($currentSelectedMethod); ?>');
        <?php endif; ?>
        });
    </script>
<?php else : ?>
    <div class="admin__message-empty"><?= $block->escapeHtml(__('No Payment Methods')); ?></div>
<?php endif; ?>
