<?php
/**
 * Html Html Element Class
 *
 * @package errigal
 * @since 1.2.0
 */

namespace Errigal\Shared;

defined( 'ABSPATH' ) || exit;

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

/**
 * This class is in charge of providing HTML HTML element functions.
 *
 * @since 1.2.0
 */
class Errigal_Html_Html_Element extends Errigal_Html_Element {
	/**
	 * Constructor.
	 *
	 * @since 1.2.0
	 *
	 * @param Html_Builder $html_builder Instance of Html builder.
	 * @param string       $tag          Tag name.
	 * @param array        $args {
	 *     Optional. Associative array of arguments for HTML element. Default empty array.
	 *
	 *     @type array  $attrs        HTML attributes.
	 *     @type array  $allowed_html Allowed HTML elements and attributes.
	 * }
	 */
	public function __construct( $html_builder, $tag, $args = array() ) {
		parent::__construct(
			$html_builder,
			Html_Tag::HTML,
			$args
		);
	}

	/**
	 * Gets open tag.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_open_tag() {
		if ( ! Validator::is_non_empty_string( $this->tag ) ) {
			return '';
		}

		$language_attributes = get_language_attributes();
		$language_attributes = Validator::is_non_empty_string( $language_attributes )
			? Utility::SEPARATOR_SPACE . $language_attributes
			: '';

		return '<!DOCTYPE html>' .
			$this->kses(
				sprintf(
					'<%1$s%2$s%3$s>',
					tag_escape( $this->tag ),
					$language_attributes,
					$this->get_attributes()
				)
			);
	}
}
