<?php

namespace RebelCode\Spotlight\Instagram\Pro\Elementor;

use Elementor\Controls_Manager;
use Elementor\Widget_Base;

/**
 * The Spotlight Elementor widget.
 *
 * @since 0.4
 */
class ElementorWidget extends Widget_Base
{
    /**
     * @since 0.4
     *
     * @var callable
     */
    protected static $renderAction;

    /**
     * Sets the render callback for the widget.
     *
     * @since 0.4
     *
     * @param callable $renderAction The render callback.
     */
    public static function setRenderAction(callable $renderAction)
    {
        static::$renderAction = $renderAction;
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    public function get_name()
    {
        return 'sl-insta-feed';
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    public function get_title()
    {
        return __('Spotlight Instagram feed', 'sl-insta');
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    public function get_icon()
    {
        return 'fa fa-instagram';
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    public function get_categories()
    {
        return ['general'];
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    protected function _register_controls()
    {
        $this->start_controls_section('sl-insta', [
            'label' => 'Instagram Feed',
            'tab' => Controls_Manager::TAB_CONTENT,
        ]);

        $this->add_control('feed', [
            'type' => ElementorSelectFeedControl::TYPE,
            'label' => __('Select the feed to display or create a new one', 'sl-insta'),
        ]);

        $this->end_controls_section();
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    public function get_script_depends()
    {
        do_action('spotlight/instagram/localize_config');

        return ['sli-elementor-widget'];
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    public function get_style_depends()
    {
        return ['sli-front', 'sli-common-pro'];
    }

    /**
     * @inheritDoc
     *
     * @since 0.4
     */
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $feedId = $settings['feed'] ?? [];

        echo (static::$renderAction)([
            'feed' => $feedId,
        ]);
    }
}
