<?php if( ! defined( "ABSPATH" ) ) return ?>
<script type="text/javascript">
var _wpadverts_stripe_cc_nonce = '<?php echo wp_create_nonce( 'wpadverts-stripe-cc-nonce' ) ?>';   
</script>
<div class="wpadverts-credit-card-wrap">
    <?php if( get_current_user_id() > 0 && ! empty( $cards->data ) ): ?>
    
        <div class="wpadverts-credit-card-list">
            <?php foreach( $cards->data as $card ): ?>
            <div class="wpadverts-credit-card-single <?php if($card->id==$stripe_default_card): ?>wpadverts-card-is-default<?php endif; ?>">
                <input type="radio" name="_stripe_card" value="<?php echo esc_attr($card->id) ?>" <?php checked( $card->id, $stripe_default_card ) ?> />

                <span class="<?php echo $icons[$card->card->brand] ?> wpadverts-stripe-cc-icon"></span>

                <span class="wpadverts-stripe-cc-details">
                    <span class="wpadverts-stripe-cc-brand"><?php echo $card->card->brand ?></span>
                    <span class="wpadverts-stripe-cc-last4">(<?php echo str_repeat( "*", 4 ) . $card->card->last4 ?>)</span>
                    <span class="wpadverts-stripe-cc-exp"><?php echo str_pad($card->card->exp_month, 2, "0", STR_PAD_LEFT ) . '/' . substr( $card->card->exp_year, 2) ?></span>
                </span>

                <span class="wpadverts-stripe-cc-actions">
                    <a href="#" class="wpadverts-stripe-cc-actions-default" title="<?php echo esc_attr_e( "Make Default", "wpadverts-stripe" ) ?>"><span class="adverts-icon-check"></span></a>
                    <a href="#" class="wpadverts-stripe-cc-actions-trash" title="<?php echo esc_attr_e( "Delete This Credit Card", "wpadverts-stripe") ?>"><span class="adverts-icon-trash"></span></a>
                </span>

                <span class="wpadverts-stripe-cc-actions-trash-confirm">
                    <?php _e( "Delete?", "wpadverts-stripe") ?>
                    <a href="#" class="wpadverts-stripe-cc-actions-trash-confirm-yes"><?php _e( "Yes", "wpadverts-stripe" ) ?></a>
                    <a href="#" class="wpadverts-stripe-cc-actions-trash-confirm-no"><?php _e( "No", "wpadverts-stripe" ) ?></a>

                </span>

                <span class="wpadverts-stripe-cc-actions-loader adverts-icon-spinner animate-spin"></span>
            </div>
            <?php endforeach; ?>
        </div>
    
        <a href="#" class="wpadverts-add-credit-card"><?php _e( "+ Use Different Credit Card", "wpadverts-stripe") ?></a>

        <div class="wpadverts-card-details" style="display: none">
            <div id="<?php echo esc_attr($field['name']) ?>" data-secret="<?php echo esc_attr( $intent->client_secret ) ?>">    

            </div>
        
            <label for="_stripe_save_card" style="margin:0">
                <input type="checkbox" name="_stripe_save_card" id="_stripe_save_card" value="1" /> 
                <?php _e( "Save card for later use", "wpadverts-stripe" ) ?>
            </label>
            
            <a href="#" class="wpadverts-add-credit-card-cancel"><?php _e( "Cancel", "wpadverts-stripe" ) ?></a>
        </div>

        <div id="card-errors" class="wpadverts-card-errors">

        </div>
        
    <?php else: ?>
        
        <div class="wpadverts-card-details">
            <div id="<?php echo esc_attr($field['name']) ?>" data-secret="<?php echo esc_attr( $intent->client_secret ) ?>">    

            </div>
        
            <?php if(get_current_user_id() > 0): ?>
            <label for="_stripe_save_card" style="margin:0">
                <input type="checkbox" name="_stripe_save_card" id="_stripe_save_card" value="1" /> 
                <?php _e( "Save card for later use", "wpadverts-stripe" ) ?>
            </label>
            <?php endif; ?>
            
            <div id="card-errors" class="wpadverts-card-errors"></div>
        </div>

    <?php endif; ?>
    
</div>
