<?php
/**
 * Gutenberg Plugin Sidebar class.
 *
 * @package Page_Generator_Pro
 * @author WP Zinc
 */

/**
 * Registers a Plugin Sidebar with Gutenberg.
 *
 * @package Page_Generator_Pro
 * @author  WP Zinc
 */
class Page_Generator_Pro_Gutenberg_Plugin_Sidebar {

	/**
	 * Registers this plugin sidebar with the Plugin.
	 *
	 * @since   5.5.5
	 *
	 * @param   array $plugin_sidebars     Plugin Sidebars to Register.
	 * @return  array               Plugin Sidebars to Register
	 */
	public function register( $plugin_sidebars ) {

		$plugin_sidebars[ $this->get_name() ] = array(
			'name'               => $this->get_name(),
			'minimum_capability' => $this->get_minimum_capability(),
			'title'              => $this->get_title(),
			'fields'             => $this->get_fields(),
			'attributes'         => $this->get_attributes(),
			'default_values'     => $this->get_default_values(),
		);

		return $plugin_sidebars;

	}

	/**
	 * Returns this plugin sidebar's meta key.
	 *
	 * @since   5.5.5
	 */
	public function get_name() {

		return '';

	}

	/**
	 * Returns this plugin sidebar's minimum capability required
	 * for displaying and permitting edits to the settings.
	 *
	 * @since   5.5.5
	 *
	 * @return  string
	 */
	public function get_minimum_capability() {

		return 'edit_posts';

	}

	/**
	 * Returns this plugin sidebar's title.
	 *
	 * @since   5.5.5
	 */
	public function get_title() {

		return '';

	}

	/**
	 * Returns this plugin sidebar's attributes.
	 *
	 * @since   5.5.5
	 *
	 * @return  array
	 */
	public function get_attributes() {

		return array();

	}

	/**
	 * Returns this plugin sidebar's Fields
	 *
	 * @since   5.5.5
	 *
	 * @return  array
	 */
	public function get_fields() {

		return array();

	}

	/**
	 * Returns this plugin sidebar's Default Values
	 *
	 * @since   5.5.5
	 *
	 * @return  array
	 */
	public function get_default_values() {

		return array();

	}

	/**
	 * Returns the given plugin sidebar's field's Default Value
	 *
	 * @since   5.5.5
	 *
	 * @param   string $field Field Name.
	 * @return  string
	 */
	public function get_default_value( $field ) {

		$defaults = $this->get_default_values();
		if ( isset( $defaults[ $field ] ) ) {
			return $defaults[ $field ];
		}

		return '';

	}

	/**
	 * Determines if the request is a WordPress REST API request
	 * made by a logged in WordPress user who has the capability to edit posts.
	 *
	 * @since   5.5.5
	 *
	 * @return  bool
	 */
	public function is_admin_rest_request() {

		return defined( 'REST_REQUEST' ) && REST_REQUEST && current_user_can( 'edit_posts' );

	}

}
