<?php
/**
 * UpSolution Core Integration Class
 *
 * @package Page_Generator_Pro
 * @author WP Zinc
 */

/**
 * Registers UpSolution Core as a Plugin integration:
 * - Registers TinyMCE Plugins in the Live Editor
 * - Copy / don't copy metadata to generated Pages, depending on if the integration is active
 * - Copy metadata to generated Pages
 *
 * @package Page_Generator_Pro
 * @author  WP Zinc
 * @version 5.5.3
 */
class Page_Generator_Pro_US_Core extends Page_Generator_Pro_Integration {

	/**
	 * Holds the base object.
	 *
	 * @since   5.5.3
	 *
	 * @var     object
	 */
	public $base;

	/**
	 * Constructor
	 *
	 * @since   5.5.3
	 *
	 * @param   object $base    Base Plugin Class.
	 */
	public function __construct( $base ) {

		// Store base class.
		$this->base = $base;

		// Enqueue TinyMCE Assets.
		add_action( 'usb_enqueue_assets_for_builder', array( $this, 'enqueue_tinymce_assets' ) );

	}

	/**
	 * Enqueue CSS, JS and re-register TinyMCE Plugins, so TinyMCE Plugins etc. work,
	 * as US Core removes actions hooked to admin_enqueue_scripts, wp_enqueue_scripts, mce_external_plugins, mce_buttons
	 *
	 * @since   5.5.3
	 */
	public function enqueue_tinymce_assets() {

		// Load Plugin CSS/JS.
		$this->base->get_class( 'admin' )->admin_scripts_css();

		// Add filters to register TinyMCE Plugins.
		// Low priority ensures this works with Frontend Page Builders.
		add_filter( 'mce_external_plugins', array( $this->base->get_class( 'editor' ), 'register_tinymce_plugins' ), 99999 );
		add_filter( 'mce_buttons', array( $this->base->get_class( 'editor' ), 'register_tinymce_buttons' ), 99999 );

	}

}
