<?php
/**
 * Legacy class aliases and constants for copied SiteOrigin widget files.
 *
 * Loaded only when SiteOrigin Widgets Bundle is present.
 *
 * @package Rsmspark_Content_Widgets
 */

defined( 'ABSPATH' ) || exit;

require_once RSMSPARK_CONTENT_WIDGETS_PATH . 'includes/class-rsmspark-content-widgets-features-fonts.php';
require_once RSMSPARK_CONTENT_WIDGETS_PATH . 'includes/class-rsmspark-content-widgets-features-styles.php';
require_once RSMSPARK_CONTENT_WIDGETS_PATH . 'includes/class-rsmspark-content-widgets-features-popouts.php';
require_once RSMSPARK_CONTENT_WIDGETS_PATH . 'includes/class-rsmspark-content-widgets-image-styles.php';
require_once RSMSPARK_CONTENT_WIDGETS_PATH . 'includes/class-rsmspark-content-widgets-headline-styles.php';

/**
 * Shim for legacy SiteOrigin widget files.
 */
class Rsmspark_Content_Widgets_Loader {

	/**
	 * @param string $registry_id Widget registry id.
	 * @return string
	 */
	public static function siteorigin_id( $registry_id ) {
		return Rsmspark_Content_Widgets_Registry::siteorigin_folder_id( $registry_id );
	}

	/**
	 * @param string $so_id SiteOrigin widget id.
	 * @return string
	 */
	public static function registry_id( $so_id ) {
		$so_id = sanitize_key( (string) $so_id );
		foreach ( Rsmspark_Content_Widgets_Registry::definitions() as $registry_id => $widget ) {
			unset( $widget );
			if ( Rsmspark_Content_Widgets_Registry::siteorigin_folder_id( $registry_id ) === $so_id ) {
				return $registry_id;
			}
		}
		return $so_id;
	}

	/**
	 * @param string $registry_id Widget registry id.
	 * @return bool
	 */
	public static function should_register_widget( $registry_id ) {
		return Rsmspark_Content_Widgets_SiteOrigin::should_register_widget( $registry_id );
	}

	/**
	 * @param array<string, mixed> $instance Widget instance.
	 * @param string               $section  Section id.
	 * @return array<string, mixed>
	 */
	public static function section_instance( $instance, $section = 'content' ) {
		return Rsmspark_Content_Widgets_Render::section_instance( $instance, $section );
	}

	/**
	 * @param mixed $media Attachment id or SiteOrigin media array.
	 * @return string
	 */
	public static function media_url( $media ) {
		return Rsmspark_Content_Widgets_Render::media_url( $media );
	}

	/**
	 * @param mixed $link SiteOrigin link field value.
	 * @return string
	 */
	public static function link_url( $link ) {
		return Rsmspark_Content_Widgets_Render::link_url( $link );
	}

	/**
	 * @return string
	 */
	public static function inline_style_vars() {
		return Rsmspark_Content_Widgets_Render::inline_style_vars();
	}

	/**
	 * @param SiteOrigin_Widget $widget Widget instance.
	 * @return void
	 */
	public static function enqueue_shared_assets( $widget ) {
		Rsmspark_Content_Widgets_SiteOrigin::maybe_enqueue_widget_json_admin_for_widget( $widget );
		if (
			is_admin()
			&& class_exists( 'Rsmspark_Content_Widgets_Media_Picker', false )
			&& Rsmspark_Content_Widgets_Media_Picker::should_use()
		) {
			Rsmspark_Content_Widgets_Media_Picker::enqueue_admin( 'post.php' );
		}
		Rsmspark_Content_Widgets_Assets::enqueue_shared();
	}
}

// Refactored in compat branch - Phase 0
