<?php 
namespace Softech_Addons_for_Elementor\Includes\Dynamic_Tags\Tags\Post_Tags;

use Elementor\Core\DynamicTags\Tag;
use Elementor\Modules\DynamicTags\Module;
use Softech_Addons_for_Elementor\Includes\Dynamic_Tags\Groups\Softech_Post_Group;

if ( ! defined( 'ABSPATH' ) ) exit;

class Softech_Post_Title extends Tag {
    
    public function get_name() {
        return 'softech-post-title';
    }
    
    public function get_title() {
        return esc_html__( 'Post / Term Title', 'softech-addons-for-elementor' );
    }
    
    public function get_group() {
        return Softech_Post_Group::get_name(); 
    }
    
    public function get_categories() {
        return [ Module::TEXT_CATEGORY ];
    }
    
    public function render() {

        $queried_object = get_queried_object();

        // Taxonomy term title
        if ( $queried_object instanceof \WP_Term ) {
            echo wp_kses_post( $queried_object->name );
            return;
        }

        // Post title
        echo wp_kses_post( get_the_title() );
    }
}