<?php
/**
 * Custom Fields — Elementor Dynamic Tag Integration.
 *
 * @package CustomFields
 */

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

function wpps_cf_register_elementor_group( $dynamic_tags_manager ): void {
	$dynamic_tags_manager->register_group(
		'wp-powersuite-cf',
		[
			'title' => __( 'WP PowerSuite Fields', 'wp-powersuite' ),
		]
	);
}

function wpps_cf_register_elementor_tag( $dynamic_tags_manager ): void {
	require_once __DIR__ . '/elementor-tag.php';
	$dynamic_tags_manager->register( new \CustomFields\Elementor_CF_Field_Tag() );
}

function wpps_cf_register_elementor_tags( $dynamic_tags_manager ): void {
	wpps_cf_register_elementor_group( $dynamic_tags_manager );
	wpps_cf_register_elementor_tag( $dynamic_tags_manager );
}

function wpps_cf_init_elementor(): void {
	if ( did_action( 'elementor/loaded' ) ) {
		add_action( 'elementor/dynamic_tags/register', 'wpps_cf_register_elementor_tags' );
	} else {
		add_action(
			'elementor/loaded',
			static function (): void {
				add_action( 'elementor/dynamic_tags/register', 'wpps_cf_register_elementor_tags' );
			}
		);
	}
}

add_action( 'init', 'wpps_cf_init_elementor', 20 );
