<?php

use Banana_Addons\Elementor\Helper;
use Elementor\Widget_Base;
use Elementor\Icons_Manager;

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

class Banae_Widget_CF7 extends Widget_Base {

	/**
	 * Get widget name.
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'banae_cf7';
	}

	/**
	 * Get widget title.
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Contact Form 7', 'banana-addons-for-elementor' );
	}

	/**
	 * Get widget icon.
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-form-horizontal';
	}

	/**
	 * Get widget categories.
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'banana-addons-category' ];
	}

	/**
	 * Get widget keywords for search
	 * 
	 * @return string[]
	 */
	public function get_keywords() {
		return [ 'form', 'contact', 'feedback', 'cf7', 'contact form 7' ];
	}

	/**
	 * Enqueue dependend styles
	 * 
	 * Retrieve the list of style dependencies the widget requires.
	 * 
	 * @return string[]
	 */
	public function get_style_depends() {
		return [];
	}

	/**
	 * Enqueue dependend script
	 * 
	 * Retrieve the list of style dependencies the widget requires.
	 * 
	 * @return string[]
	 */
	public function get_script_depends() {
		return [];
	}

	protected function is_dynamic_content(): bool {
		return false;
	}

	/**
	 * Register widget content controls
	 */
	protected function register_controls() {

		// Instantiate the control class
		require_once 'register-controls.php';

		// Call to the register controls method
		Banae_CF7_Control::add_register_controls( $this );

	}

	protected function render() {
		$settings = $this->get_settings_for_display();
		$cf7_html_class = esc_attr( $settings['cf7_html_class'] );

		if ( ! Helper::is_cf7_activated() ) {
			Helper::rising_plugin_missing_notice( __( 'Contact Forms 7', 'banana-addons-for-elementor' ) );
			return;
		}

		if ( ! empty( $settings['cf7_form_id'] ) ) {
			echo Helper::banae_do_shortcode( 'contact-form-7', [
				'id' => $settings['cf7_form_id'],
				'html_class' => 'banae-cf7-form ' . Helper::sanitize_html_classes( $cf7_html_class ),
			] );
		}
	}
}