<?php

/**
 * Flo Guten Blocks Archive Title.
 *
 * @package FBG
 */

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

if (!class_exists('Flo_Guten_Blocks_Archive_Title_Block')) {

	/**
	 * Class Flo_Guten_Blocks_Archive_Title_Block.
	 */
	final class Flo_Guten_Blocks_Archive_Title_Block
	{
		/**
		 * Member Variable
		 *
		 * @var instance
		 */
		private static $instance;

		/**
		 *  Initiator
		 */
		public static function get_instance()
		{
			if (!isset(self::$instance)) {
				self::$instance = new self();
			}
			return self::$instance;
		}

		/**
		 * Constructor
		 */
		public function __construct()
		{
			add_action('init', array($this, 'register_block'), 100);
		}

		public function register_block()
		{
			register_block_type('flo-block/archive-title', array(
				'attributes' => $this->get_attributes(),
				'render_callback' => array($this, 'render_callback')
			));
		}

		public function get_attributes()
		{
			return array(
				'title'       => array(
					'type'    => 'string',
					'default' => '%Taxonomy%: %Term_Title%',
				),
				'titleColor'            => array(
					'type'    => 'object',
					'default' => array(
						'custom' => '',
						'theme' => 'scheme_1/text/default'
					),
				),
				'titleTypography' => array(
					'type'    => 'object',
					'default' => Flo_Guten_Blocks_Helper::get_default_typography_attributes('title_2/large')
				),

				'displayDescription'         => array(
					'type'    => 'boolean',
					'default' => TRUE,
				),
				'descriptionColor'            => array(
					'type'    => 'object',
					'default' => array(
						'custom' => '',
						'theme' => 'scheme_1/text/default'
					),
				),
				'descriptionTypography' => array(
					'type'    => 'object',
					'default' => Flo_Guten_Blocks_Helper::get_default_typography_attributes('second_level/paragraph')
				),

				'marginTop' => array(
					'type'    => 'number',
					'default' => 0,
				),
				'marginBottom' => array(
					'type'    => 'number',
					'default' => 0,
				),
				'mobileMarginTop' => array(
					'type'    => 'number',
					'default' => 0,
				),
				'mobileMarginBottom' => array(
					'type'    => 'number',
					'default' => 0,
				),
				'anchor'  => array(
					'type'    => 'string',
					'default' => '',
				),
				'className'  => array(
					'type'    => 'string',
					'default' => '',
				),
				'blockKey'  => array(
					'type'    => 'string',
					'default' => '',
				),
			);
		}
		public function render_callback($attributes)
		{
			ob_start();
			include dirname(__FILE__) . '/views/html-archive-title.php';
			return ob_get_clean();
		}
	}

	Flo_Guten_Blocks_Archive_Title_Block::get_instance();
}
