<?php

if ( ! function_exists( 'ginevra_core_add_button_widget' ) ) {
	/**
	 * Function that add widget into widgets list for registration
	 *
	 * @param array $widgets
	 *
	 * @return array
	 */
	function ginevra_core_add_button_widget( $widgets ) {
		$widgets[] = 'GinevraCore_Button_Widget';

		return $widgets;
	}

	add_filter( 'ginevra_core_filter_register_widgets', 'ginevra_core_add_button_widget' );
}

if ( class_exists( 'QodeFrameworkWidget' ) ) {
	class GinevraCore_Button_Widget extends QodeFrameworkWidget {

		public function map_widget() {
			$widget_mapped = $this->import_shortcode_options(
				array(
					'shortcode_base' => 'ginevra_core_button',
				)
			);
			if ( $widget_mapped ) {
				$this->set_base( 'ginevra_core_button' );
				$this->set_name( esc_html__( 'Ginevra Button', 'ginevra-core' ) );
				$this->set_description( esc_html__( 'Add a button element into widget areas', 'ginevra-core' ) );
			}
		}

		public function render( $atts ) {
			echo GinevraCore_Button_Shortcode::call_shortcode( $atts ); // XSS OK
		}
	}
}
