<?php
/**
 * Post Tag Class
 *
 * @package Wira
 * @since 1.0.0
 */

namespace Wira\Templates;

if ( ! class_exists( 'Post_Tags' ) ) {

	/**
	 * Class to render the Post tags.
	 */
	class Post_Tags {

		/**
		 * Tags
		 *
		 * @since 1.0.0
		 * @var string
		 */
		protected $tags;

		/**
		 * Constructor.
		 *
		 * @since 1.0.0
		 */
		public function __construct() {
			$this->tags = get_the_tags();
		}

		/**
		 * Render the Post tags
		 *
		 * @return string
		 */
		public function render() {
			if ( $this->tags && is_array( $this->tags ) ) {
				ob_start();

				/**
				 * Post Tags Wrapper
				 */
				echo '<div class="post-tags d-flex align-items-center flex-wrap">';
				echo '<i class="fas fa-tags theme-color-primary me-1"></i>';
				echo '<strong class="d-inline me-3 theme-small-title theme-color-heading">' . esc_html__( 'Tags:', 'wira' ) . '</strong>';

				/**
				 * Get Post tags
				 */
				foreach ( $this->tags as $tag ) {
					echo '<a class="me-2 mt-md-0 mt-2 theme-btn-post-tag" href="' . esc_url( get_tag_link( $tag->term_id ) ) . '">';
					echo esc_html( $tag->name );
					echo '</a>';
				}

				echo '</div>';

				return ob_get_clean();
			}

			return '';
		}
	}
}
