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

namespace Errigal\Shared;

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Html_Tag as Html_Tag,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Shared\{
	Errigal_Html_Element as Html_Element,
	Errigal_Html_Html_Element as Html_Html_Element,
	Errigal_Html_Schema as Html_Schema,
	Errigal_Utility as Utility,
};
/**
 * This class is in charge of providing HTML builder functions.
 *
 * @since 1.2.0
 */
class Errigal_Html_Builder extends Errigal_Html_Builder_Base {
	/**
	 * Creates a element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_a( $args = array() ) {
		return $this->create_element(
			Html_Tag::A,
			$args,
			Html_Schema::get_allowed_html_svg()
		);
	}

	/**
	 * Creates article element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_article( $args = array() ) {
		return $this->create_element( Html_Tag::ARTICLE, $args );
	}

	/**
	 * Creates aside element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_aside( $args = array() ) {
		return $this->create_element( Html_Tag::ASIDE, $args );
	}

	/**
	 * Creates b element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_b( $args = array() ) {
		return $this->create_element( Html_Tag::B, $args );
	}

	/**
	 * Creates body element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_body( $args = array() ) {
		return $this->create_element(
			Html_Tag::BODY,
			$args,
			Html_Schema::get_allowed_html_body()
		);
	}

	/**
	 * Creates button element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_button( $args = array() ) {
		return $this->create_element(
			Html_Tag::BUTTON,
			$args,
			Html_Schema::get_allowed_html_svg()
		);
	}

	/**
	 * Creates div element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_div( $args = array() ) {
		return $this->create_element(
			Html_Tag::DIV,
			$args,
			Html_Schema::get_allowed_html_svg()
		);
	}

	/**
	 * Creates figcaption element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_figcaption( $args = array() ) {
		return $this->create_element( Html_Tag::FIGCAPTION, $args );
	}

	/**
	 * Creates figure element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_figure( $args = array() ) {
		return $this->create_element( Html_Tag::FIGURE, $args );
	}

	/**
	 * Creates footer element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_footer( $args = array() ) {
		return $this->create_element( Html_Tag::FOOTER, $args );
	}

	/**
	 * Creates form element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_form( $args = array() ) {
		return $this->create_element(
			Html_Tag::FORM,
			$args,
			Utility::array_merge_deep(
				Html_Schema::get_allowed_html_form(),
				Html_Schema::get_allowed_html_input(),
				Html_Schema::get_allowed_html_svg()
			)
		);
	}

	/**
	 * Creates h1 element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_h1( $args = array() ) {
		return $this->create_element( Html_Tag::H1, $args );
	}

	/**
	 * Creates h2 element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_h2( $args = array() ) {
		return $this->create_element( Html_Tag::H2, $args );
	}

	/**
	 * Creates h3 element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_h3( $args = array() ) {
		return $this->create_element( Html_Tag::H3, $args );
	}

	/**
	 * Creates h4 element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_h4( $args = array() ) {
		return $this->create_element( Html_Tag::H4, $args );
	}

	/**
	 * Creates head element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_head( $args = array() ) {
		return $this->create_element(
			Html_Tag::HEAD,
			$args,
			Html_Schema::get_allowed_html_head()
		);
	}

	/**
	 * Creates header element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_header( $args = array() ) {
		return $this->create_element( Html_Tag::HEADER, $args );
	}

	/**
	 * Creates html element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_html( $args = array() ) {
		return $this->create_element(
			Html_Tag::HTML,
			array_merge(
				$args,
				array(
					Html_Option::HTML_ELEMENT_CLASS => Html_Html_Element::class,
				)
			),
			Html_Schema::get_allowed_html_html()
		);
	}

	/**
	 * Creates img element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_img( $args = array() ) {
		return $this->create_element( Html_Tag::IMG, $args );
	}

	/**
	 * Creates input element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_input( $args = array() ) {
		return $this->create_element(
			Html_Tag::INPUT,
			$args,
			Html_Schema::get_allowed_html_input()
		);
	}

	/**
	 * Creates label element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_label( $args = array() ) {
		return $this->create_element( Html_Tag::LABEL, $args );
	}

	/**
	 * Creates li element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_li( $args = array() ) {
		return $this->create_element(
			Html_Tag::LI,
			$args,
			Html_Schema::get_allowed_html_svg()
		);
	}

	/**
	 * Creates link element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_link( $args = array() ) {
		return $this->create_element(
			Html_Tag::LINK,
			$args,
			Html_Schema::get_allowed_html_link()
		);
	}

	/**
	 * Creates main element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_main( $args = array() ) {
		return $this->create_element(
			Html_Tag::MAIN,
			$args,
			Html_Schema::get_allowed_html_main()
		);
	}

	/**
	 * Creates meta element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_meta( $args = array() ) {
		return $this->create_element(
			Html_Tag::META,
			$args,
			Html_Schema::get_allowed_html_meta()
		);
	}

	/**
	 * Creates nav element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_nav( $args = array() ) {
		return $this->create_element(
			Html_Tag::NAV,
			$args,
			Html_Schema::get_allowed_html_svg()
		);
	}

	/**
	 * Creates ol element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_ol( $args = array() ) {
		return $this->create_element( Html_Tag::OL, $args );
	}

	/**
	 * Creates p element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_p( $args = array() ) {
		return $this->create_element( Html_Tag::P, $args );
	}

	/**
	 * Creates section element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_section( $args = array() ) {
		return $this->create_element( Html_Tag::SECTION, $args );
	}

	/**
	 * Creates span element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_span( $args = array() ) {
		return $this->create_element( Html_Tag::SPAN, $args );
	}

	/**
	 * Creates strong element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_strong( $args = array() ) {
		return $this->create_element( Html_Tag::STRONG, $args );
	}

	/**
	 * Creates textarea element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_textarea( $args = array() ) {
		return $this->create_element( Html_Tag::TEXTAREA, $args );
	}

	/**
	 * Creates time element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_time( $args = array() ) {
		return $this->create_element(
			Html_Tag::TIME,
			$args,
			Html_Schema::get_allowed_html_time()
		);
	}

	/**
	 * Creates ul element.
	 *
	 * @since 1.2.0
	 *
	 * @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.
	 * }
	 * @return Html_Element
	 */
	public function create_ul( $args = array() ) {
		return $this->create_element( Html_Tag::UL, $args );
	}
}
