<?php //phpcs:disable
/**
 * Class responsible for indexing in Algolia.
 *
 * @package WLC_Algolia
 */
namespace wlc_algolia;

defined( 'ABSPATH' ) || die( 'Direct file access is forbidden' );

/**
 * Algolia_Index class.
 */
class Algolia_Metabox {
 //phpcs:enable
	/**
	 * Init hooks.
	 *
	 * @return void
	 */
	public function hooks(): void {
		add_action( 'add_meta_boxes', array( $this, 'wlc_algolia_metabox' ) );
	}

	/**
	 * Render Metabox For Indexing.
	 *
	 * @return void
	 */
	public function wlc_algolia_metabox(): void {
		add_meta_box(
			'custom_meta_box',
			__( 'Algolia Indexing', 'wlc-search-integration-with-algolia' ),
			array( $this, 'wlc_render_custom_algolia_meta_box' ),
			'post',
			'side',
			'core'
		);
	}

	/**
	 * Algolia Index Metabox.
	 *
	 * @param \WP_Post $post WP Post.
	 *
	 * @return void
	 */
	public function wlc_render_custom_algolia_meta_box( \WP_Post $post ): void {
		?>
		<div class="algolia-metabox">
			<div class="button-container">
				<input type="hidden" class="algolia-post-index" name="post_ID" value="<?php echo esc_attr( $post->ID ); ?>" />
				<button type="button" class="btn btn-primary algolia_post_index">
					<?php esc_html_e( 'Index Post', 'wlc-search-integration-with-algolia' ); ?>
				</button>
				<div class="algolia-update-message"><p class="algolia-message "></p></div>
			</div>
		</div>
		<?php
	}
}
