<?php
/**
 * Post types index template.
 *
 * @package WLC_Algolia
 *
 * @var array  $post_types
 * @var string $settings_tab
 * @var array  $checked
 * @var string $index_name
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

( static function ( array $wlc_algolia_scope_vars ) {
	extract( $wlc_algolia_scope_vars, EXTR_SKIP ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract

	?>
<div class="index-error-message"><p class="post-type-index-error-message"></p></div>
<div class="index-success-message"><p class="post-type-index-success-message"></p></div>
<div class="wlc-algolia-show-advanced">
	<label class="wlc-algolia-toggle">
		<input type="checkbox" id="wlc-posttype-show-advanced" value="1" />
		<span class="wlc-algolia-toggle-slider"></span>
	</label>
	<label for="wlc-posttype-show-advanced" class="wlc-algolia-toggle-label">
		<?php esc_html_e( 'Show advanced settings', 'wlc-search-integration-with-algolia' ); ?>
	</label>
</div>
<table class="index-container container">
	<thead>
	<tr>
		<th><?php esc_html_e( 'Post type', 'wlc-search-integration-with-algolia' ); ?></th>
		<th><?php esc_html_e( 'enable Indexing', 'wlc-search-integration-with-algolia' ); ?></th>
		<th><?php esc_html_e( 'is autosuggestion index?', 'wlc-search-integration-with-algolia' ); ?></th>
		<th><?php esc_html_e( 'index name', 'wlc-search-integration-with-algolia' ); ?></th>
		<th><?php esc_html_e( 'Custom index name', 'wlc-search-integration-with-algolia' ); ?></th>
		<th><?php esc_html_e( 'status', 'wlc-search-integration-with-algolia' ); ?></th>
		<th><?php esc_html_e( 'INDEX', 'wlc-search-integration-with-algolia' ); ?></th>
	</tr>
	</thead>
	<tbody>
	<?php
	foreach ( $post_types as $wlc_algolia_post_type_item ) {
		$wlc_algolia_post_type_slug  = $wlc_algolia_post_type_item->name;
		$wlc_algolia_post_type_label = $wlc_algolia_post_type_item->label;
		$wlc_algolia_selected        = isset( $checked[ $wlc_algolia_post_type_slug ] ) ? esc_attr( $checked[ $wlc_algolia_post_type_slug ] ) : '';
		$wlc_algolia_autosuggestion  = isset( $checked[ $wlc_algolia_post_type_slug . '_autosuggestion' ] ) ? esc_attr( $checked[ $wlc_algolia_post_type_slug . '_autosuggestion' ] ) : '';
		$wlc_algolia_custom_index    = isset( $checked[ $wlc_algolia_post_type_slug . '_custom_index' ] ) ? esc_attr( $checked[ $wlc_algolia_post_type_slug . '_custom_index' ] ) : '';
		?>
		<tr>
			<td class="label"><?php echo esc_html( $wlc_algolia_post_type_label ); ?></td>
			<td class="enable-indexing">
				<label class="wlc-algolia-toggle">
					<input type="hidden" name="wlc_algolia_settings_<?php echo esc_attr( $settings_tab ); ?>[<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>]" value="0" />
					<input type="checkbox" class="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>" name="wlc_algolia_settings_<?php echo esc_attr( $settings_tab ); ?>[<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>]" id="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>" value="1" <?php echo checked( 1, $wlc_algolia_selected, false ); ?> />
					<span class="wlc-algolia-toggle-slider"></span>
				</label>
			</td>
			<td class="autosuggestion-index">
				<label class="wlc-algolia-toggle">
					<input type="hidden" name="wlc_algolia_settings_<?php echo esc_attr( $settings_tab ); ?>[<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>_autosuggestion]" value="0" />
					<input type="checkbox" class="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>_autosuggestion" name="wlc_algolia_settings_<?php echo esc_attr( $settings_tab ); ?>[<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>_autosuggestion]" id="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>_autosuggestion" value="1" <?php echo checked( 1, $wlc_algolia_autosuggestion, false ); ?> />
					<span class="wlc-algolia-toggle-slider"></span>
				</label>
			</td>
			<td class="index-name">
				<?php echo esc_html( $index_name . '_' . $wlc_algolia_post_type_slug ); ?>
			</td>
			<td class="custom-index-name">
				<input type="text" name="wlc_algolia_settings_<?php echo esc_attr( $settings_tab ); ?>[<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>_custom_index]" id="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>_custom_index" value="<?php echo esc_attr( $wlc_algolia_custom_index ); ?>" class="wlc-algolia-custom-index-input" placeholder="" />
			</td>
			<td class="status">
				<div class="wlc-post-type-progress">
					<div class="wlc-progress-bar-container">
						<div class="wlc-progress-bar progress-bar-<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>" style="width:0%"></div>
					</div>
					<div class="wlc-progress-text progress-text-<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>">0%</div>
				</div>
			</td>
			<td class="index-button">
				<button data-post-type="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>" type="button" data-index-name="<?php echo esc_html( $index_name . '_' . $wlc_algolia_post_type_slug ); ?>" class="btn btn-primary index-post-type" name="<?php echo esc_attr( $wlc_algolia_post_type_slug ); ?>">
					<?php echo esc_html( 'Index ' . $wlc_algolia_post_type_label ); ?>
				</button>
			</td>
		</tr>
		<?php
	}
	?>
	</tbody>
</table>

	<?php
} )( get_defined_vars() );
?>
