<?php
/**
 * Livada SEO — Elementor Integration
 *
 * Registers the Livada SEO dynamic tag group and individual tags with
 * Elementor's dynamic tag manager.  This file is loaded by the main loader
 * only when Elementor is active; the plugin continues to function normally
 * when Elementor is deactivated.
 *
 * @package Livada_SEO
 */

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

class Livada_SEO_Elementor {

	/**
	 * Bootstraps the Elementor integration.
	 *
	 * Returns early when Elementor has not been loaded, ensuring zero overhead
	 * on sites that do not use Elementor.
	 */
	public static function init(): void {
		if ( ! did_action( 'elementor/loaded' ) ) {
			return;
		}

		add_action( 'elementor/dynamic_tags/register', [ self::class, 'register_tags' ] );
	}

	/**
	 * Registers the Livada SEO tag group and all dynamic tags.
	 *
	 * @param \Elementor\Core\DynamicTags\Manager $dynamic_tags Elementor dynamic tags manager.
	 */
	public static function register_tags( $dynamic_tags ): void {
		// Register the tag group so all Livada SEO tags are grouped together
		// in the Elementor dynamic tag picker.
		$dynamic_tags->register_group(
			'livada-seo',
			[ 'title' => 'Livada SEO' ]
		);

		// Require and register the breadcrumbs dynamic tag.
		require_once __DIR__ . '/dynamic-tags/class-breadcrumbs-tag.php';
		$dynamic_tags->register( new Livada_SEO_Breadcrumbs_Tag() );
	}
}
