<?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
 */

function register_hello_world_widget($widgets_manager)
{
  $widgets_dir = __DIR__ . '/widgets';
  $before = get_declared_classes();

  foreach (glob($widgets_dir . '/*.php') as $file) {
      require_once $file;
  }

  $after = get_declared_classes();
  $new_classes = array_diff($after, $before);

  foreach ($new_classes as $class) {
      $widgets_manager->register(new $class());
  }
}
add_action('elementor/widgets/register', 'register_hello_world_widget');

// 🔹 CSS
function enqueue_elementor_addon_styles()
{
  if (did_action('elementor/loaded')) {

    // Main CSS
    wp_enqueue_style(
      'elementor-addon-main-css',
      plugins_url('assets/css/main.css', __FILE__),
      [],
      '1.0.0'
    );

    // Swiper
    wp_enqueue_style(
      'elementor-addon-swiper-css',
      plugins_url('plugins/swiper/swiper.min.css', __FILE__),
      [],
      '1.0.0'
    );
  }
}
add_action('wp_enqueue_scripts', 'enqueue_elementor_addon_styles');


// 🔹 JS
function enqueue_elementor_addon_scripts()
{
  if (did_action('elementor/loaded')) {

    // Main JS
    wp_enqueue_script(
      'elementor-addon-main-js',
      plugins_url('assets/js/main.js', __FILE__),
      ['jquery'],
      '1.0.0',
      true
    );

    // Swiper JS
    wp_enqueue_script(
      'swiper-js',
      plugins_url('plugins/swiper/swiper.min.js', __FILE__),
      [],
      '1.0.0',
      true
    );

    // GSAP core
    wp_enqueue_script(
      'gsap-js',
      plugins_url('plugins/gsap/gsap.min.js', __FILE__),
      [],
      '3.12.5',
      true
    );

    // ScrollTrigger plugin
    wp_enqueue_script(
      'gsap-scrolltrigger-js',
      plugins_url('plugins/gsap/ScrollTrigger.min.js', __FILE__),
      ['gsap-js'],
      '3.12.5',
      true
    );
  }
}
add_action('wp_enqueue_scripts', 'enqueue_elementor_addon_scripts');
