<!-- File contain displaying page settings section of setting tab -->

<?php 
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
    // Default Data if variables are not set.

    $rtwmer_page_setting_dashboard = 'not_selected';
    $rtwmer_page_setting_my_orders = 'not_selected';
    $rtwmer_page_terms_conditions = 'not_selected';
    $rtwmer_page_store_listing = 'not_selected';
   
    //Getting data from options table

    if( current_user_can('manage_options') )
    {
        if( !empty( get_option('rtwmer_page_setting' )) )
        {
            $rtwmer_page_setting_option = get_option('rtwmer_page_setting');
            
            if(is_array($rtwmer_page_setting_option) && !empty($rtwmer_page_setting_option) )
            {   
                if( isset($rtwmer_page_setting_option['rtwmer_page_setting_dashboard']) )
                {
                    $rtwmer_page_setting_dashboard = $rtwmer_page_setting_option['rtwmer_page_setting_dashboard'];
                }
                if( isset($rtwmer_page_setting_option['rtwmer_page_my_orders']) )
                {
                    $rtwmer_page_my_orders = $rtwmer_page_setting_option['rtwmer_page_my_orders'];
                }
                if( isset($rtwmer_page_setting_option['rtwmer_page_terms_conditions']) )
                {
                    $rtwmer_page_terms_conditions = $rtwmer_page_setting_option['rtwmer_page_terms_conditions'];   
                }
                if( isset($rtwmer_page_setting_option['rtwmer_page_store_listing']) )
                {
                    $rtwmer_page_store_listing = $rtwmer_page_setting_option['rtwmer_page_store_listing'];
                }
            }
        }
    }?>

    <div class = "rtwmer-section-content rtwmer_card rtwmer_wrapper_div" id = "rtwmer-page-setting">
        <h3 class = "rtwmer-setting-heading"><?php esc_html_e('Page Settings','mercado'); ?></h3>
        <div class = "rtwmer-subsetting-content">
        <ul>
            <li><label><?php esc_html_e('Dashboard','mercado'); ?></label><span>
                <?php
                if( isset( $rtwmer_page_setting_dashboard ) && !empty( $rtwmer_page_setting_dashboard ) )
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'name' => 'rtwmer_page_setting_dashboard',
                                'id' => 'rtwmer_page_setting_dashboard',
                                'class' => 'rtwmer-select-text',
                                'option_none_value' => 'not_selected',
                                'selected' => esc_html($rtwmer_page_setting_dashboard),
                                ));
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'Dashboard Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                else
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'name' => 'rtwmer_page_setting_dashboard',
                                'id' => 'rtwmer_page_setting_dashboard',
                                'class' => 'rtwmer-select-text',
                                'option_none_value' => 'not_selected',
                                ) );
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'Dashboard Page','mercado' ); ?></label>
                        </div>
                    <?php
                }    
                ?> 
                <p class="rtwer-notice"><?php esc_html_e('Select a page to show Vendor Dashboard','mercado'); ?><p></span>
            </li>

            <li><label><?php esc_html_e('My Orders','mercado'); ?></label><span>
                <?php 
                if(isset($rtwmer_page_my_orders) && !empty($rtwmer_page_my_orders))
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'option_none_value' => 'not_selected',
                                'name' => 'rtwmer_page_my_orders',
                                'class' => 'rtwmer-select-text',
                                'id' => 'rtwmer_page_my_orders',
                                'selected' => esc_html($rtwmer_page_my_orders),
                                ));
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'My Orders Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                else
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'option_none_value' => 'not_selected',
                                'name' => 'rtwmer_page_my_orders',
                                'class' => 'rtwmer-select-text',
                                'id' => 'rtwmer_page_my_orders',
                                ) );
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'My Orders Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                ?> 
                <p class="rtwer-notice"><?php esc_html_e('Select a page to show My Orders','mercado'); ?><p></span>
            </li>

            <li><label><?php esc_html_e('Store Listing','mercado'); ?></label><span>
                <?php 
                if(isset($rtwmer_page_store_listing) && !empty($rtwmer_page_store_listing))
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'option_none_value' => 'not_selected',
                                'name' => 'rtwmer_page_store_listing',
                                'class' => 'rtwmer-select-text',
                                'id' => 'rtwmer_page_store_listing',
                                'selected' => esc_html($rtwmer_page_store_listing),
                                ));
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'Store Listing Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                else
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'option_none_value' => 'not_selected',
                                'name' => 'rtwmer_page_store_listing',
                                'class' => 'rtwmer-select-text',
                                'id' => 'rtwmer_page_store_listing',
                                ) );
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'Store Listing Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                ?> 
                <p class="rtwer-notice"><?php esc_html_e('Select a page to show all Stores','mercado'); ?><p></span>
            </li>

            <li><label><?php esc_html_e('Terms and Conditions Page','mercado'); ?></label><span>
                <?php
                if(isset($rtwmer_page_my_orders) && !empty($rtwmer_page_my_orders))
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'option_none_value' => 'not_selected',
                                'name' => 'rtwmer_page_terms_conditions',
                                'class' => 'rtwmer-select-text',
                                'id' => 'rtwmer_page_terms_conditions',
                                'selected' => esc_html($rtwmer_page_terms_conditions),
                                ) );
                            ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'Terms & Conditions Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                else
                {
                    ?>
                        <div class='rtwmer_select_box'>
                            <?php
                                wp_dropdown_pages( array(
                                'show_option_none' => 'select page',
                                'option_none_value' => 'not_selected',
                                'name' => 'rtwmer_page_terms_conditions',
                                'class' => 'rtwmer-select-text',
                                'id' => 'rtwmer_page_terms_conditions',
                                ) );
                                ?>
                            <label class='rtwmer_select_label'><?php esc_html_e( 'Terms & Conditions Page','mercado' ); ?></label>
                        </div>
                    <?php
                }
                ?>
                <p class = "rtwer-notice"><?php esc_html_e( 'Select where you want to add Mercado pages','mercado' ); ?> <a href="<?php echo esc_attr( 'https://redefiningtheweb.com/' ); ?>"> <?php esc_html_e( 'Learn More','mercado' ); ?></a><p></span>
            </li>
            <?php
                $rtwmer_page_setting_array = array(
                    
                );
                $rtwmer_page_setting_array = apply_filters('rtwmer_page_setting_meta_data',$rtwmer_page_setting_array);
                if( isset($rtwmer_page_setting_array) && !empty($rtwmer_page_setting_array) && is_array($rtwmer_page_setting_array) )
                {
                    foreach($rtwmer_page_setting_array as $rtwmer_vendor => $rtwmer_value)
                    {
                        if( isset($rtwmer_value) && !empty($rtwmer_value) )
                        {
                            //$rtwmer_value holds 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 = "submit"><input type = "submit" name = "submit" id = "rtwmer-page-setting-submit" class = "mdc-button mdc-button--raised mdc-ripple-upgraded rtwmer-button" value = "<?php esc_html_e('Save Changes','mercado') ?>"></p>
        </ul>
        </div>
        <?php do_action('rtwmer_mercado_page_setting_page'); ?>
    </div>