<?php
/**
 * Livada SEO — Elementor Dynamic Tag: Breadcrumbs
 *
 * Exposes the Livada SEO breadcrumb trail as an Elementor dynamic tag so it
 * can be dropped into any Text widget or HTML widget inside the editor.
 * Output is captured from the global livada_seo_breadcrumbs() helper (which
 * echoes HTML + inline JSON-LD) and returned to Elementor for rendering.
 *
 * @package Livada_SEO
 */

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

class Livada_SEO_Breadcrumbs_Tag extends \Elementor\Core\DynamicTags\Tag {

	/**
	 * Returns the unique machine name of this tag.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'livada-breadcrumbs';
	}

	/**
	 * Returns the human-readable label shown in the Elementor tag picker.
	 *
	 * @return string
	 */
	public function get_title(): string {
		return 'Livada Breadcrumbs';
	}

	/**
	 * Returns the group key this tag belongs to.
	 * Must match the group registered in Livada_SEO_Elementor::register_tags().
	 *
	 * @return string
	 */
	public function get_group(): string {
		return 'livada-seo';
	}

	/**
	 * Returns the Elementor content categories this tag supports.
	 * TEXT_CATEGORY allows the tag to be used in any text-based control.
	 *
	 * @return string[]
	 */
	public function get_categories(): array {
		return [ \Elementor\Modules\DynamicTags\Module::TEXT_CATEGORY ];
	}

	/**
	 * Renders the breadcrumb trail by delegating to the global helper.
	 *
	 * The helper echoes its output directly, so output buffering is used to
	 * capture it before handing it back to Elementor.
	 */
	public function render(): void {
		if ( ! function_exists( 'livada_seo_breadcrumbs' ) ) {
			return;
		}

		ob_start();
		livada_seo_breadcrumbs();
		$output = ob_get_clean();

		echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML generated by trusted internal function.
	}
}
