<?php
namespace Gridpress_Elementor;

defined('ABSPATH') || exit;

if (! class_exists('Gridpress_Elementor_Init')) {

    class Gridpress_Elementor_Init
    {
        private static $gridpress_instance = null;

        public function __construct()
        {
            add_action('elementor/elements/categories_registered', [$this, 'gridpress_add_elementor_widget_categories']);
            add_action('elementor/widgets/widgets_registered', [$this, 'gridpress_register_widgets']);
        }

        public static function gridpress_instance()
        {
            if (is_null(self::$gridpress_instance)) {
                self::$gridpress_instance = new self();
            }
            return self::$gridpress_instance;
        }

        public function gridpress_add_elementor_widget_categories($gridpress_elements_manager)
        {
            $gridpress_elements_manager->add_category(
                'gridpress',
                [
                    'title' => esc_html__('Gridpress', 'gridpress-grid-layout-design'),
                    'icon' => 'fa fa-plug',
                ]
            );
        }

        public function gridpress_register_widgets()
        {
            include_once GRIDPRESS_ABSPATH . 'includes/elementor/elements/grid.php';

            \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Widgets\Gridpress_Grid_Elementor());
        }
    }

    Gridpress_Elementor_Init::gridpress_instance();
}