<?php
/**
 * Revio - Elementor
 * Elementor
 *
 * @package RVIOR
 */

namespace RVIOR;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit( 1 );

if ( ! class_exists( '\RVIOR\ElementorInit' ) ) {
	/**
	 * Class ElementorInit
	 *
	 * @since 1.0.0
	 * @package RVIOR
	 */
	class ElementorInit {

		/**
		 * ElementorInit constructor.
		 */
		public function __construct() {
			add_action( 'elementor/widgets/widgets_registered', [ $this, 'add_rvior_elementor_widgets' ], 99 );
			add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'rvior_elementor_before_enqueue_scripts' ] );
		}

		/**
		 * Add Elementor Widgets
		 */
		public function add_rvior_elementor_widgets() {
			require_once __DIR__ . '/widgets/class-elementor-showcase-widget.php';

			\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \RVIOR\Elementor\Widget\Showcase() );
		}

		/**
		 * Elementor before scripts add custom icon class
		 */
		public function rvior_elementor_before_enqueue_scripts() {
			// Register a handle for our icon styles
			wp_register_style(
				'rvior-elementor-icons',
				false,  // No actual CSS file
				[],     // No dependencies
				RVIOR_VERSION
			);

			// Add our inline CSS to the registered style
			wp_add_inline_style(
				'rvior-elementor-icons',
				'
				.rvior-logo-icon {
					width: 25px;
					height: 20px;
					display: inline-block;
					margin: auto;
					background-image: url(\'' . esc_url( RVIOR_PUBLIC ) . '/images/revio.svg\') !important;
					background-size: 100%;
				}'
			);

			// Enqueue the style
			wp_enqueue_style( 'rvior-elementor-icons' );
		}
	}

	new ElementorInit();
}
