<?php
/**
 * OrokuBlocks Elementor Widget Base
 * 
 * @package OrokuBlocks
 * @author OrokuBlocks (https://orokublocks.com/)
 * 
 * @since 1.0.0
 * 
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

if ( ! class_exists( 'OrokuBlocks_Elementor_Widget_Base' ) ) {
  class OrokuBlocks_Elementor_Widget_Base extends \Elementor\Widget_Base {
    /**
     * Widget id
     * 
     * @since 1.0.0
     * 
     * @access protected
     */
    protected $widget_id = '';

    /**
     * Script dependencies
     * 
     * @since 1.0.0
     * 
     * @access protected
     */
    protected $script_dependencies = [];

    /**
     * Widget icon name for displaying to the user
     * 
     * @since 1.0.0
     * 
     * @access protected
     */
    protected $icon = '';

    /**
     * Widget keywords that are used when filtering the widget list
     * 
     * @since 1.0.0
     * 
     * @access private
     */
    private $keywords = [];

    /**
     * Widget constructor
     * 
     * @since 1.0.0
     */
    public function __construct( $data = [], $args = null ) {
      parent::__construct( $data, $args );

      $this->keywords = [ 'orokublocks', 'card' ];
      $this->script_dependencies = [ 'elementor-frontend' ];
    }

    /**
     * Returns the widget name
     * 
     * @since 1.0.0
     */
    public function get_name() {
      return 'orokublocks_' . OrokuBlocks_Router::widgetPathIdGet( $this->widget_id ) . '_elementor_widget';
    }

    /**
     * Returns the widget name for displaying to the user
     * 
     * @since 1.0.0
     */
    public function get_title() {
      return orokublocks()->widgets[$this->widget_id]['name'];
    }

    /**
     * Returns the widget icon name for displaying to the user
     * 
     * @since 1.0.0
     */
    public function get_icon() {
      $icon_name = 'oroku-font-icon oroku-font-icon--' . $this->widget_id;

      $widget_data = orokublocks()->widgets[$this->widget_id];

      if ( array_key_exists( 'icon', $widget_data ) && array_key_exists( 'elementor', $widget_data['icon'] ) ) {
        $icon_name = $widget_data['icon']['elementor'];
      }
      
      return $icon_name;
    }

    /**
     * Returns the widget categories
     * 
     * @since 1.0.0
     */
    public function get_categories() {
      return [ 'orokublocks' ];
    }
  
    /**
     * Returns the widget keywords that are used when filtering the widget list
     * 
     * @since 1.0.0
     */
    public function get_keywords() {
      return $this->keywords;
    }

    /**
     * Add strings to the widget keywords list
     * 
     * @since 1.0.0
     * 
     * @param array $keywords       Widget keywords.
     * 
     * @access protected
     */
    protected function addKeywords( $keywords ) {
      $this->keywords = array_merge( $this->keywords, $keywords );
    }

    /**
     * Add strings to the script dependencies list
     * 
     * @since 1.0.0
     * 
     * @param array $script_dependencies       Script dependencies.
     * 
     * @access protected
     */
    protected function addScriptDependencies( $script_dependencies ) {
      $this->script_dependencies = array_merge( $this->script_dependencies, $script_dependencies );
    }
  }
}