<?php
/**
 * Widget: Block Partner
 *
 * Widget show the block posts from selected category in different layouts.
 *
 * @package MatrixAddons
 * @subpackage trainify
 * @since 1.0.0
 */
if(!class_exists( 'Trainify_Contact_Form_Widget' ) ):

	class Trainify_Contact_Form_Widget extends TrainifyFramework_Master_Widget{

		/**
		 * Register widget with WordPress.
		 */
		public function __construct() {
			$widget_ops = array(
				'classname'   => 'trainify_contact_form_widget tff-full-widget',
				'description' => esc_html__( 'Display contact form with beautiful layout.', 'trainify' )
			);
			parent::__construct( 'trainify_contact_form_widget', esc_html__( 'TF - Contact Form', 'trainify' ), $widget_ops );
		}

		/**
		 * Helper function that holds widget fields
		 * Array is used in update and form functions
		 */
		public function widget_fields( $instance = array() ) {

			$fields = array(
				'trainify_framework_widget_tab'       => array(
					'trainify_framework_widget_field_name'     => 'trainify_framework_widget_tab',
					'trainify_framework_widget_field_title'    => esc_html__( 'General', 'trainify' ),
					'trainify_framework_widget_field_default'  => 'general',
					'trainify_framework_widget_field_type'     => 'tabgroup',
					'trainify_framework_widget_field_options'  => array(
						'general'=>array(
							'trainify_framework_widget_field_title'=>esc_html__('General', 'trainify'),
							'trainify_framework_widget_field_options'=> array(
								'title' => array(
									'trainify_framework_widget_field_name'        => 'title',
									'trainify_framework_widget_field_default'  => esc_html__( 'Enter contact form title.', 'trainify' ),
									'trainify_framework_widget_field_title'       => esc_html__( 'Section Title', 'trainify' ),
									'trainify_framework_widget_field_description' => esc_html__( 'Enter your block title', 'trainify' ),
									'trainify_framework_widget_field_type'  => 'text'
								),
								'form_shortcode'         => array(
									'trainify_framework_widget_field_name'     => 'form_shortcode',
									'trainify_framework_widget_field_title'    => esc_html__( 'Form Shortcode', 'trainify' ),
									'trainify_framework_widget_field_type'     => 'text',
									'trainify_framework_widget_description'    => esc_html__('Please add shortcode of contact form here.', 'trainify'),
								),
								'background_color'         => array(
									'trainify_framework_widget_field_name'     => 'background_color',
									'trainify_framework_widget_field_title'    => esc_html__( 'Background color', 'trainify' ),
									'trainify_framework_widget_field_type'     => 'color',
									'trainify_framework_widget_description'    => esc_html__('Please add a background color for this section.', 'trainify'),
								),
								'background_image'         => array(
									'trainify_framework_widget_field_name'     => 'background_image',
									'trainify_framework_widget_field_title'    => esc_html__( 'Background Image', 'trainify' ),
									'trainify_framework_widget_field_type'     => 'upload',
									'trainify_framework_widget_description'    => esc_html__('Please add a background image for this section.', 'trainify'),
								),
							),
						),
					)
				)
			);

			$widget_fields_key = 'fields_'.$this->id_base;
			$widgets_fields = apply_filters( $widget_fields_key, $fields );
			return $widgets_fields;

		}

		/**
		 * Front-end display of widget.
		 *
		 * @see WP_Widget::widget()
		 *
		 * @param array $args Widget arguments.
		 * @param array $instance Saved values from database.
		 */
		public function widget( $args, $instance ) {

			extract( $args );
			if ( empty( $instance ) ) {
				return;
			}
			$title  = isset( $instance['title'] ) ? $instance['title'] : '';
			$title 	= apply_filters( 'widget_title', $title, $instance, $this->id_base );
			$form_shortcode = isset($instance['form_shortcode']) ? $instance['form_shortcode'] : '';
			$background_color = isset($instance['background_color']) ? $instance['background_color'] : '';
			$background_image = isset($instance['background_image']) ? $instance['background_image'] : '';
	        trainify_framework_before_widget($args);
	        ?>
	        <div class="apply-now-section" style="background-color:<?php echo esc_attr($background_color); ?>;background-image:url('<?php echo esc_url($background_image); ?>'); background-size: cover">	
	        	<div class="apply-now-wrap">
	        		<div class="apply-now-left"><?php echo esc_html($title); ?></div>
	        		<div class="apply-now-right">
	        			<?php echo do_shortcode($form_shortcode); ?>
	        		</div>
	        	</div>
	        </div>
	        <?php
	        trainify_framework_after_widget($args);
	    }

	}

endif;