<?php

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

/**
 * Plugin Elementor Init.
 *
 * The main class that initiates and runs the Elementor widgets.
 *
 * @since 1.0.0
 */
final class DSProofwp_Elementor_Init
{

    /**
     * Instance
     *
     * @since 1.0.0
     *
     * @access private
     * @static
     *
     * @var DSProofwp_Elementor_Init The single instance of the class.
     */
    private static $_instance = null;

    /**
     * Instance
     *
     * Ensures only one instance of the class is loaded or can be loaded.
     *
     * @since 1.0.0
     *
     * @access public
     * @static
     *
     * @return DSProofwp_Elementor_Init An instance of the class.
     */
    public static function instance()
    {

        if (is_null(self::$_instance)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * Constructor
     *
     * @since 1.0.0
     *
     * @access public
     */
    public function __construct()
    {
        add_action('elementor/widgets/register', [$this, 'register_widgets']);
    }

    /**
     * Register Widgets
     *
     * Register new Elementor widgets.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
     */
    public function register_widgets($widgets_manager)
    {
        require_once plugin_dir_path(dirname(__DIR__, 2) . '/proofwp.php') . 'includes/elementor/widgets/class-proofwp-widget.php';

        $widgets_manager->register(new \DSProofwp_Widget());

        $editor_style_path = plugin_dir_path(dirname(__DIR__, 2) . '/proofwp.php') . 'assets/css/admin.css';
        $editor_style_url  = plugins_url('assets/css/admin.css', dirname(__DIR__, 2) . '/proofwp.php');

        wp_enqueue_style(
            'dsproofwp-elementor-editor-css',
            $editor_style_url,
            [],
            file_exists($editor_style_path) ? (string) filemtime($editor_style_path) : '1.3.12'
        );
    }
}

DSProofwp_Elementor_Init::instance();
