<?php
/**
 * Authorize.net My Account Edit eCheck Template
 *
 * @package Authorize_Net_Payments_For_Woocommerce
 *
 * @var array $profile
 * @var int $user_id
 * @var int $payment_profile_id
 * @var int $customer_profile_id
 */

if (! defined('ABSPATH')) {
    exit;
}

// Enqueue the CSS file that contains our styles.
wp_enqueue_style('anet-echeck-css', plugin_dir_url(__FILE__) . '../../assets/css/anet-echeck-normal-checkout.css', array(), ANET_PLUGIN_VERSION);
wc_print_notices();
?>
<div id="anet-echeck-edit-form" class="woocommerce">
    <h2><?php esc_html_e('Update eCheck Details', 'authorize-net-payments-for-woocommerce'); ?></h2>
    <form method="post" class="woocommerce-form woocommerce-form-login login">
        <div id="anet-echeck-edit-error" style="color:#b32d2e; margin-bottom:12px; display:none;"></div>
        <div class="echeck-row">
            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="anet-echeck-edit-account-number"><?php esc_html_e('Account Number', 'authorize-net-payments-for-woocommerce'); ?></label>
                <input type="text" id="anet-echeck-edit-account-number" class="woocommerce-Input woocommerce-Input--text input-text" name="account_number" maxlength="10" placeholder="Enter Account Number" autocomplete="off" required
                    value="<?php echo esc_attr($profile['account_number'] ?? ''); ?>" />
            </p>
            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="anet-echeck-edit-routing-number"><?php esc_html_e('Routing Number', 'authorize-net-payments-for-woocommerce'); ?></label>
                <input type="text" id="anet-echeck-edit-routing-number" class="woocommerce-Input woocommerce-Input--text input-text" name="routing_number" maxlength="10" placeholder="Enter Routing Number" autocomplete="off" required
                    value="<?php echo esc_attr($profile['routing_number'] ?? ''); ?>" />
            </p>
        </div>
        <div class="echeck-row">
            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="anet-echeck-edit-name-on-account"><?php esc_html_e('Name on Account', 'authorize-net-payments-for-woocommerce'); ?></label>
                <input type="text" id="anet-echeck-edit-name-on-account" class="woocommerce-Input woocommerce-Input--text input-text" name="name_on_account" minlength="4" maxlength="22" placeholder="Enter Name on Account" autocomplete="off" required
                    value="<?php echo esc_attr($profile['name_on_account'] ?? ''); ?>" />
            </p>
            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="anet-echeck-edit-account-type"><?php esc_html_e('Account Type', 'authorize-net-payments-for-woocommerce'); ?></label>
                <select id="anet-echeck-edit-account-type" class="woocommerce-Input woocommerce-Input--text input-text" style="height: 50px;" name="account_type" required>
                    <option value="" disabled <?php echo empty($profile['account_type']) ? 'selected' : ''; ?>>
                        <?php esc_html_e('Select Account Type', 'authorize-net-payments-for-woocommerce'); ?>
                    </option>
                    <option value="checking" <?php echo (!empty($profile['account_type']) && 'checking' === $profile['account_type']) ? 'selected' : ''; ?>>
                        <?php esc_html_e('Checking', 'authorize-net-payments-for-woocommerce'); ?>
                    </option>
                    <option value="savings" <?php echo (!empty($profile['account_type']) && 'savings' === $profile['account_type']) ? 'selected' : ''; ?>>
                        <?php esc_html_e('Savings', 'authorize-net-payments-for-woocommerce'); ?>
                    </option>
                </select>
            </p>
            <input type="hidden" name="anet_echeck_edit_nonce" value="<?php echo esc_attr(wp_create_nonce('anet_echeck_edit_nonce')); ?>" />
        </div>
        <p class="form-row">
            <button style="margin: 1em;" id="anet-echeck-save-btn" type="submit" class="woocommerce-button button wp-element-button" name="save_echeck"><?php esc_html_e('Save', 'authorize-net-payments-for-woocommerce'); ?></button>
            <a href="<?php echo esc_url(wc_get_account_endpoint_url(ANET_PAYMENT_METHODS)); ?>" id="anet-echeck-cancel-btn" class="woocommerce-button button wp-element-button"><?php esc_html_e('Cancel', 'authorize-net-payments-for-woocommerce'); ?></a>
        </p>
    </form>
</div>