<?php
/**
 * Dynamic Tag: Product Purchase Note.
 *
 * @package captain-widgets-kit
 */

use Elementor\Core\DynamicTags\Tag;
use Elementor\Modules\DynamicTags\Module;
if ( ! defined( 'ABSPATH' ) ) {
	exit;
	// Exit if accessed directly.
}

/**
 * Plus Addons Dynamic Tag - Product Purchase Note
 *
 * Provides a dynamic tag for Elementor to output the current product purchase note.
 *
 * @since 6.4.5
 */
class Captwiki_Tag_Product_Purchase_Note extends Tag {


	/**
	 * Unique dynamic tag name used internally by Elementor.
	 *
	 * @since 6.4.5
	 * @return string
	 */
	public function get_name(): string {

		return 'captwiki-tag-product-purchase-note';
	}

	/**
	 * Label shown in Elementor Dynamic Tags list.
	 *
	 * @since 6.4.5
	 * @return string
	 */
	public function get_title(): string {

		return esc_html__( 'Product Purchase Note', 'captain-widgets-kit' );
	}

	/**
	 * Registers the group under which this tag will appear.
	 *
	 * @since 6.4.5
	 * @return array
	 */
	public function get_group(): array {

		return array( 'captwiki-woocommerce' );
	}

	/**
	 * Defines the category type (Text) for this dynamic tag.
	 *
	 * @since 6.4.5
	 * @return array
	 */
	public function get_categories(): array {

		return array(
			Module::TEXT_CATEGORY,
		);
	}

	/**
	 * Register controls for this dynamic tag.
	 *
	 * @since 6.4.5
	 * @return void
	 */
	protected function register_controls(): void {}

	/**
	 * Render the dynamic product title on frontend.
	 *
	 * Gets the current product ID and prints its title.
	 *
	 * @since 6.4.5
	 * @return void
	 */
	public function render(): void {

		$product_id = get_the_ID();

		if ( ! $product_id ) {
			return;
		}

		$product = wc_get_product( $product_id );

		if ( ! $product ) {
			return;
		}

		$note = $product->get_purchase_note();

		if ( empty( $note ) ) {
			return;
		}

		$note = wpautop( do_shortcode( wp_kses_post( $note ) ) );

		echo wp_kses_post( $note );
	}
}
