<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class IDSC_Elementor {

    public function __construct() {
        add_action( 'elementor/elements/categories_registered', array( $this, 'register_category' ) );
        add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ) );
        add_action( 'elementor/preview/enqueue_styles', array( $this, 'enqueue_preview_styles' ) );
        add_action( 'elementor/preview/enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
    }

    public function register_category( $elements_manager ) {
        $elements_manager->add_category( 'idsc', array(
            'title' => __( 'ID Shortcodes', 'idsc' ),
            'icon'  => 'eicon-shortcode',
        ) );
    }

    public function register_widgets( $widgets_manager ) {
        $widgets = array(
            'alert',
            'card',
            'counter',
            'gallery',
            'map',
            'progress',
            'testimonial',
            'toc',
            'accordion',
            'tabs',
            'icon-list',
            'social-links',
        );

        foreach ( $widgets as $widget ) {
            require_once IDSC_PLUGIN_DIR . 'includes/elementor/class-idsc-elementor-' . $widget . '.php';
        }

        $widgets_manager->register( new IDSC_Elementor_Alert() );
        $widgets_manager->register( new IDSC_Elementor_Card() );
        $widgets_manager->register( new IDSC_Elementor_Counter() );
        $widgets_manager->register( new IDSC_Elementor_Gallery() );
        $widgets_manager->register( new IDSC_Elementor_Map() );
        $widgets_manager->register( new IDSC_Elementor_Progress() );
        $widgets_manager->register( new IDSC_Elementor_Testimonial() );
        $widgets_manager->register( new IDSC_Elementor_TOC() );
        $widgets_manager->register( new IDSC_Elementor_Accordion() );
        $widgets_manager->register( new IDSC_Elementor_Tabs() );
        $widgets_manager->register( new IDSC_Elementor_Icon_List() );
        $widgets_manager->register( new IDSC_Elementor_Social_Links() );
    }

    public function enqueue_preview_styles() {
        wp_enqueue_style(
            'idsc-blocks',
            IDSC_PLUGIN_URL . 'assets/css/idsc-blocks.css',
            array(),
            IDSC_VERSION
        );
    }

    public function enqueue_preview_scripts() {
        wp_enqueue_script(
            'idsc-blocks',
            IDSC_PLUGIN_URL . 'assets/js/idsc-blocks.js',
            array(),
            IDSC_VERSION,
            true
        );
    }
}
