<?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 control">
    <?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->escapeHtmlAttr($_code); ?>"
                   value="<?= $block->escapeHtmlAttr($_code); ?>"
                   type="radio" name="payment[method]"
                   title="<?= $block->escapeHtmlAttr($_method->getTitle()); ?>"
                   onclick="payment.switchMethod('<?= $block->escapeJs($_code); ?>')"
                    <?php if ($currentSelectedMethod == $_code) : ?>
                    checked="checked"
                    <?php endif; ?>
                   data-validate="{'validate-one-required-by-name':true}"
                   class="admin__control-radio"/>
        <?php else :?>
            <span class="no-display">
                <input id="p_method_<?= $block->escapeHtmlAttr($_code); ?>"
                       value="<?= $block->escapeHtmlAttr($_code); ?>"
                       type="radio"
                       name="payment[method]" class="admin__control-radio"
                       checked="checked"/>
            </span>
        <?php endif;?>

            <label class="admin__field-label" for="p_method_<?= $block->escapeHtmlAttr($_code); ?>">
                <?= $block->escapeHtml($_method->getTitle()) ?>
            </label>
        </dt>
        <dd class="admin__payment-method-wrapper">
            <?= $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->escapeJs($currentSelectedMethod); ?>');
        <?php else : ?>
            payment.switchMethod('<?= $block->escapeJs($currentSelectedMethod); ?>');
        <?php endif; ?>
        });
    </script>
<?php else : ?>
    <div class="admin__message-empty"><?= $block->escapeHtml(__('No Payment Methods')); ?></div>
<?php endif; ?>
