<?php

    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

    define('PLAN_BASIC', 1);
    define('PLAN_STANDARD', 2);
    define('PLAN_PRO', 3);

?>
<div class="wrap">
    <h1><?php
		echo esc_html( get_admin_page_title() ); ?></h1>
    <form action="options.php" method="post">
		<?php
		// Output security fields for the registered setting.
		settings_fields( 'epnab' );
		?>
        <table class="form-table" role="presentation">
	        <?php
	        $license_key = get_option( 'epnab_license_key' );
	        ?>
            <tr>
                <th scope="row"><label for="epnab_license_key"><?php
				        esc_html_e( 'Plugin License Key', 'epn-affiliate-banner' ); ?></label></th>
                <td>
                    <input id="epnab_license_key" name="epnab_license_key" type="text"
                           value="<?php esc_attr_e($license_key) ?>"/>
                </td>
            </tr>
			<?php
			$ebay_campaign_id = get_option( 'epnab_ebay_campaign_id' );
			?>
            <tr>
                <th scope="row"><label for="epnab_ebay_campaign_id"><?php
						esc_html_e( 'eBay Campaign ID', 'epn-affiliate-banner' ); ?></label></th>
                <td>
                    <input id="epnab_ebay_campaign_id" name="epnab_ebay_campaign_id" type="text"
                           value="<?php esc_attr_e($ebay_campaign_id) ?>"/>
                    <p class="description">
						<?php
						esc_html_e( 'Your eBay advertising campaign ID to track your traffic and earnings',
							'epn-affiliate-banner' ); ?>
                    </p>
                </td>
            </tr>
        </table>
        <h2 class="title"><?php
			esc_html_e( 'Search Settings', 'epn-affiliate-banner' ); ?></h2>
        <table class="form-table" role="presentation">
			<?php
			$keywords_strategy = get_option( 'epnab_keywords_strategy' );
			$keywords_count    = get_option( 'epnab_keywords_count' );
			?>
            <tr>
                <th scope="row"><?php
					esc_html_e( 'Use as a keyword', 'epn-affiliate-banner' ); ?></th>
                <td>
                    <label for="epnab_strategy_popular">
                        <input type="radio" id="epnab_strategy_popular"
                               name="epnab_keywords_strategy"
                               value="popular"<?php echo $keywords_strategy == 'popular' ? ' checked' : '' ?>/>
						<?php
						esc_html_e( 'The most popular word', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_strategy_any">
                        <input type="radio" id="epnab_strategy_any" name="epnab_keywords_strategy"
                               value="any"<?php echo $keywords_strategy == 'any' ? ' checked' : '' ?>/>
						<?php
						esc_html_e( 'Any word from popular words', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_strategy_random">
                        <input type="radio" id="epnab_strategy_random"
                               name="epnab_keywords_strategy"
                               value="random"<?php echo $keywords_strategy == 'random' ? ' checked' : '' ?>/>
						<?php
						esc_html_e( 'Random word from popular words', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <br/>
                    <label for="epnab_keywords_count">
					<?php
					esc_html_e( 'Consider', 'epn-affiliate-banner' ); ?>
                    <input type="text" class="small-text" id="epnab_keywords_count"
                           name="epnab_keywords_count" value="<?php esc_attr_e($keywords_count) ?>"/>
					<?php
					esc_html_e( 'words as popular', 'epn-affiliate-banner' ); ?>
                    </label>
                </td>
            </tr>
			<?php
			$keywords_title   = get_option( 'epnab_keywords_title' );
			$keywords_tags    = get_option( 'epnab_keywords_tags' );
			$keywords_content = get_option( 'epnab_keywords_content' );
			$keywords_custom  = get_option( 'epnab_keywords_custom' );
			$keywords         = get_option( 'epnab_keywords' );
			?>
            <tr>
                <th scope="row"><?php
					esc_html_e( 'Keywords', 'epn-affiliate-banner' ); ?></th>
                <td>
                    <label for="epnab_keywords_title">
                        <input type="checkbox" name="epnab_keywords_title"
                               id="epnab_keywords_title" value="1"<?php echo $keywords_title ? ' checked' : '' ?>>
						<?php
						esc_html_e( 'Extract from post title', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_keywords_tags">
                        <input type="checkbox" name="epnab_keywords_tags" id="epnab_keywords_tags"
                               value="1"<?php echo $keywords_tags ? ' checked' : '' ?>>
						<?php
						esc_html_e( 'Extract from post tags', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_keywords_content">
                        <input type="checkbox" name="epnab_keywords_content"
                               id="epnab_keywords_content"
                               value="1"<?php echo $keywords_content ? ' checked' : '' ?>>
						<?php
						esc_html_e( 'Extract from post content', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_keywords_custom">
                        <input type="checkbox" name="epnab_keywords_custom"
                               id="epnab_keywords_custom" value="1"<?php echo $keywords_custom ? ' checked' : '' ?>>
						<?php
						esc_html_e( 'Custom, use comma separated list', 'epn-affiliate-banner' ); ?>:<br/>
                        <textarea id="epnab_keywords" name="epnab_keywords" cols="80"
                                  rows="7"><?php esc_attr_e($keywords) ?></textarea><br/>
                    </label>
                </td>
            </tr>
			<?php
			$stopwords = get_option( 'epnab_stopwords' );
			?>
            <tr>
                <th scope="row"><label for="epnab_stopwords"><?php
						esc_html_e( 'Stop Words', 'epn-affiliate-banner' ); ?></label></th>
                <td>
                    <p><?php
						esc_html_e( 'Words which are filtered out before processing of text because they are insignificant',
							'epn-affiliate-banner' ); ?>:</p>
                    <textarea id="epnab_stopwords" name="epnab_stopwords" cols="80"
                              rows="7"><?php esc_attr_e($stopwords) ?></textarea><br/>
                    <button id="epnab_load_stopwords"><?php
						esc_html_e( 'Load Default List', 'epn-affiliate-banner' ); ?></button>
                    <button id="epnab_clear_stopwords"><?php
						esc_html_e( 'Clear', 'epn-affiliate-banner' ); ?></button>
                </td>
            </tr>
			<?php
			$min_price             = get_option( 'epnab_min_price' );
			$max_price             = get_option( 'epnab_max_price' );
			$condition_new         = get_option( 'epnab_condition_new' );
			$condition_used        = get_option( 'epnab_condition_used' );
			$type_auction          = get_option( 'epnab_type_auction' );
			$type_classified       = get_option( 'epnab_type_classified' );
			$type_fixed            = get_option( 'epnab_type_fixed' );
			$type_store            = get_option( 'epnab_type_store' );
			$free_shipping         = get_option( 'epnab_free_shipping' );
			?>
            <tr>
                <th scope="row"><?php
					esc_html_e( 'Filters', 'epn-affiliate-banner' ); ?></th>
                <td>
                    <label for="epnab_min_price">
						<?php
						esc_html_e( 'Price from', 'epn-affiliate-banner' ); ?>
                        <input type="text" class="small-text" id="epnab_min_price"
                               name="epnab_min_price" value="<?php esc_attr_e($min_price) ?>"/>
                    </label>
                    <label for="epnab_max_price">
						<?php
						esc_html_e( 'to', 'epn-affiliate-banner' ); ?>
                        <input type="text" class="small-text" id="epnab_max_price"
                               name="epnab_max_price" value="<?php esc_attr_e($max_price) ?>"/><br/>
                    </label>
                    <br/>
					<?php
					esc_html_e( 'Condition', 'epn-affiliate-banner' ) ?><br/>
                    <label for="epnab_condition_new">
                        <input type="checkbox" id="epnab_condition_new" name="epnab_condition_new"
                               value="1"<?php echo $condition_new ? ' checked' : '' ?>/> <?php
						esc_html_e( 'New', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_condition_used">
                        <input type="checkbox" id="epnab_condition_used"
                               name="epnab_condition_used"
                               value="1"<?php echo $condition_used ? ' checked' : '' ?>/> <?php
						esc_html_e( 'Used', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <br/>
					<?php
					esc_html_e( 'Type', 'epn-affiliate-banner' ) ?><br/>
                    <label for="epnab_type_auction">
                        <input type="checkbox" id="epnab_type_auction" name="epnab_type_auction"
                               value="1"<?php echo $type_auction ? ' checked' : '' ?>/> <?php
						esc_html_e( 'Auction', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_type_classified">
                        <input type="checkbox" id="epnab_type_classified"
                               name="epnab_type_classified"
                               value="1"<?php echo $type_classified ? ' checked' : '' ?>/> <?php
						esc_html_e( 'Classified', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_type_fixed">
                        <input type="checkbox" id="epnab_type_fixed" name="epnab_type_fixed"
                               value="1"<?php echo $type_fixed ? ' checked' : '' ?>/> <?php
						esc_html_e( 'Fixed Price', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <label for="epnab_type_store">
                        <input type="checkbox" id="epnab_type_store" name="epnab_type_store"
                               value="1"<?php echo $type_store ? ' checked' : '' ?>/> <?php
						esc_html_e( 'Store', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                    <br/>
                    <label for="epnab_free_shipping">
                        <input type="checkbox" id="epnab_free_shipping" name="epnab_free_shipping"
                               value="1"<?php echo $free_shipping ? ' checked' : '' ?>/> <?php
						esc_html_e( 'Free Shipping', 'epn-affiliate-banner' ); ?><br/>
                    </label>
                </td>
            </tr>
			<?php
			$sort_order  = get_option( 'epnab_sort_order' );
			$page_size   = get_option( 'epnab_page_size' );
			?>
            <tr>
                <th scope="row"><?php
					esc_html_e( 'Results', 'epn-affiliate-banner' ); ?></th>
                <td>
                    <label for="epnab_sort_order">
						<?php
						esc_html_e( 'Order by', 'epn-affiliate-banner' ); ?> </label>
                        <select name="epnab_sort_order" id="epnab_sort_order">
                            <option<?php echo $sort_order == '' ? ' selected' : '' ?>></option>
                            <option<?php echo $sort_order == 'lowest price' ? ' selected' : '' ?>><?php
								esc_html_e( 'lowest price', 'epn-affiliate-banner' ); ?></option>
                            <option<?php echo $sort_order == 'highest price' ? ' selected' : '' ?>><?php
								esc_html_e( 'highest price', 'epn-affiliate-banner' ); ?></option>
                            <option<?php echo $sort_order == 'random' ? ' selected' : '' ?>><?php
								esc_html_e( 'random', 'epn-affiliate-banner' ); ?></option>
                        </select><br/>
                    <br/>
                    <label for="epnab_page_size">
						<?php
						esc_html_e( 'Return', 'epn-affiliate-banner' ); ?>
                        <input type="text" class="small-text" id="epnab_page_size"
                               name="epnab_page_size" value="<?php esc_attr_e($page_size) ?>"/>
						<?php
						esc_html_e( 'items per page', 'epn-affiliate-banner' ); ?>
                    </label>
                </td>
            </tr>
        </table>
        <h2 class="title"><?php
			esc_html_e( 'Display Settings', 'epn-affiliate-banner' ); ?></h2>
        <table class="form-table" role="presentation">
			<?php

			// Get the value of the setting we've registered with register_setting()
			$template = get_option( 'epnab_template' );
			$carousel = get_option( 'epnab_carousel' );
			$position = get_option( 'epnab_position' );

			// Get template dir files
			$filesystem = new FilesystemIterator( EPNAB_DIR_TEMPLATES );
			$files      = new Epnab_FileIterator( $filesystem, [ 'phtml' ] );

			?>
            <tr>
                <th scope="row"><?php
						esc_html_e( 'Banner', 'epn-affiliate-banner' ); ?></th>
                <td>
                    <p><label for="epnab_template"><?php
			                esc_html_e( 'Template', 'epn-affiliate-banner' ); ?></label></p>
                    <select id="epnab_template" name="epnab_template">
						<?php

                        $count = 0;
						foreach ( $files as $file ) {
							$name = $file->getFilename();
							?>
                            <option value="<?php esc_attr_e($name) ?>" <?php
							echo selected( $template, $name ); ?>>
								<?php
								esc_html_e( $name, 'epn-affiliate-banner' ); ?>
                            </option>
							<?php
                            $count++;
						}
						?>

                    </select>
                    <p class="description">
						<?php
						esc_html_e( 'Please, select what template to use to show the banner', 'epn-affiliate-banner' ); ?>
                    </p>
                    <br/>
                    <p><label for="epnab_position"><?php
			                esc_html_e( 'Position', 'epn-affiliate-banner' ); ?></label></p>
                        <select name="epnab_position" id="epnab_position">
                            <option value="before"<?php echo $position == 'before' ? ' selected' : '' ?>><?php
				                esc_html_e( 'Before content', 'epn-affiliate-banner' ); ?></option>
                            <option value="after"<?php echo $position == 'after' ? ' selected' : '' ?>><?php
				                esc_html_e( 'After content', 'epn-affiliate-banner' ); ?></option>
                        </select>
                        <p class="description">
                            <?php
                            esc_html_e( 'Please, select where to show the banner', 'epn-affiliate-banner' ); ?>
                        </p>
                </td>
            </tr>
			<?php
			$button_color            = get_option( 'epnab_button_color' );
			$button_hover_color      = get_option( 'epnab_button_hover_color' );
			$button_text_color       = get_option( 'epnab_button_text_color' );
			$button_text_hover_color = get_option( 'epnab_button_text_hover_color' );
			$button_border_radius = get_option( 'epnab_button_border_radius' );
			?>
            <tr>
                <th scope="row"><label for="epnab_button_color"><?php
						esc_html_e( 'Buy Button', 'epn-affiliate-banner' ); ?></label></th>
                <td>
                    <p><label for="epnab_button_color"><?php
							esc_html_e( 'Background color', 'epn-affiliate-banner' ); ?></label></p>
                    <input id="epnab_button_color" name="epnab_button_color" type="text"
                           value="<?php esc_attr_e($button_color) ?>"/>
                    <p class="description">
						<?php
						esc_html_e( 'Please, select what color to use for Buy button', 'epn-affiliate-banner' ); ?>
                    </p>
                    <p><label for="epnab_button_hover_color"><?php
							esc_html_e( 'Background hover color', 'epn-affiliate-banner' ); ?></label></p>
                    <input id="epnab_button_hover_color" name="epnab_button_hover_color"
                           type="text"
                           value="<?php esc_attr_e($button_hover_color) ?>"/>
                    <p class="description">
						<?php
						esc_html_e(
							'Please, select what color to use for Buy button when the mouse pointer is over the button',
							'epn-affiliate-banner'
						); ?>
                    </p>
                    <p><label for="epnab_button_text_color"><?php
							esc_html_e( 'Text color', 'epn-affiliate-banner' ); ?></label></p>
                    <input id="epnab_button_text_color" name="epnab_button_text_color" type="text"
                           value="<?php esc_attr_e($button_text_color) ?>"/>
                    <p class="description">
						<?php
						esc_html_e( 'Please, select what color to use for Buy button text', 'epn-affiliate-banner' ); ?>
                    </p>
                    <p><label for="epnab_button_text_hover_color"><?php
							esc_html_e( 'Text hover color', 'epn-affiliate-banner' ); ?></label></p>
                    <input id="epnab_button_text_hover_color" name="epnab_button_text_hover_color"
                           type="text"
                           value="<?php esc_attr_e($button_text_hover_color) ?>"/>
                    <p class="description">
						<?php
						esc_html_e(
							'Please, select what color to use for Buy button text when the mouse pointer is over the button',
							'epn-affiliate-banner'
						); ?>
                    </p>
                    <p><label for="epnab_button_border_radius"><?php
			                esc_html_e( 'Border radius', 'epn-affiliate-banner' ); ?></label></p>
                    <input id="epnab_button_border_radius" name="epnab_button_border_radius"
                           type="text"
                           value="<?php esc_attr_e($button_border_radius) ?>" maxlength="3" style="width:100px"/> px
                    <p class="description">
		                <?php
		                esc_html_e(
			                'Please, select how much to round the corners of the Buy button outer border edge',
			                'epn-affiliate-banner'
		                ); ?>
                    </p>
                </td>
            </tr>
        </table>
		<?php
		submit_button( esc_html__('Save Settings', 'epn-affiliate-banner') );
		?>
    </form>
</div>