<?php
	settings_fields('rtwwpcp_basic_setting');
	$rtwwpcp_get_setting = get_option('rtwwpcp_basic_setting_opt');

	$rtwwpcp_terms = get_terms([
		'taxonomy' => 'product_cat',
		'hide_empty' => false,
		'parent' => 0
	]);

    foreach ($rtwwpcp_terms as $rtwwpcp_key => $rtwwpcp_value) {
    	$rtwwpcp_prod_cat[$rtwwpcp_value->slug] = $rtwwpcp_value->name;
    }
    
    $user_role = array();
    global $wp_roles;
    $all_roles = $wp_roles->roles;
    foreach ($all_roles as $k => $v) {
    	$user_role[$k] = $v['name'];
    }
    $user_role['all_users'] = 'All Users';
?>
<table class="wp-list-table form-table rtwwpcp-table">
	<tbody>
		<tr>
			<th class="descr"><?php esc_html_e('Enable Catalog', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<input type="checkbox" name="rtwwpcp_basic_setting_opt[enabl_catalog]" value="1" <?php echo isset( $rtwwpcp_get_setting['enabl_catalog'] ) && $rtwwpcp_get_setting['enabl_catalog'] == 1 ? esc_html('checked="checked"') : ''; ?> />
				<div class="descr"><?php esc_html_e('Check it if you want generate PDF catalog of your products.( not work if category catalog is enable )', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th class="descr"><?php esc_html_e('Rtl Support', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<input type="checkbox" name="rtwwpcp_basic_setting_opt[rtl]" value="1" <?php echo isset( $rtwwpcp_get_setting['rtl'] ) && $rtwwpcp_get_setting['rtl'] == 1 ? esc_html('checked="checked"') : ''; ?> />
				<div class="descr"><?php esc_html_e('Check it if you want generate pdf in Arabic or languages which start from right align.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Text For Catalog Button', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr">
				<input type="text" name="rtwwpcp_basic_setting_opt[catalog_btn_txt]"
			value="<?php echo esc_attr((isset ( $rtwwpcp_get_setting['catalog_btn_txt'] )) ? $rtwwpcp_get_setting['catalog_btn_txt'] : 'Download PDF Catalog'); ?>" />
				<div class="descr"><?php esc_html_e('Enter your required text for catalog button. By default Download PDF Catalog is set.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Select Role', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<select multiple="multiple" id="rtwwpcp_user_role" name="rtwwpcp_basic_setting_opt[user_roles][]">
					<option><?php esc_html_e('Select', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></option>
					<?php
					foreach ($user_role as $rtwwpcf_k => $rtwwpcf_val) 
					{
						?>
						<option value="<?php echo esc_attr($rtwwpcf_k);?>" <?php echo esc_html(isset( $rtwwpcp_get_setting['user_roles'] )) && (in_array($rtwwpcf_k, $rtwwpcp_get_setting['user_roles'])) ? 'selected="selected"' : '';?>><?php echo esc_html($rtwwpcf_val);?></option>
						<?php
					}
					?>
				</select>
				<div class="descr"><?php esc_html_e('Select the user roles by which they can see Catalog button and single product PDF button.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th class="descr"><?php esc_html_e('Enable Single Product PDF', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<input type="checkbox" name="rtwwpcp_basic_setting_opt[enabl_sngl_prdct_pdf]" value="1" <?php echo isset( $rtwwpcp_get_setting['enabl_sngl_prdct_pdf'] ) && $rtwwpcp_get_setting['enabl_sngl_prdct_pdf'] == 1 ? esc_html('checked="checked"') : ''; ?> />
				<div class="descr"><?php esc_html_e('Check it if you want print product button on single product page.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Select Name For Single Product PDF', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr">
				<select id="rtwwpcp_pdf_name" name="rtwwpcp_basic_setting_opt[pdf_name]">
					<option value="rtwwpcp_post_id" <?php echo isset( $rtwwpcp_get_setting['pdf_name'] ) && $rtwwpcp_get_setting['pdf_name'] == 'rtwwpcp_post_id' ? 'selected="selected"' : '';?>><?php esc_html_e('Post ID', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></option>
					<option value="rtwwpcp_post_name" <?php echo isset( $rtwwpcp_get_setting['pdf_name'] ) && $rtwwpcp_get_setting['pdf_name'] == 'rtwwpcp_post_name' ? 'selected="selected"' : '';?>><?php esc_html_e('Post Name', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></option>
				</select>
				<div class="descr"><?php esc_html_e('Choose option for single product PDF name. By default post id is set.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Text For Product PDF Button', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr">
				<input type="text" name="rtwwpcp_basic_setting_opt[prodct_pdf_btn_txt]"
			value="<?php echo esc_attr((isset ( $rtwwpcp_get_setting['prodct_pdf_btn_txt'] )) ? $rtwwpcp_get_setting['prodct_pdf_btn_txt'] : 'Download PDF'); ?>" />
				<div class="descr"><?php esc_html_e('Enter your required text for button of single product PDF. By default Download PDF is set.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Select where to show single product PDF button', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr">
				<select name="rtwwpcp_basic_setting_opt[sngl_prod_btn]">
					<option value="woocommerce_before_single_product">Before Product Page</option>
					<option value="woocommerce_single_product_summary" <?php echo esc_html(isset( $rtwwpcp_get_setting['sngl_prod_btn'] ) && $rtwwpcp_get_setting['sngl_prod_btn'] == 'woocommerce_single_product_summary' ? 'selected="selected"' : '');?>>Before product title</option>
					<option value="woocommerce_after_add_to_cart_button" <?php echo esc_html(isset( $rtwwpcp_get_setting['sngl_prod_btn'] ) && $rtwwpcp_get_setting['sngl_prod_btn'] == 'woocommerce_after_add_to_cart_button' ? 'selected="selected"' : '');?>>After add to cart button</option>
					<option value="woocommerce_product_meta_end" <?php echo esc_html(isset( $rtwwpcp_get_setting['sngl_prod_btn'] ) && $rtwwpcp_get_setting['sngl_prod_btn'] == 'woocommerce_product_meta_end' ? 'selected="selected"' : '');?>>After Product SKU</option>
					<option value="woocommerce_after_single_product_summary" <?php echo esc_html(isset( $rtwwpcp_get_setting['sngl_prod_btn'] ) && $rtwwpcp_get_setting['sngl_prod_btn'] == 'woocommerce_after_single_product_summary' ? 'selected="selected"' : '');?>>After Product Description</option>
					<option value="woocommerce_after_single_product" <?php echo esc_html(isset( $rtwwpcp_get_setting['sngl_prod_btn'] ) && $rtwwpcp_get_setting['sngl_prod_btn'] == 'woocommerce_after_single_product' ? 'selected="selected"' : '');?>>After product page</option>
				</select>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Enable Category Catalog', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<input type="checkbox" id="rtwwpcp_cat_catalog" name="rtwwpcp_basic_setting_opt[enbl_ctgry_catlog]" value="1" <?php echo isset( $rtwwpcp_get_setting['enbl_ctgry_catlog'] ) && $rtwwpcp_get_setting['enbl_ctgry_catlog'] == 1 ? esc_html('checked="checked"') : ''; ?> />
				<div class="descr"><?php esc_html_e('Check it if you want generate PDF catalog of specific product category.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr id="rtwwpcp_show_cat_opt" class="<?php if( !isset( $rtwwpcp_get_setting['enbl_ctgry_catlog'] )) { echo esc_attr('rtwwpcp_hide_template'); } ?>">
			<th class="descr"><?php esc_html_e('Select Product Category', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td>
				<select multiple="multiple" id="rtwwpcp_e1" name="rtwwpcp_basic_setting_opt[product_catgry][]">
					<?php
						foreach ($rtwwpcp_prod_cat as $k => $val) { ?>
							<option value="<?php echo esc_attr($k);?>" <?php echo esc_html(isset( $rtwwpcp_get_setting['product_catgry'] )) && (in_array($k, $rtwwpcp_get_setting['product_catgry'])) ? 'selected="selected"' : '';?> ><?php echo esc_html($val);?></option>
					<?php	}
					?>
				</select>
				<div class="descr"><?php esc_html_e('Select your product categories for which you want to generate PDF catalog.(you can see download catalog button on selected category page)', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Include In Stock Products Only', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<input type="checkbox" id="" name="rtwwpcp_basic_setting_opt[include_instock_product]" value="1" <?php echo isset( $rtwwpcp_get_setting['include_instock_product'] ) && $rtwwpcp_get_setting['include_instock_product'] == 1 ? esc_html('checked="checked"') : ''; ?> />
				<div class="descr"><?php esc_html_e('Check it if you want to ctreate catalog with only all those productds which are in stock.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
		<tr>
			<th><?php esc_html_e('Hide Add To Cart Button', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
			<td class="descr_2">
				<input type="checkbox" id="" name="rtwwpcp_basic_setting_opt[hide_add_to_cart_button]" value="1" <?php echo isset( $rtwwpcp_get_setting['hide_add_to_cart_button'] ) && $rtwwpcp_get_setting['hide_add_to_cart_button'] == 1 ? esc_html('checked="checked"') : ''; ?> />
				<div class="descr"><?php esc_html_e('Check it if you want to hide add to cart button from catalog (not works in template 3 & 4) and single product PDF.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
			</td>
		</tr>
	</tbody>	
</table>
<table class="wp-list-table form-table rtwwpcp-table">
	<tr>
		<th><?php esc_html_e('Enable Password Protection', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
		<td><input type="checkbox" id="rtwwpcp_pswrd_prtcn" name="rtwwpcp_basic_setting_opt[enable_paswrd]" value="1" <?php echo ( isset( $rtwwpcp_get_setting['enable_paswrd'] )) ? esc_html('checked = "checked"') : ''?> />
			<div class="descr"><?php esc_html_e('Check it if you want to enable Password Protection.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
		</td>
	</tr>
	<tr>
		<th class="descr"><?php esc_html_e('Cover Image For First Page ', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
		<td>
			<?php $rtwwpcp_src_img = isset($rtwwpcp_get_setting['cvr_img_url'] ) ? $rtwwpcp_get_setting['cvr_img_url'] : '';?>
			<?php if($rtwwpcp_src_img != '') { ?>
				<div id="rtwwpcp_cover_img">
					<img id="rtwwpcp_cover_img_btn" src="<?php echo esc_url($rtwwpcp_src_img); ?>"/>
				</div>
			<?php } ?>
			<div id="rtwwpcp_covr_img">
				<input type="hidden" id="rtwwpcp_cvr_img_url"
				name="rtwwpcp_basic_setting_opt[cvr_img_url]"
				value="<?php echo esc_attr($rtwwpcp_src_img); ?>" />
				<button type="button" class="rtwwpcp_cvr_img_upload button"><?php esc_html_e( 'Upload/Add image', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></button><br>
				<?php if($rtwwpcp_src_img != '') { ?>
					<button type="button" class="rtwwpcp_remove_cvr_img button"><?php esc_html_e( 'Remove image', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></button>
				<?php } ?>
			</div>
			<div class="descr"><?php esc_html_e('Choose your Image which you want to show as cover image of first page of PDF catalog.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
		</td>
	</tr>
	<tr>
		<th class="descr"><?php esc_html_e('Cover Image For Last Page ', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
		<td>
			<?php $rtwwpcp_src_img = isset($rtwwpcp_get_setting['bck_cvr_img_url'] ) ? $rtwwpcp_get_setting['bck_cvr_img_url'] : '';?>
			<?php if($rtwwpcp_src_img != '') { ?>
				<div id="rtwwpcp_bck_cover_img">
					<img id="rtwwpcp_bck_cover_img_btn" src="<?php echo esc_url($rtwwpcp_src_img); ?>"/>
				</div>
			<?php } ?>
			<div id="rtwwpcp_bck_covr_img">
				<input type="hidden" id="rtwwpcp_bck_cvr_img_url"
				name="rtwwpcp_basic_setting_opt[bck_cvr_img_url]"
				value="<?php echo esc_attr($rtwwpcp_src_img); ?>" />
				<button type="button" class="rtwwpcp_bck_cvr_img_upload button"><?php esc_html_e( 'Upload/Add image', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></button><br>
				<?php if($rtwwpcp_src_img != '') { ?>
					<button type="button" class="rtwwpcp_remove_bck_cvr_img button"><?php esc_html_e( 'Remove image', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></button>
				<?php } ?>
			</div>
			<div class="descr"><?php esc_html_e('Choose your Image which you want to show as cover image of last page of PDF catalog.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
		</td>
	</tr>
</table>
<table id="rtwwpcp_add_pswrd_protctn" class="wp-list-table form-table rtwwpcp-table <?php if( !isset( $rtwwpcp_get_setting['enable_paswrd'] )) { echo esc_attr('rtwwpcf_hidden_table'); } ?>">
	<tr>
		<th><?php esc_html_e('Enter A Password', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
		<td class="descr">
			<input type="text" name="rtwwpcp_basic_setting_opt[catalog_pswrd]"
		value="<?php echo esc_attr((isset ( $rtwwpcp_get_setting['catalog_pswrd'] )) ? $rtwwpcp_get_setting['catalog_pswrd'] : '0123456789'); ?>" />
			<div class="descr"><?php esc_html_e('Enter your required password for PDf catalog. By default 0123456789 is set.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
		</td>
	</tr>
</table>
<table class="wp-list-table form-table rtwwpcp-table">
<tbody>
<tr>
	<th class="descr"><?php esc_html_e('Set background Image for PDF', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
	<td>
		<?php $rtwwpcp_src_img = isset($rtwwpcp_get_setting['bck_img_url'] ) ? $rtwwpcp_get_setting['bck_img_url'] : '';?>
		<?php if($rtwwpcp_src_img != '') { ?>
			<div id="rtwwpcp_bckgrnd_img">
				<img id="rtwwpcp_bckgrnd_img_btn" src="<?php echo esc_url($rtwwpcp_src_img); ?>"/>
			</div>
		<?php } ?>
		<div id="rtwwpcp_bck_img">
			<input type="hidden" id="rtwwpcp_bck_img_url"
			name="rtwwpcp_basic_setting_opt[bck_img_url]"
			value="<?php echo esc_attr($rtwwpcp_src_img); ?>" />
			<button type="button" class="rtwwpcp_btn_bckgrnd_img_upload button"><?php esc_html_e( 'Upload/Add image', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></button><br>
			<?php if($rtwwpcp_src_img != '') { ?>
				<button type="button" class="rtwwpcp_btn_remove_bckgrnd_img button"><?php esc_html_e( 'Remove image', 'rtwwpcp-woocommerce-pdf-catalog-pro'); ?></button>
			<?php } ?>
		</div>
		<div class="descr"><?php esc_html_e('Choose your Image which you want to show as background image in generated PDF.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
	</td>
</tr>
<tr>
	<th class="descr"><?php esc_html_e('Select Background color For PDF', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
	<td>
		<?php $rtwwpcp_back_color = isset($rtwwpcp_get_setting['back_color'] ) ? $rtwwpcp_get_setting['back_color'] : ''; ?>
		<div class="wp-picker-container">
			<input class="color-field" type="text" name="rtwwpcp_basic_setting_opt[back_color]" value="<?php echo esc_attr($rtwwpcp_back_color); ?>" />
		</div>
		<div class="descr"><?php esc_html_e('Choose the color for your pdf background.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
	</td>
</tr>
<tr>
	<th class="descr"><?php esc_html_e('Hide Page No.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></th>
	<td class="descr_2">
		<input type="checkbox" name="rtwwpcp_basic_setting_opt[page_no]" value="1" <?php echo isset( $rtwwpcp_get_setting['page_no'] ) && $rtwwpcp_get_setting['page_no'] == 1 ? esc_html('checked="checked"') : ''; ?> />
		<div class="descr"><?php esc_html_e('Check it if you want Hide PDF page no.', 'rtwwpcp-woocommerce-pdf-catalog-pro');?></div>
	</td>
</tr> 
</tbody>
</table>