<?php
/**
 * Notice Class
 *
 * @package errigal
 * @since 1.1.0
 */

namespace Errigal\Admin;

defined( 'ABSPATH' ) || exit;

use Errigal\Admin\Errigal_Admin as Admin;
use Errigal\Shared\{
	Errigal_Theme_Info as Theme_Info,
	Errigal_Validator as Validator,
};

/**
 * This class is in charge of providing notice settings and functions.
 *
 * @since 1.1.0
 */
class Errigal_Notice {
	/**
	 * ID.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const ID = 'notice_id';

	/**
	 * Title.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const TITLE = 'notice_title';

	/**
	 * Section: What's new.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const SECTION_NEW = 'section_new';

	/**
	 * Section: Why not try.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const SECTION_TRY = 'section_try';

	/**
	 * Tagline.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const TAGLINE = 'tagline';

	/**
	 * Icon.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const ICON = 'icon';

	/**
	 * Notification type.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const NOTIFICATION_TYPE = 'notification_type';

	/**
	 * Notification type: Updated.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const NOTIFICATION_TYPE_UPDATED = 'notification_type_updated';

	/**
	 * Notification content.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const NOTIFICATION_CONTENT = 'notification_content';

	/**
	 * Item title.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const ITEM_TITLE = 'item_title';

	/**
	 * Item description.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const ITEM_DESCRIPTION = 'item_description';

	/**
	 * Item instructions.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const ITEM_INSTRUCTIONS = 'item_instructions';

	/**
	 * CTA: Customiser URL.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CTA_CUSTOMISER_URL = 'cta_customiser_url';

	/**
	 * CTA: Customiser Text.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CTA_CUSTOMISER_TEXT = 'cta_customiser_text';

	/**
	 * CTA: Documentation URL.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CTA_DOCUMENTATION_URL = 'cta_documentation_url';

	/**
	 * CTA: Documentation Text.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CTA_DOCUMENTATION_TEXT = 'cta_documentation_text';

	/**
	 * Supported notification types.
	 *
	 * @since 1.1.0
	 *
	 * @var string[]
	 */
	private const SUPPORTED_NOTIFICATION_TYPES = array(
		self::NOTIFICATION_TYPE_UPDATED,
	);

	/**
	 * Determines whether notice can be displayed.
	 *
	 * @since 1.1.0
	 *
	 * @param string[] $notice_pages Pages where notice can be displayed.
	 * @return bool
	 */
	public static function can_show( $notice_pages ) {
		return Validator::has_string_list_item(
			$notice_pages,
			Admin::get_current_page()
		);
	}

	/**
	 * Gets section heading.
	 *
	 * @since 1.1.0
	 *
	 * @param string $section Section.
	 * @return string
	 */
	public static function get_section_heading( $section ) {
		if ( ! Validator::is_non_empty_string( $section ) ) {
			return '';
		}

		switch ( $section ) {
			case self::SECTION_NEW:
				return esc_html__( "What's new", 'errigal' );
			case self::SECTION_TRY:
				return esc_html__( 'Why not try', 'errigal' );
			default:
				return '';
		}
	}

	/**
	 * Determines whether notification type is supported.
	 *
	 * @since 1.1.0
	 *
	 * @param string $notification_type Notification type.
	 * @return bool
	 */
	public static function is_supported_notification_type( $notification_type ) {
		return Validator::has_string_list_item(
			self::SUPPORTED_NOTIFICATION_TYPES,
			$notification_type
		);
	}
}
