<?php //phpcs:disable
/**
 * The file contains definition of WLC_Algolia class
 *
 * @package WLC\Algolia
 */
namespace wlc_algolia;

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

/**
 * Enqueues class
 */
class Enqueues {
 //phpcs:enable
	/**
	 * Init Hooks.
	 *
	 * @return void
	 */
	public function hooks(): void {
		add_action( 'admin_enqueue_scripts', array( $this, 'wlc_admin_styles' ) );
		add_action( 'admin_enqueue_scripts', array( $this, 'wlc_admin_scripts' ) );
	}

	/**
	 * Admin Styles.
	 *
	 * @param string $hook_suffix Current admin page hook suffix.
	 *
	 * @return void
	 */
	public function wlc_admin_styles( string $hook_suffix = '' ): void {
		// Only load on the plugin admin screen.
		if ( 'toplevel_page_wlc-algolia' !== $hook_suffix ) {
			return;
		}

		wp_enqueue_style(
			'wlc-algolia-admin-boilerplate',
			WLC_ALGOLIA_PLUGIN_DIR_URL . '/assets/css/wlc-admin-boilerplate.css',
			array(),
			WLC_ALGOLIA_PLUGIN_CURRENT_VERSION
		);

		wp_enqueue_style(
			'wlc-algolia-admin-styles',
			WLC_ALGOLIA_PLUGIN_DIR_URL . '/assets/css/algolia-admin.css',
			array( 'wlc-algolia-admin-boilerplate' ),
			WLC_ALGOLIA_PLUGIN_CURRENT_VERSION
		);
	}

	/**
	 * Admin Scripts.
	 *
	 * @param string $hook_suffix Current admin page hook suffix.
	 *
	 * @return void
	 */
	public function wlc_admin_scripts( string $hook_suffix = '' ): void {
		// Only load on the plugin admin screen.
		if ( 'toplevel_page_wlc-algolia' !== $hook_suffix ) {
			return;
		}

		wp_enqueue_script(
			'wlc-algolia-admin-scripts',
			WLC_ALGOLIA_PLUGIN_DIR_URL . '/assets/js/algolia-admin.js',
			array(
				'jquery',
			),
			WLC_ALGOLIA_PLUGIN_CURRENT_VERSION,
			true
		);

		wp_enqueue_script(
			'wlc-algolia-admin-toggles',
			WLC_ALGOLIA_PLUGIN_DIR_URL . '/assets/js/wlc-algolia-admin-toggles.js',
			array(),
			WLC_ALGOLIA_PLUGIN_CURRENT_VERSION,
			true
		);

		wp_localize_script(
			'wlc-algolia-admin-scripts',
			'wlc_algolia',
			array(
				'ajax_url'       => esc_url( admin_url( 'admin-ajax.php' ) ),
				'nonce'          => wp_create_nonce( 'wlc_algolia_post_index' ),
				'cpt_nonce'      => wp_create_nonce( 'wlc_algolia_post_type_index' ),
				'progress_nonce' => wp_create_nonce( 'wlc_algolia_index_progress' ),
			)
		);
	}
}
