<?php
/**
 * Elementor V4 Atomic Widgets capability checks.
 *
 * Migration policy (saved templates): Legacy widget JSON uses classic `widgetType` and settings shape.
 * Atomic widgets use distinct `get_element_type()` values (e.g. sifency-atomic-divider). There is no
 * automatic conversion; re-add the widget from the panel or run a custom migration if you change types.
 *
 * @package Sifency_Addons
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Environment and phased rollout helpers for Sifency atomic widgets.
 */
class Sifency_Atomic_Environment {

	const MIN_ELEMENTOR_FOR_ATOMIC = '4.0.0';

	/**
	 * Widget IDs that currently ship an atomic implementation (when e_atomic_elements is on).
	 * Add each ID here when `atomic_class` / `atomic_file` are added in sifency-widgets.php so
	 * release notes and smoke tests stay aligned (Phase 1: low-dependency widgets; later: loops, Woo, TB).
	 *
	 * @var string[]
	 */
	public static $atomic_ready_widget_ids = array(
		'sifency-divider',
	);

	/**
	 * Whether Elementor is new enough to ship the Atomic Widgets module API.
	 */
	public static function is_elementor_meets_atomic_requirement(): bool {
		return defined( 'ELEMENTOR_VERSION' )
			&& version_compare( ELEMENTOR_VERSION, self::MIN_ELEMENTOR_FOR_ATOMIC, '>=' );
	}

	/**
	 * Whether the e_atomic_elements experiment is active (Atomic Widgets module running).
	 */
	public static function is_atomic_widgets_active(): bool {
		if ( ! self::is_elementor_meets_atomic_requirement() ) {
			return false;
		}
		if ( ! class_exists( '\Elementor\Modules\AtomicWidgets\Module' ) ) {
			return false;
		}
		return \Elementor\Modules\AtomicWidgets\Module::is_active();
	}
}
