<?php
/**
 * Dynamic Tag: Archive Description
 *
 * @package captain-widgets-kit
 * @since   1.1.0
 */

use Elementor\Core\DynamicTags\Tag;
use Elementor\Modules\DynamicTags\Module;
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
/**
 * Class Captwiki_Tag_Archive_Description
 * Outputs the current archive description (category/tag/author/post-type).
 */
class Captwiki_Tag_Archive_Description extends Tag {
	/**
	 * Get tag name.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-tag-archive-description'; }
	/**
	 * Get tag title.
	 *
	 * @return string
	 */
	public function get_title(): string {
		return esc_html__( 'Archive Description', 'captain-widgets-kit' ); }
	/**
	 * Get tag group.
	 *
	 * @return array
	 */
	public function get_group(): array {
		return array( 'captwiki-archive' ); }
	/**
	 * Get tag categories.
	 *
	 * @return array
	 */
	public function get_categories(): array {
		return array( Module::TEXT_CATEGORY ); }
	/**
	 * Register tag controls.
	 *
	 * @return void
	 */
	protected function register_controls(): void {}
	/**
	 * Handle register advanced section.
	 *
	 * @return void
	 */
	protected function register_advanced_section(): void {}
	/**
	 * Render tag output.
	 *
	 * @return void
	 */
	public function render(): void {
		$value = '';
		if ( is_category() || is_tag() || is_tax() ) {
			$term = get_queried_object();
			if ( $term && ! empty( $term->description ) ) {
				$value = wpautop( $term->description ); }
		} elseif ( is_author() ) {
			$value = get_the_author_meta( 'description', get_queried_object_id() );
		} elseif ( is_post_type_archive() ) {
			$pt = get_queried_object();
			if ( $pt && ! empty( $pt->description ) ) {
				$value = wpautop( $pt->description ); }
		}
		echo wp_kses_post( $value );
	}
}
