<?php
/**
 * BookiFlex
 *
 * @package   BookiFlex
 * @author    BookiFlex
 * @copyright Copyright (c) 2025 BookiFlex
 * @license   GPL-2.0-or-later
 *
 * @link https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Plugin\UI\Elementor;

defined('ABSPATH') || exit;

/**
 * Registers BookiFlex Elementor widgets, but only when the Elementor plugin is
 * active. All references to \Elementor\* classes live inside hook callbacks that
 * fire only when Elementor is loaded, so this stays safe without Elementor.
 */
class ElementorIntegration
{
    public function register(): void
    {
        if (!did_action('elementor/loaded')) {
            return;
        }

        add_action('elementor/elements/categories_registered', [$this, 'registerCategory']);
        add_action('elementor/widgets/register', [$this, 'registerWidgets']);
    }

    /**
     * @param \Elementor\Elements_Manager $elementsManager
     */
    public function registerCategory($elementsManager): void
    {
        $elementsManager->add_category('bookiflex', [
            'title' => 'BookiFlex',
            'icon'  => 'fa fa-calendar',
        ]);
    }

    /**
     * @param \Elementor\Widgets_Manager $widgetsManager
     */
    public function registerWidgets($widgetsManager): void
    {
        $widgetsManager->register(new SearchFormWidget());
    }
}
