<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\Integrations;

defined('ABSPATH') || exit;

/**
 * Elementor integration: adds a "CliqThemes" widget category and a Store Locator
 * widget that embeds a saved locator template (a thin wrapper over the
 * [cliq_store_locator] shortcode — no locator design logic is duplicated).
 */
final class Elementor implements Integration
{
    public const CATEGORY = 'cliqthemes';

    public function isActive(): bool
    {
        return defined('ELEMENTOR_VERSION');
    }

    public function register(): void
    {
        add_action('elementor/elements/categories_registered', [$this, 'registerCategory']);
        add_action('elementor/widgets/register', [$this, 'registerWidget']);
    }

    /** @param \Elementor\Elements_Manager $manager */
    public function registerCategory($manager): void
    {
        $manager->add_category(self::CATEGORY, [
            'title' => __('CliqThemes', 'cliq-store-locator'),
            'icon' => 'eicon-map-pin',
        ]);
    }

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

        /**
         * Register Elementor widgets for a feature of your own.
         *
         * @param \Elementor\Widgets_Manager $widgetsManager
         * @param string                     $category the shared widget category
         */
        do_action('cliq_sl_register_elementor_widgets', $widgetsManager, self::CATEGORY);
    }
}
