<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>

<?php $amazingaffiliates_page = "insert";  ?>

<main class="amazingaffiliates_admin_page" data-ajax="<?php echo esc_url( get_site_url() ); ?>/wp-admin/admin-ajax.php" data-nonce="<?php echo esc_attr( wp_create_nonce( 'workshop-warehouse' ) ); ?>" >
	
	<nav id="amazingaffiliates_navbar">
		<?php do_action('amazingaffiliates_navbar', $amazingaffiliates_page ); ?>
	</nav>
	
	<?php do_action('amazingaffiliates_setupnotice' ); ?>
	
	<details id="header" >
		
		<summary><h1 class="amazingaffiliates_admin_page_title">Amazing Affiliates Workshop<span>ⓘ</span></h1></summary>
		<h2>In this page you can insert products just by copying the ASIN or product URL</h2>
		<p>To add the Amazon product in your website you just need either the ASIN or the product link.</p>
		<p>Once inserted, the product/s will be automatically added to your website database and you can browse them in the "Amazing Affiliates Warehouse" (the "Edit" section of the plugin).</p>
		<p>To display the product on your blog post just copy the product id and paste it on the dedicated field of the "Amazing Product" Gutenberg Block on the desired post.</p>
		
	</details>
	
	<i style="display:block;width:calc(100% - 0.5em);text-align:center;">Enjoying <strong>Amazing Affiliates</strong>? Please rate <a href="https://wordpress.org/plugins/amazingaffiliates/#reviews" target="_blank" rel="noopener noreferrer">★★★★★</a> on <a <a="" href="https://wordpress.org/plugins/amazingaffiliates/#reviews" target="_blank" rel="noopener">WordPress.org</a> to help us spread the word. Thank you!</i>
	
	<section id="workshop_forge" style="padding:10px;">
		<details>
			<summary><h2 style="margin:5px 0 10px 0;">Automatic (through Amazon APIs) <span>ⓘ</span></h2></summary>
				<p style="margin-left:10px;line-height:1.75em;">That's the best, fastest, effortless way to add Amazon prodcuts to your website database.
					<br><b>You need access to the Amazon PAAPI5 to use it.</b>
					<br>Just copy paste the product link and it will be added to the list below.
					<br>Then when your list is ready hit insert, the products will be created and filled with data directly from Amazon.
					<br><i>If your account is not eligible for the use of the APIs you can use the manual insert below.</i>
				</p>
		</details>

		<input id="asin_purifier" type="text" placeholder="Paste here the ASIN or the link">
		<button onclick="clearAsinCrucible();">Clear list</button>
		<ol id="asins_crucible" data-asin >
		</ol>
		<button id="insert_products" style="padding:10px 15px;">Insert<br>(automatic)</button>
	</section>
	
	<section style="padding:10px;">

			<details>
				<summary><h2 style="margin:5px 0 10px 0;">Manual insert (no APIs needed) <span>ⓘ</span></h2></summary>
				<p style="margin-left:10px;line-height:1.75em;">Don't have access to the API's?
					<br>Don't worry you can still use this plugin!
					<br>You need to copypaste below the ASIN of the product and then insert the product.
					<br><i>The ASIN is the unique 10 characters string for each Amazon product like ABC123GHI4)</i>
					<br>Remember to fill the fields through the <img alt="" width="15" height="15" src="<?php echo esc_attr( AMAZINGAFFILIATES_PLUGIN_URL . '/admin/img/edit.jpg' ); ?>" > edit button after having created the blank product.
				</p>
			</details>			
			<div style="display:flex;justify-content:space-between;align-items:stretch;flex-grow:1;margin-top:5px;">
				<input id="asin_blank_product" type="text" placeholder="Paste here the ASIN" style="flex-grow:1;margin-right:5px;">
				<button id="insert_products_blank"  style="padding:10px 15px;">Insert<br>(manually)</button>
			</div>

	</section>
	
	<div id="consolebox" >
		<div id="console"></div>
		<button id="expand" >+ More +</button>
	</div>
	
	<div class="warehouse_selectors" style="display:none;">
			<div class="warehouse_selector_wrapper" >
				<div class="warehouse_selector labeled" >
					<label for="warehouse_entries_selector">Entries:</label>
					<select name="warehouse_entries_selector" id="warehouse_entries_selector" >
							 <option value="25" selected >Show 25 entries</option>
							 <option value="50" >Show 50 entries</option>
							 <option value="100" >Show 100 entries</option>
					</select>
				</div>
				<div class="warehouse_selector labeled" >
					<label for="warehouse_asin_selector">ASIN:</label>
					<input name="warehouse_asin_selector" id="warehouse_asin_selector" type="text" placeholder="Search by ASIN or url:" >
				</div>
				<div class="warehouse_selector labeled" >
					<label for="warehouse_title_selector">Title:</label>
					<input name="warehouse_title_selector" id="warehouse_title_selector" type="text" placeholder="Search by title:" >
				</div>
			</div>
            <div class="warehouse_selector_wrapper" >
                
                <?php foreach(AmazingAffiliates_Admin::$amazingaffiliates_tax_index as $taxonomy) : ?>
                    
                    <div class="warehouse_selector labeled" >
                        
                        <label><?php echo esc_html( $taxonomy['taxNameSingular'] ); ?>:</label>
                        <div id="warehouse_<?php echo esc_attr( $taxonomy['taxSlug'] ); ?>_selector" >
                            
                            <?php
                            $tax_args = array(
                                'taxonomy' => $taxonomy['taxSlug'],
                                'orderby' => 'name',
                                'order' => 'ASC',
                                'hide_empty' => false
                            );
                            $taxonomy_entries = get_terms( $tax_args );
                            ?>
                            
                            <?php foreach  ($taxonomy_entries as $taxonomy_entry) : ?>
                                
                                <input  type="checkbox"
                                    name="warehouse_<?php echo esc_attr( $taxonomy['taxSlug'] ); ?>_selector"
                                    id="<?php echo esc_html( $taxonomy_entry->slug ); ?>_checkbox"
                                    value="<?php echo esc_attr( $taxonomy_entry->term_id ); ?>"
                                >
                                
                                <label for="<?php echo esc_html( $taxonomy_entry->slug ); ?>_checkbox">
                                    <?php echo esc_html( $taxonomy_entry->name ); ?>
                                </label>
                                
                            <?php endforeach; ?>
                            
                        </div>
                        
                    </div>
                    
                <?php endforeach; ?>
                	
            </div>
		</div>
	
	<section style="padding:5px 10px 10px 10px;">
		
		<h2 style="margin:5px 0 10px 0;">Latest added products</h2>
		
		<div id="product_display" ></div>
		
	</section>

</main>