<?php
/**
 * Template part for displaying post tags
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Component_Class as Component_Class,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
	Errigal_Shared_Class as Shared_Class,
};
use Errigal\Content\Errigal_Content as Content;
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

if ( ! has_tag() ) {
	return;
}

Html_Builder::create()->create_ul(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => 'post-tags',
			Html_Attr::ARIA_LABEL => __( 'Tags', 'errigal' ),
		),
	)
)->render_element(
	function ( $html_builder ) {
		if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
			return;
		}

		foreach ( get_the_tags() as $post_tag ) {
			if ( ! Content::is_wp_term( $post_tag ) ) {
				continue;
			}

			$html_builder->create_li()->render_element(
				function ( $html_builder ) use ( $post_tag ) {
					if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
						return;
					}

					$html_builder->create_a(
						array(
							Html_Option::ATTRS => array(
								Html_Attr::CLASS_NAME => array(
									Component_Class::CHIP,
									Shared_Class::SECONDARY,
								),
								Html_Attr::HREF       => get_tag_link( $post_tag ),
								Html_Attr::REL        => 'tag',
							),
						)
					)->render_element(
						esc_html( $post_tag->name )
					);
				}
			);
		}
	}
);
