<?php

namespace Bookingor\Integrations\Elementor;

include_once ABSPATH . 'wp-admin/includes/plugin.php';

use Elementor\Controls_Manager;
use Elementor\Core\Common\Modules\Ajax\Module as AjaxModule;
use Elementor\Core\Settings\Manager as SettingsManager;
use Elementor\Widget_Base;
use Elementor\Control_Base;
use ElementorPro\Modules\Forms\Actions\Base as FormActionBase;
use ElementorPro\Modules\Forms\Actions\Ajax_Handler as FormAjaxHandler;
use Elementor\Plugin;
use Bookingor\Integrations\Elementor\BookingorElementorWidget;
use Bookingor\Integrations\Elementor\BookingorElementorControl;
use Bookingor\Integrations\Elementor\BookingorElementorButtonWidget;
use Bookingor\Integrations\Elementor\BookingorElementorTemplateWidget;
use Bookingor\Integrations\Elementor\BookingorElementorStarterWidget;

use Bookingor\Integrations\Elementor\BookingorElementorFormAction;

class ElementorIntegration
{
    private static $_instance = null;

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

    public function __construct()
    {
        add_action('elementor/widgets/register', [$this, 'register_widgets']);
    }

    public function init()
    {
        // Initialize Elementor
    }

    public function includes()
    {
        require_once(plugin_dir_path(__FILE__) . 'BookingorElementorWidget.php');
    }

    public function register_widgets($widgets_manager)
    {
        if (method_exists($widgets_manager, 'register')) {
            $widgets_manager->register(new BookingorElementorButtonWidget());
            $widgets_manager->register(new BookingorElementorTemplateWidget());
            $widgets_manager->register(new BookingorElementorStarterWidget());
        } else {
            $widgets_manager->register_widget_type(new BookingorElementorButtonWidget());
            $widgets_manager->register_widget_type(new BookingorElementorTemplateWidget());
            $widgets_manager->register_widget_type(new BookingorElementorStarterWidget());
        }
    }

    public function register_form_actions()
    {
        // Register custom form actions
        // \ElementorPro\Modules\Forms\Actions::instance()->register_action(new MyFormAction());
    }
}

// Uncomment and implement MyFormAction if needed
// class MyFormAction extends FormActionBase {
//     public function get_name() {
//         return 'my-form-action';
//     }
//     public function get_label() {
//         return esc_html__( 'My Form Action', 'bookingor' );
//     }
//     public function run( $record, $ajax_handler ) {
//         // Run form action code
//         // $record is the form submission data
//         // $ajax_handler is an instance of the ElementorPro\Modules\Forms\Ajax_Handler class
//     }
// }
