<?php
/**
 * Plugin Name: Elementor Addon
 * Description: Simple hello world widgets for Elementor.
 * Version:     1.0.0
 * Author:      Elementor Developer
 * Author URI:  https://developers.elementor.com/
 * Text Domain: elementor-addon
 *
 * Requires Plugins: elementor
 * Elementor tested up to: 3.21.0
 * Elementor Pro tested up to: 3.21.0
 */

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

/**
 * Register widget files
 */
function register_hello_world_widget( $widgets_manager ) {
	require_once( __DIR__ . '/widgets/vertical-separator.php' );
	require_once( __DIR__ . '/widgets/number-box.php' );

	$widgets_manager->register( new \Elementor_Vertical_Separator() );
	$widgets_manager->register( new \Elementor_Number_Box() );
}
add_action( 'elementor/widgets/register', 'register_hello_world_widget' );

/**
 * Register scripts/styles only.
 * Do not enqueue them globally.
 */
function elementor_addon_register_assets() {
	$css_path = plugin_dir_path( __FILE__ ) . 'assets/css/main.css';
	$css_url  = plugin_dir_url( __FILE__ ) . 'assets/css/main.css';
	$css_ver  = file_exists( $css_path ) ? filemtime( $css_path ) : '1.0.0';

	$js_path = plugin_dir_path( __FILE__ ) . 'assets/js/main.js';
	$js_url  = plugin_dir_url( __FILE__ ) . 'assets/js/main.js';
	$js_ver  = file_exists( $js_path ) ? filemtime( $js_path ) : '1.0.0';

	// Widget CSS
	wp_register_style(
		'elementor-addon-main-css',
		$css_url,
		[],
		$css_ver
	);

	// Widget JS
	wp_register_script(
		'elementor-addon-main-js',
		$js_url,
		[ 'jquery' ],
		$js_ver,
		true
	);
}
add_action( 'elementor/frontend/after_register_styles', 'elementor_addon_register_assets' );
add_action( 'elementor/frontend/after_register_scripts', 'elementor_addon_register_assets' );
