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

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

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

class Softech_Post_Custom_Field extends Tag {
    
    public function get_name() {
        return 'softech-post-custom-field';
    }
    
    public function get_title() {
        return esc_html__( 'Post Custom Field', 'softech-addons-for-elementor' );
    }
    
    public function get_group() {
        return Softech_Post_Group::get_name();
    }
    
    public function get_categories() {
        return [ Module::TEXT_CATEGORY, Module::POST_META_CATEGORY ];
    }
    
    protected function register_controls() {
        $this->add_control(
            'key',
            [
                'label' => esc_html__( 'Key', 'softech-addons-for-elementor' ),
                'type' => Controls_Manager::TEXT,
            ]
        );
    }
    
    public function render() {
        $key = $this->get_settings( 'key' );
        
        if ( empty( $key ) ) {
            return;
        }
        
        $value = get_post_meta( get_the_ID(), $key, true );
        
        echo wp_kses_post( $value );
    }
}