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

// @codingStandardsIgnoreFile

/** @var \Magento\Paypal\Block\Adminhtml\Payflowpro\CcForm $block */
$code = $block->escapeHtml($block->getMethodCode());
$ccType = $block->getInfoData('cc_type');
$ccExpYear = $block->getInfoData('cc_exp_year');
$ccExpMonth = $block->getInfoData('cc_exp_month');
?>

<!-- IFRAME for request to Payment Gateway -->
<iframe id="<?= /* @noEscape */ $code ?>-transparent-iframe"
        data-container="<?= /* @noEscape */ $code ?>-transparent-iframe"
        allowtransparency="true"
        frameborder="0"
        name="iframeTransparent"
        style="display: none; width: 100%; background-color: transparent;"
        src="<?= $block->escapeUrl($block->getViewFileUrl('blank.html')) ?>"></iframe>
<fieldset
    id="payment_form_<?= /* @noEscape */ $code ?>"
    class="admin__fieldset"
    data-mage-init='{
     "transparent":{
        "controller":"<?= $block->escapeHtml($block->getRequest()->getControllerName()) ?>",
        "gateway":"<?= /* @noEscape */ $code ?>",
        "dateDelim":"<?= $block->escapeHtml($block->getDateDelim()) ?>",
        "cardFieldsMap":<?= $block->escapeHtml($block->getCardFieldsMap()) ?>,
        "orderSaveUrl":"<?= $block->escapeUrl($block->getOrderUrl()) ?>",
        "cgiUrl":"<?= $block->escapeUrl($block->getCgiUrl()) ?>",
        "expireYearLength":"<?= $block->escapeHtml($block->getMethodConfigData('cc_year_length')) ?>",
        "nativeAction":"<?= $block->escapeUrl($block->getUrl('*/*/save', ['_secure' => $block->getRequest()->isSecure()])) ?>"
      }, "validation":[]}'
    style="display: none;">
    <div class="admin__field _required">
        <label for="<?= /* @noEscape */ $code ?>_cc_type" class="admin__field-label">
            <span><?= $block->escapeHtml(__('Credit Card Type')) ?></span>
        </label>

        <div class="admin__field-control">
            <select id="<?= /* @noEscape */ $code ?>_cc_type"
                    data-container="<?= /* @noEscape */ $code ?>-cc-type"
                    name="payment[cc_type]"
                    data-validate='{required:true, "validate-cc-type-select":"#<?= /* @noEscape */ $code ?>_cc_number"}'
                    class="admin__control-select">
                <option value=""><?= $block->escapeHtml(__('Please Select')) ?></option>
                <?php foreach ($block->getCcAvailableTypes() as $typeCode => $typeName): ?>
                    <option
                        value="<?= $block->escapeHtml($typeCode) ?>"<?php if ($typeCode == $ccType): ?> selected="selected"<?php endif ?>>
                        <?= $block->escapeHtml($typeName) ?>
                    </option>
                <?php endforeach ?>
            </select>
        </div>
    </div>

    <div class="admin__field _required field-number">
        <label for="<?= /* @noEscape */ $code ?>_cc_number" class="admin__field-label">
            <span><?= $block->escapeHtml(__('Credit Card Number')) ?></span>
        </label>

        <div class="admin__field-control">
            <input type="text" id="<?= /* @noEscape */ $code ?>_cc_number"
                   data-container="<?= /* @noEscape */ $code ?>-cc-number"
                   name="payment[cc_number]" title="<?= $block->escapeHtml(__('Credit Card Number')) ?>"
                   class="admin__control-text"
                   value=""
                   data-validate='{
                       "required-number":true,
                       "validate-cc-number":"#<?= /* @noEscape */ $code ?>_cc_type",
                       "validate-cc-type":"#<?= /* @noEscape */ $code ?>_cc_type"
                   }'
                   autocomplete="off"/>
        </div>
    </div>

    <div class="admin__field _required field-date" id="<?= /* @noEscape */ $code ?>_cc_type_exp_div">
        <label for="<?= /* @noEscape */ $code ?>_expiration" class="admin__field-label">
            <span><?= $block->escapeHtml(__('Expiration Date')) ?></span>
        </label>

        <div class="admin__field-control">
            <select id="<?= /* @noEscape */ $code ?>_expiration" name="payment[cc_exp_month]"
                    data-container="<?= /* @noEscape */ $code ?>-cc-month"
                    class="admin__control-select admin__control-select-month"
                    data-validate='{required:true, "validate-cc-exp":"#<?= /* @noEscape */ $code ?>_expiration_yr"}'>
                <?php foreach ($block->getCcMonths() as $k => $v): ?>
                    <option
                        value="<?= /* @noEscape */ $k ? $block->escapeHtml($k) : '' ?>"
                        <?php if ($k == $ccExpMonth): ?> selected="selected"<?php endif; ?>>
                        <?= $block->escapeHtml($v) ?>
                    </option>
                <?php endforeach ?>
            </select>

            <select id="<?= /* @noEscape */ $code ?>_expiration_yr" name="payment[cc_exp_year]"
                    class="admin__control-select admin__control-select-year"
                    data-container="<?= /* @noEscape */ $code ?>-cc-year" data-validate='{required:true}'>
                <?php foreach ($block->getCcYears() as $k => $v): ?>
                    <option
                        value="<?= /* @noEscape */ $k ? $block->escapeHtml($k) : '' ?>"
                        <?php if ($k == $ccExpYear): ?> selected="selected"<?php endif ?>>
                        <?= $block->escapeHtml($v) ?>
                    </option>
                <?php endforeach ?>
            </select>
        </div>
    </div>
    <?php if ($block->hasVerification()): ?>
        <div class="admin__field _required field-cvv" id="<?= /* @noEscape */ $code ?>_cc_type_cvv_div">
            <label for="<?= /* @noEscape */ $code ?>_cc_cid" class="admin__field-label">
                <span><?= $block->escapeHtml(__('Card Verification Number')) ?></span>
            </label>

            <div class="admin__field-control">
                <input type="text" title="<?= $block->escapeHtml(__('Card Verification Number')) ?>"
                       data-container="<?= /* @noEscape */ $code ?>-cc-cvv"
                       class="admin__control-text cvv"
                       id="<?= /* @noEscape */ $code ?>_cc_cid" name="payment[cc_cid]"
                       value=""
                       data-validate='{"required-number":true, "validate-cc-cvn":"#<?= /* @noEscape */ $code ?>_cc_type"}'
                       autocomplete="off"/>
            </div>
        </div>
    <?php endif; ?>

    <?php if($block->isVaultEnabled()): ?>
        <div class="admin__field admin__field-option field-tooltip-content">
            <input type="checkbox"
                   id="<?= /* @noEscape */ $code ?>_vault"
                   name="payment[is_active_payment_token_enabler]"
                   class="admin__control-checkbox"/>
            <label class="admin__field-label" for="<?= /* @noEscape */ $code ?>_vault">
                <span><?= $block->escapeHtml(__('Save for later use.')) ?></span>
            </label>
        </div>
    <?php endif; ?>
    <input type="hidden" id="<?= /* @noEscape */ $code ?>_cc_last_4"
           name="payment[cc_last_4]"/>

    <?= $block->getChildHtml() ?>
</fieldset>

<script>
    /**
     * Disable card server validation in admin
     */
    require(["Magento_Sales/order/create/form"], function () {
        order.addExcludedPaymentMethod('<?= /* @noEscape */ $code ?>');
    });
</script>
