<?php
/**
 * Goodmeet_Gutenberg Class
 *
 * This class manages the frontend functionality for the goodmeet plugin.
 *
 * @package SOVLIX\GOODMEET
 */

namespace SOVLIX\GOODMEET;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Goodmeet_Gutenberg' ) ) {
	/**
	 * Goodmeet_Gutenberg Class
	 *
	 * Handles frontend-related tasks and functionality for the goodmeet plugin.
	 *
	 * @since 1.0.0
	 */
	class Goodmeet_Gutenberg {

		/**
		 * Goodmeet_Gutenberg constructor.
		 *
		 * Initializes the frontend class.
		 */
		public function __construct() {
			add_action( 'enqueue_block_editor_assets', array( $this, 'register_block_assets' ) );
			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) );
		}

		/**
		 * Register block assets.
		 *
		 * Enqueues block editor script and styles.
		 *
		 * @since 1.0.0
		 */
		public function register_block_assets() {
			// Enqueue block editor script.
			wp_enqueue_script(
				'goodmeet_gutenberg-editor',
				GOODMEET_ASSETS . '/dist/block.build.js',
				array( 'wp-blocks', 'wp-components', 'wp-editor' ),
				filemtime( GOODMEET_PATH . '/assets/dist/block.build.js' ),
				true
			);

			// Localize script with zoom_users data.
			wp_localize_script(
				'goodmeet_gutenberg-editor',
				'goodmeetGutenbergData',
				array(
					'ajax_url' => admin_url( 'admin-ajax.php' ),
					'nonce'    => wp_create_nonce( 'goodmeet_admin_nonce' ),
				)
			);

			wp_enqueue_style(
				'goodmeet_gutenberg-editor-style',
				GOODMEET_ASSETS . '/dist/block.build.css',
				array( 'wp-edit-blocks' ),
				filemtime( GOODMEET_PATH . '/assets/dist/block.build.css' ),
				null
			);
		}

		/**
		 * Enqueue frontend assets.
		 *
		 * Enqueues frontend styles.
		 *
		 * @since 1.0.0
		 */
		public function enqueue_frontend_assets() {
			wp_enqueue_style(
				'goodmeet_frontend-style',
				GOODMEET_ASSETS . '/dist/block.build.css',
				array(),
				filemtime( GOODMEET_PATH . '/assets/dist/block.build.css' )
			);
		}
	}
}
