<?php
/**
 * Dynamic Tag: DC Term URL
 *
 * @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_DC_Term_URL
 * Outputs the archive URL of the current term in a Dynamic Categories loop.
 */
class Captwiki_Tag_DC_Term_URL extends Tag {
	/**
	 * Get tag name.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-tag-dc-term-url'; }
	/**
	 * Get tag title.
	 *
	 * @return string
	 */
	public function get_title(): string {
		return esc_html__( 'DC Term URL', 'captain-widgets-kit' ); }
	/**
	 * Get tag group.
	 *
	 * @return array
	 */
	public function get_group(): array {
		return array( 'captwiki-dc' ); }
	/**
	 * Get tag categories.
	 *
	 * @return array
	 */
	public function get_categories(): array {
		return array( Module::URL_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 {
		$term = null;
		if ( isset( $GLOBALS['captwiki_current_dc_term'] ) && $GLOBALS['captwiki_current_dc_term'] instanceof \WP_Term ) {
			$term = $GLOBALS['captwiki_current_dc_term'];
		} else {
			$queried = get_queried_object();
			if ( $queried instanceof \WP_Term ) {
				$term = $queried; }
		}
		if ( $term ) {
			$link = get_term_link( $term );
			if ( ! is_wp_error( $link ) ) {
				echo esc_url( $link ); }
		}
	}
}
