<?php
namespace Sifency_Addons\Includes\Admin;

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

class Sifency_Addons_Admin_Widgets {
	/**
	 * Renders a generic admin notice.
	 *
	 * @param string $message The message to display.
	 * @param string $class   The class for the notice div (e.g., 'notice-warning', 'notice-error').
	 */
	public static function render_sifency_admin_notice( $message, $class = 'notice-warning' ) {
		// This function should ONLY render the notice HTML, not handle redirects.
		// Handling redirects here interferes with WordPress admin actions like plugin activation.
		printf( '<div class="notice %1$s is-dismissible"><p>%2$s</p></div>', esc_attr( $class ), wp_kses_post( $message ) );
	}

	/**
	 * Loads the widget configuration array from its dedicated file.
	 * This is used to build the settings page.
	 *
	 * @return array A list of all available widgets.
	 */
	public static function get_all_sifency_widgets_for_settings() {
		if ( class_exists( '\Sifency_Addons\Includes\Elementor\Sifency_Addons_Widget_Registry' ) ) {
			return \Sifency_Addons\Includes\Elementor\Sifency_Addons_Widget_Registry::get_categorized();
		}

		$widgets_config_path = SIFENCY_ADDONS_DIR . 'includes/elementor/sifency-widgets.php';

		if ( file_exists( $widgets_config_path ) ) {
			$config = include $widgets_config_path;

			return is_array( $config ) ? $config : array();
		}

		return array();
	}
}
