<!-- File contain displaying withdraw options section of setting tab -->
<?php
 if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}   
    // initializing custom data, if no data found from db

    $rtwmer_withdraw_bank  = 1;
    $rtwmer_minimum_withdraw  = 0;
    $rtwmer_withdraw_to_vendor = 'rtwmer_after_admin_approval';

    // Getting data from database

    if(current_user_can('manage_options'))
    {
        if( !empty(get_option('rtwmer_withdraw_option')))
        {
            $rtwmer_withdraw_option_data = get_option('rtwmer_withdraw_option');
            
            if(is_array($rtwmer_withdraw_option_data) && !empty($rtwmer_withdraw_option_data) )
            {
                if(isset($rtwmer_withdraw_option_data['rtwmer_withdraw_paypal']))
                {
                    $rtwmer_withdraw_paypal  = $rtwmer_withdraw_option_data['rtwmer_withdraw_paypal'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_withdraw_bank']) )
                {
                    $rtwmer_withdraw_bank  = $rtwmer_withdraw_option_data['rtwmer_withdraw_bank'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_withdraw_stripe']) )
                {
                    $rtwmer_withdraw_stripe  = $rtwmer_withdraw_option_data['rtwmer_withdraw_stripe'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_minimum_withdraw']) )
                {
                    $rtwmer_minimum_withdraw  = $rtwmer_withdraw_option_data['rtwmer_minimum_withdraw'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_withdraw_to_vendor']) )
                {
                    $rtwmer_withdraw_to_vendor  = $rtwmer_withdraw_option_data['rtwmer_withdraw_to_vendor'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_withdraw_paypal_test_box']) )
                {
                    $rtwmer_withdraw_paypal_test_box  = $rtwmer_withdraw_option_data['rtwmer_withdraw_paypal_test_box'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_paypal_client_id']) )
                {
                    $rtwmer_paypal_client_id  = $rtwmer_withdraw_option_data['rtwmer_paypal_client_id'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_paypal_secret_key']) )
                {
                    $rtwmer_paypal_secret_key  = $rtwmer_withdraw_option_data['rtwmer_paypal_secret_key'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_withdraw_stripe_test_box']) )
                {
                    $rtwmer_withdraw_stripe_test_box  = $rtwmer_withdraw_option_data['rtwmer_withdraw_stripe_test_box'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_stripe_client_id']) )
                {
                    $rtwmer_stripe_client_id  = $rtwmer_withdraw_option_data['rtwmer_stripe_client_id'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_stripe_secret_key']) )
                {
                    $rtwmer_stripe_secret_key  = $rtwmer_withdraw_option_data['rtwmer_stripe_secret_key'];
                }
                if( isset($rtwmer_withdraw_option_data['rtwmer_stripe_publishable_key']) )
                {
                    $rtwmer_stripe_publishable_key  = $rtwmer_withdraw_option_data['rtwmer_stripe_publishable_key'];
                }
            }
        }
    }
?> 
    <div class = "rtwmer-section-content rtwmer_card rtwmer_wrapper_div" id = "rtwmer-withdraw-options">
        <h3 class = "rtwmer-setting-heading rtwmer_withdraw_option_setting_updated"><?php esc_html_e('Withdraw Options','mercado'); ?></h3>

        <form class = "rtwmer-subsetting-content" method = "post" action = "">
            <ul>
                <?php 
                    $rtwmer_withdraw_option_array = array(
                    "<li><label> ".esc_html__('Minimum Withdraw Limit','mercado')." </label>
                        <span>
                            <label class='mdc-text-field mdc-text-field--outlined rtwmer-w-50'>
                                <input type='text' class='mdc-text-field__input rtwmer_textbox_width rtwmer_withdraw_option_page_data' id='rtwmer_minimum_withdraw' name='rtwmer_minimum_withdraw' value = ".(isset($rtwmer_minimum_withdraw) ? ($rtwmer_minimum_withdraw) : "" ).">
                                <div class='mdc-notched-outline mdc-notched-outline--upgraded'>
                                    <div class='mdc-notched-outline__leading'></div>
                                        <div class='mdc-notched-outline__notch' >
                                            <span class='mdc-floating-label' >".esc_html__('Minimum Withdraw Limit','mercado')."</span>
                                        </div>
                                    <div class=' mdc-notched-outline__trailing'></div>
                                </div>
                            </label>
                            <p class = 'rtwer-notice'> ".esc_html__('Minimum balance required to make a withdraw request. Leave blank to set no minimum limits.','mercado')." </p>
                        </span>
                    </li>",
                    "<li><label> ".esc_html__( "Amount add to vendor's Account",'mercado' )." </label>
                        <span>
                            <div class='rtwmer_select_box'>
                                <select id = 'rtwmer_withdraw_to_vendor' class = 'rtwmer-select-text rtwmer_withdraw_option_page_data rtwmer_select_textbox_width'>
                                    <option value = ' '> ".esc_html__('Select Option','mercado')." </option>
                                    <option value = 'rtwmer_after_admin_approval' ".(isset( $rtwmer_withdraw_to_vendor ) ? ( ($rtwmer_withdraw_to_vendor == 'rtwmer_after_admin_approval') ? "selected" : "" ) : "")." > ".esc_html__('After Admin Approval','mercado')." </option>
                                    <option value='rtwmer_order_completed' ".(isset( $rtwmer_withdraw_to_vendor ) ? ( ($rtwmer_withdraw_to_vendor == 'rtwmer_order_completed') ? "selected" : "" ) : "")."> ".esc_html__('On Order Completed','mercado')." </option>
                                    <option value='rtwmer_order_processing' ".(isset( $rtwmer_withdraw_to_vendor ) ? ( ($rtwmer_withdraw_to_vendor == 'rtwmer_order_processing') ? "selected" : "" ) : "")."> ".esc_html__('On Order Processing','mercado')."</option>
                                </select>
                                <label class='rtwmer_select_label'>".esc_html__( 'Add Amount','mercado' )."</label>
                            </div>
                            <p class = 'rtwer-notice'> ".esc_html__('When vendor receive Balance? , Default set to after admin Approval','mercado')." </p>
                        </span>
                    </li>"
                    );
                    
                    $rtwmer_withdraw_option_array = apply_filters('rtwmer_withdraw_option_meta_data',$rtwmer_withdraw_option_array);

                    if( isset($rtwmer_withdraw_option_array) && is_array($rtwmer_withdraw_option_array) )
                    {
                        foreach($rtwmer_withdraw_option_array as $rtwmer_vendor => $rtwmer_value)
                        {
                            // $rtwmer_value conntains html==//
                            $rtwmer_allowed_html = array(
                                'div' => array(
                                    'class' => true,
                                    'id'    => true,
                                ),

                                'span' => array(
                                    'class' => true,
                                    'id'    => true,
                                ),

                                'label' => array(
                                    'class' => true,
                                    'for'   => true,
                                ),

                                'input' => array(
                                    'type'    => true,
                                    'id'      => true,
                                    'name'    => true,
                                    'class'   => true,
                                    'value'   => true,
                                    'checked' => true,
                                    'selected'=> true,
                                ),

                                'select' => array(
                                    'id'    => true,
                                    'name'  => true,
                                    'class' => true,
                                ),

                                'option' => array(
                                    'value'    => true,
                                    'selected' => true,
                                ),

                                'textarea' => array(
                                    'id'          => true,
                                    'name'        => true,
                                    'class'       => true,
                                    'aria-label'  => true,
                                    'rows'        => true,
                                    'cols'        => true,
                                ),

                                'button' => array(
                                    'id'    => true,
                                    'class' => true,
                                    'type'  => true,
                                ),

                                'p' => array(
                                    'class' => true,
                                ),

                                'ul' => array(
                                    'class' => true,
                                ),

                                'li' => array(
                                    'class' => true,
                                ),

                                'h3' => array(
                                    'class' => true,
                                ),

                                'h5' => array(
                                    'class' => true,
                                ),

                                'a' => array(
                                    'href'   => true,
                                    'target' => true,
                                    'class'  => true,
                                    'rel'    => true,
                                ),

                                /* SVG SUPPORT (Material Design Icons) */
                                'svg' => array(
                                    'class'   => true,
                                    'viewBox' => true,
                                    'xmlns'   => true,
                                ),

                                'path' => array(
                                    'd'    => true,
                                    'fill' => true,
                                ),
                            );


                            echo wp_kses( $rtwmer_value, $rtwmer_allowed_html );
                        }
                    }
                ?>

            <p class="button-wrapper"><input type = "submit" name = "submit" id = "rtwmer-withdraw-option-submit" class = "mdc-button mdc-button--raised mdc-ripple-upgraded rtwmer-button" value = "<?php esc_html_e('Save Changes','mercado') ?>"><span><a href="<?php echo isset($rtwmer_mercado_url) ? esc_url($rtwmer_mercado_url) : ""; ?>" class = "mdc-button mdc-button--outlined mdc-ripple-upgraded rtwmer_store_setup_skip_btn"><?php esc_html_e('Skip For Now','mercado'); ?></a></span></p>
            
            </ul>
        </form> 
        <?php do_action('rtwmer_mercado_withdraw_option_page'); ?>
    </div>