<?php
/**
 * Custom Heading Style Class
 *
 * @package errigal
 * @since 1.1.0
 */

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Shared\{
	Errigal_Utility as Utility,
	Errigal_Validator as Validator,
};

/**
 * This class is in charge of providing heading style settings and functions.
 *
 * @since 1.1.0
 */
class Errigal_Custom_Heading_Style extends Errigal_Custom_Base {
	/**
	 * Setting ID: Heading style.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const ID_HEADING_STYLE = 'heading_style';

	/**
	 * Heading style: Standard.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const HEADING_STYLE_STANDARD = 'standard';

	/**
	 * Heading style: Simple.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const HEADING_STYLE_SIMPLE = 'simple';

	/**
	 * Default setting value: Heading style.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const DEFAULT_HEADING_STYLE = self::HEADING_STYLE_STANDARD;

	/**
	 * Heading style suffix.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	private const HEADING_STYLE_SUFFIX = 'headings';

	/**
	 * Gets heading style class.
	 *
	 * @since 1.1.0
	 *
	 * @return string
	 */
	public static function get_heading_style_class() {
		return Utility::get_class( self::get_heading_style_name() );
	}

	/**
	 * Gets editor theme stylesheet file name suffix.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public static function get_editor_theme_stylesheet_file_name_suffix() {
		return self::is_default_heading_style()
			? ''
			: self::get_heading_style_name();
	}

	/**
	 * Gets heading style.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	private static function get_heading_style() {
		return self::get_theme_mod_string(
			self::ID_HEADING_STYLE,
			self::DEFAULT_HEADING_STYLE
		);
	}

	/**
	 * Gets heading style name.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	private static function get_heading_style_name() {
		$heading_style = self::get_heading_style();

		if ( ! Validator::is_non_empty_string( $heading_style ) ) {
			return '';
		}

		return sanitize_key(
			Utility::join(
				Utility::SEPARATOR_HYPHEN,
				$heading_style,
				self::HEADING_STYLE_SUFFIX
			)
		);
	}

	/**
	 * Determines whether heading style is default.
	 *
	 * @since 1.1.0
	 *
	 * @return bool
	 */
	private static function is_default_heading_style() {
		return self::DEFAULT_HEADING_STYLE === self::get_heading_style();
	}
}
