<?php
if (!defined( 'ABSPATH' )) exit;
wp_register_style('select2.min.css', WOO2APP_CSS_URL . 'select2.min.css');
wp_enqueue_style('select2.min.css'.WOO2APP_FILES_VER);
wp_enqueue_script('select2.min.js'.WOO2APP_FILES_VER, WOO2APP_JS_URL . 'select2.min.js');

$current_url = admin_url().'admin.php?page=woo2app/woo2app_design/woo2app_show_design.php&tab=chideman&sub_page=create';
$results = get_option('mr2app_custom_product_list');
?>


<div class="div_mainpage1">
    <div>
        <div class="">
            <h2 class="background-color-e5e5e5 padding-7px">
				<?php _e('New Product List', 'woo2app'); ?>
            </h2>
            <table class="form-table width-600px">
                <tbody>
                <tr>
                    <th> <?php _e('Type' , 'woo2app');?> </th>
                    <td>
                        <select class="regular-text" id="select_item_option">
                            <option value="1001"> <?php _e('Vertical - Simple', 'woo2app'); ?> </option>
                            <option value="1002"> <?php _e('Horizontal - Simple', 'woo2app'); ?> </option>
                            <option value="1003"> <?php _e('Amazing list', 'woo2app'); ?> </option>
                            <option value="1004"> <?php _e('Horizontal with banner', 'woo2app'); ?> </option>
                            <option value="1005"> <?php _e('Vertical - 3 columns', 'woo2app'); ?> </option>
                            <option value="1006"> <?php _e('Horizontal - 3 rows', 'woo2app'); ?> </option>
                            <option value="1007"> <?php _e('Vertical - Left circle image', 'woo2app'); ?> </option>
                            <option value="1008"> <?php _e('Vertical - Left square image', 'woo2app'); ?> </option>
                            <option value="1009"> <?php _e('Vertical - Top circle image', 'woo2app'); ?> </option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th> <?php _e('Preview' , 'woo2app');?> </th>
                    <td>
                        <img class="img_product_list hide" id="demo_PList_1000"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_1.jpg'?>">
                        <img class="img_product_list" id="demo_PList_1001"       style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_1.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1002"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_2.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1003"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_3.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1004"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_4.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1005"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_5.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1006"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_6.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1007"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_7.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1008"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_8.jpg'?>">
                        <img class="img_product_list hide" id="demo_PList_1009"  style="height: 400px" src="<?= WOO2APP_URL .'/files/img/MainPageProduct/mp-prd_9.jpg'?>">
                    </td>
                </tr>
                <tr class="div_mainpage div_list_vertical">
                    <th> <?php _e('Title' , 'woo2app');?> </th>
                    <td>
                        <input placeholder="<?php _e('Title', 'woo2app'); ?>" type="text"
                               class="regular-text" name="txt_title_ver_item" id="txt_title_ver_item">
                    </td>
                </tr>
                <tr class="div_mainpage div_list_vertical">
                    <th> <?php _e('Product count' , 'woo2app');?>  </th>
                    <td>
                        <input placeholder="<?php _e('Product Count', 'woo2app'); ?>" type="number"
                               value="15" class="regular-text" name="txt_number_load_ver_item"
                               id="txt_number_load_ver_item">
                    </td>
                </tr>
                <tr class="div_mainpage div_list_vertical">
                    <th> <?php _e('Category/Tag' , 'woo2app');?> </th>
                    <td>
                        <select class="regular-text" id="cat_tag_ver" onchange="change_cat_tag(this)">
                            <option value="cat_ver"> <?php _e('Category', 'woo2app'); ?> </option>
                            <option value="tag_ver"> <?php _e('Tag', 'woo2app'); ?> </option>
                            <option value="custom_list"> <?php _e('Custom List', 'woo2app'); ?> </option>
                        </select>
                    </td>
                </tr>
                <tr class="div_mainpage div_list_vertical">
                    <th> <?php _e('Select' , 'woo2app'); ?> </th>
                    <td>
                        <div class="cat_tag_ver"  id="cat_list_ver">
                            <select name="cat" data-id="cat"
                                    data-placeholder="<?php _e('Please Select ...', 'woo2app'); ?>"
                                    id="value_cat_items_ver" class="regular-text js-data-example-ajax ">
                                <option class=""
                                        value="all"> <?php _e('All Categories', 'woo2app'); ?> </option>
                            </select>
                        </div>
                        <div class="cat_tag_ver hide"  id="tag_list_ver">
                            <select name="tags" data-id="tags"
                                    data-placeholder="<?php _e('Please Select ...', 'woo2app'); ?>" id="value_tag_items_ver"
                                    class="regular-text  js-data-example-ajax">

                            </select>
                        </div>
                        <div class="cat_tag_ver hide"  id="custom_list_ver">
                            <select id="value_custom_list" class="regular-text">
		                        <?php
		                        $results =  get_option('mr2app_custom_product_list');
		                        foreach ($results as $key) {
			                        ?>
                                    <option value='<?= json_encode($key['list_product']) ?>'> <?= $key['title']; ?></option>
			                        <?php
		                        }
		                        ?>
                            </select>
                            <a href="<?= $current_url . '&sub_page=product_list'?>" >
		                        <?php _e('Create Custom List', 'woo2app'); ?>
                            </a>
                        </div>
                    </td>
                </tr>
                <tr class="div_mainpage div_list_vertical">
                    <th> <?php _e('Sort' , 'woo2app');?>  </th>
                    <td>
                        <select  id="value_sort_ver" class="regular-text" >
                            <option value=""> <?php _e('Default', 'woo2app'); ?></option>
                            <option value="orderby=popularity&order=DESC"> <?php _e('Popularity', 'woo2app'); ?></option>
                            <option value="orderby=date&order=DESC"> <?php _e('Newest', 'woo2app'); ?> </option>
                            <option value="orderby=price&order=ASC"> <?php _e('Lowest Price', 'woo2app'); ?> </option>
                            <option value="orderby=price&order=DESC"> <?php _e('Highest Price', 'woo2app'); ?> </option>
                            <option value="orderby=selling&order=DESC"> <?php _e('Best Seller', 'woo2app'); ?> </option>
                        </select>
                    </td>
                </tr>
                <tr class="div_mainpage div_pishnehad_vizhe hide">
                    <th> <?php _e('Select List' , 'woo2app');?> </th>
                    <td>
                        <select id="value_pishnehad_vizhe" class="regular-text">
							<?php
							$results =  get_option('mr2app_custom_product_list');
							foreach ($results as $key) {
								?>
                                <option  value='<?= json_encode($key['list_product']) ?>'> <?= $key['title']; ?></option>
								<?php
							}
							?>
                        </select>
                        <a href="<?= $current_url . '&sub_page=product_list'?>" >
							<?php _e('Create Amazing List', 'woo2app'); ?>
                        </a>
                    </td>
                </tr>
                <tr class="div_mainpage div_pishnehad_vizhe hide">
                    <th> <?php _e('Expiration' , 'woo2app');?>   </th>
                    <td>
                        <input type="text" placeholder="<?php _e('Expiration Time', 'woo2app'); ?>"
                               class="regular-text"
                               id="value_pishnehad_vizhe_time"/>
                        <p><small> <?= _e('If you enter 12, it expires after 12 hours.' , 'woo2app');?></small></p>
                    </td>
                </tr>
                <tr class="div_mainpage div_list_vertical hide" id="tr_list_image"  >
                    <th>
                        <label dir="rtl"> <?php _e('Image', 'woo2app'); ?> </label>
                    </th>
                    <td class="forminp">
                        <input type="text" class="regular-text" id="ListImage" value="">
                        <button type="button"  class="button"
                                id="Sel_ListImage"> <?php _e('Select Image', 'woo2app'); ?> </button>

                                <p>
                        <hr>
                        <?php _e('Best scale', 'woo2app'); ?> : 2x1
                        <hr>
                        <?php _e('Recommended Resolution', 'woo2app'); ?> : 1000x500
                        <hr>
                        <?php _e('Max Size', 'woo2app'); ?> : 150KB
                        <hr>
                        <?php _e('Format', 'woo2app'); ?> : PNG - JPG - JPEG - GIF
                    </p>
                    </td>

                    
                </tr>
                <tr>
                    <th> <img id="img_load1" class="hide width-height-25px"
                              src="<?php echo WP_PLUGIN_URL . "/" . dirname(plugin_basename(__FILE__)) . '/../files/img/load.gif' ?>"> </th>
                    <td>
                        <button onclick="add_item_mainpage()" type="button"
                                class="button button-primary"> <?php _e('+ Add To Page', 'woo2app'); ?> </button>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="green hide"  id="alert_item">
                        </div>
                    </td>
                </tr>
                </tbody>

            </table>
        </div>
    </div>
</div>
<?php
wp_enqueue_script( 'loadajax.js'.WOO2APP_FILES_VER , WOO2APP_JS_URL.'loadAjaxPosts.js', array('jquery'));
wp_enqueue_script( 'sort.js'.WOO2APP_FILES_VER , WOO2APP_JS_URL.'sort.js?ver=1.1', array('jquery'));
wp_enqueue_media();
wp_enqueue_script( 'upload_item_banner.js'.WOO2APP_FILES_VER , WOO2APP_JS_URL.'upload_item_banner.js', array('jquery'));
?>
<script>
    jQuery('#Sel_ListImage').click(function (e) {
        e.preventDefault();
        custom_uploader_hami = wp.media.frames.custom_uploader_hami = wp.media({
            title: '<?php _e('Select Image', 'woo2app'); ?>',
            library: {type: 'image'},
            button: {text: '<?php _e('Select', 'woo2app'); ?>'},
            multiple: false
        });
        custom_uploader_hami.on('select', function() {
            attachment = custom_uploader_hami.state().get('selection').first().toJSON();
            jQuery('#ListImage').val(attachment.url);
            url_image = attachment.url;
        });
        custom_uploader_hami.open();
    })

    jQuery('#select_action_banner').on('change', function() {
        var type_val = (jQuery('#select_action_banner').val());
        //alert(type_val)
        jQuery('.el_type').css('display','none');
        if(type_val == 1){
            jQuery('#el_products').css('display','table-row');
        }
        else if(type_val == 2){
            jQuery('#el_cats').css('display','table-row');
        }
        else if(type_val == 3){
            jQuery('#el_link').css('display','table-row');
        }
    });
    jQuery('#search_product_banner1').keyup(function(){
        // alert(11)
        var  v = jQuery(this).val();
        if(v.length >= 3){
            jQuery("#img_load").attr("style",'display:block');
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "load_all_product",
                    search_product : v
                },
                success:function(data) {
                    jQuery("#img_load").attr("style",'display:none');
                    jQuery("#value_post_items").html(data);
                    jQuery("#value_post_items").prepend('<option selected value="0"> <?php _e('Select ...', 'woo2app');?></option>')
                }
            });
        }
    });
</script>

<script>
    function change_cat_tag(e) {
        if(e.value == 'cat'){
            jQuery('.cat_tag').addClass('hide')
            jQuery('#cat_list').removeClass('hide')
        }
        else if(e.value == 'tag'){
            jQuery('.cat_tag').addClass('hide')
            jQuery('#tag_list').removeClass('hide')
        }
        else if(e.value == 'tag_ver'){
            jQuery('.cat_tag_ver').addClass('hide')
            jQuery('#tag_list_ver').removeClass('hide')
        }
        else if(e.value == 'cat_ver'){
            jQuery('.cat_tag_ver').addClass('hide')
            jQuery('#cat_list_ver').removeClass('hide')
        }
        else if(e.value == 'custom_list'){
            jQuery('.cat_tag_ver').addClass('hide')
            jQuery('#custom_list_ver').removeClass('hide')
        }
    }
</script>