<?php
/**
 * This file is used to markup the plugin settings in table with modal popup.
 *
 * @since      1.0
 *
 * @package    SiteEase_Smart_Product_Filtering_Engine
 * @subpackage SiteEase_Smart_Product_Filtering_Engine/admin/partials
 */

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<?php if ( !empty( $modal_popup_settings ) ) { ?>
<table class="ifqpf-table-modal ifqpf-sortable-table">
	<thead>
		<th><?php echo esc_html__('Position', 'siteease-smart-product-filtering-engine'); ?></th>
		<th><?php echo esc_html__('Hide/Show', 'siteease-smart-product-filtering-engine'); ?></th>
		<th><?php echo esc_html__('Name', 'siteease-smart-product-filtering-engine'); ?></th>
		<th><?php echo esc_html__('Type', 'siteease-smart-product-filtering-engine'); ?></th>
		<th><?php echo esc_html__('View/Edit', 'siteease-smart-product-filtering-engine'); ?></th>
	</thead>
	<tbody>
		<?php foreach ($modal_popup_settings as $se_key => $setting) { ?>
			<?php
			$classes = isset( $setting['class'] ) ? $setting['class'] . ' ' : '';
			$sortable = isset( $setting['sortable'] ) ? $setting['sortable'] : false;
			$sortable_class = $sortable ? 'ifqpf-row-sortable' : '';
			$setting_id = $setting['id'];
			$fields = isset( $setting['fields'] ) ? $setting['fields'] : array();
			$name = isset( $setting['name'] ) && !empty( $setting['name'] ) ? $setting['name'] : "-";
			$type = isset( $setting['type'] ) && !empty( $setting['type'] ) ? $setting['type'] : "-";

			if ( isset( $setting['field'] ) && !empty( $setting['field'] ) ) {
				$classes .= 'ifqpf-check-popup-field ';
			}

			?>
			<tr class="<?php echo esc_attr( $classes . $sortable_class ); ?>">
				<td>
					<?php
					if ( !empty($sortable) ) {
						echo wp_kses_post('<span class="ui-icon ui-icon-arrowthick-2-n-s sorting-handle"></span>');
					} else {
						echo esc_html__('-', 'siteease-smart-product-filtering-engine');
					}
					?>
				</td>
				<td>
					<?php
					if ( isset( $setting['field'] ) && !empty( $setting['field'] ) ) {
						$field = $setting['field'];
						$field['class'] = isset( $field['class'] ) ? $field['class'] . 'ifqpf-enable-popup ' : 'ifqpf-enable-popup ';
						ifqpf_get_admin_field_markup( $field );
					} else {
						echo esc_html__('-', 'siteease-smart-product-filtering-engine');
					}
					?>
				</td>
				<td><?php echo esc_html( $name ); ?></td>
				<td><?php echo esc_html( $type ); ?></td>
				<td>
					<?php 
					if (!isset($defaults)) { $defaults = array(); }

					if ( isset( $setting['popup'] ) && $setting['popup'] === true ) { ?>
						<a href="#" class="ifqpf-table-modal-open" data-id="<?php echo esc_attr( $setting_id ); ?>"><?php echo esc_html__('View/Edit', 'siteease-smart-product-filtering-engine'); ?></a>
						<?php if ( !empty( $fields ) ) { ?>
							<?php 
							$popup_args = array(
								'setting' => $setting,
								'fields' => $fields,
								'popup_heading' => $name,
								'defaults' => $defaults,
							);
							ifqpf_get_admin_template('ifqpf-settings-popup.php', $popup_args);
							?>
						<?php } ?>
					<?php } else { ?>
						<?php echo esc_html__('-', 'siteease-smart-product-filtering-engine'); ?>	
					<?php } ?>
				</td>
			</tr>
		<?php } ?>
	</tbody>
</table>
<?php } ?>