<?php
/**
 * Theme widgets.
 *
 * @package Mediclean
 */

// Load widget base.
require_once get_template_directory() . '/lib/widget-base/class-widget-base.php';

if ( ! function_exists( 'mediclean_load_widgets' ) ) :

	/**
	 * Load widgets.
	 *
	 * @since 1.0.0
	 */
	function mediclean_load_widgets() {

		// Social widget.
		register_widget( 'Mediclean_Social_Widget' );

		// Featured Page widget.
		register_widget( 'Mediclean_Featured_Page_Widget' );

		// Latest News widget.
		register_widget( 'Mediclean_Latest_News_Widget' );

		// Call To Action widget.
		register_widget( 'Mediclean_Call_To_Action_Widget' );

		// Services widget.
		register_widget( 'Mediclean_Services_Widget' );

		// Contact widget.
		register_widget( 'Mediclean_Appointment_Widget' );

		// Testimonial slider widget.
		register_widget( 'Mediclean_Testimonial_Slider_Widget' );

		// Portfolio widget.
		register_widget( 'Mediclean_Portfolio_Widget' );

		// Clients widget.
		register_widget( 'Mediclean_Clients_Widget' );

		// Pricing Table widget.
		register_widget( 'Mediclean_Pricing_Table_Widget' );

		// Recent Posts widget.
		register_widget( 'Mediclean_Recent_Posts_Widget' );

		// Teams widget.
		register_widget( 'Mediclean_Teams_Widget' );

		// Skills widget.
		register_widget( 'Mediclean_Skills_Widget' );

		// Information widget.
		register_widget( 'Mediclean_Information_Widget' );

	}

endif;

add_action( 'widgets_init', 'mediclean_load_widgets' );

if ( ! class_exists( 'Mediclean_Social_Widget' ) ) :

	/**
	 * Social widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Social_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_social',
				'description'                 => __( 'Displays social icons.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				);

			if ( false === has_nav_menu( 'social' ) ) {
				$fields['message'] = array(
					'label' => __( 'Social menu is not set. Please create menu and assign it to Social Menu.', 'mediclean-pro' ),
					'type'  => 'message',
					'class' => 'widefat',
					);
			}

			parent::__construct( 'mediclean-social', __( 'Mediclean: Social', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			if ( has_nav_menu( 'social' ) ) {
				wp_nav_menu( array(
					'theme_location' => 'social',
					'container'      => false,
					'depth'          => 1,
					'link_before'    => '<span class="screen-reader-text">',
					'link_after'     => '</span>',
				) );
			}

			echo $args['after_widget'];

		}
	}
endif;

if ( ! class_exists( 'Mediclean_Featured_Page_Widget' ) ) :

	/**
	 * Featured page widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Featured_Page_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_featured_page',
				'description'                 => __( 'Displays single featured Page or Post.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'use_page_title' => array(
					'label'   => __( 'Use Page/Post Title as Widget Title', 'mediclean-pro' ),
					'type'    => 'checkbox',
					'default' => true,
					),
				'featured_page' => array(
					'label'            => __( 'Select Page:', 'mediclean-pro' ),
					'type'             => 'dropdown-pages',
					'show_option_none' => __( '&mdash; Select &mdash;', 'mediclean-pro' ),
					),
				'id_message' => array(
					'label'            => '<strong>' . _x( 'OR', 'Featured Page Widget', 'mediclean-pro' ) . '</strong>',
					'type'             => 'message',
					),
				'featured_post' => array(
					'label'             => __( 'Post ID:', 'mediclean-pro' ),
					'placeholder'       => __( 'Eg: 1234', 'mediclean-pro' ),
					'type'              => 'text',
					'sanitize_callback' => 'mediclean_widget_sanitize_post_id',
					),
				'content_type' => array(
					'label'   => __( 'Show Content:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 'full',
					'options' => array(
						'excerpt' => __( 'Excerpt', 'mediclean-pro' ),
						'full'    => __( 'Full', 'mediclean-pro' ),
						),
					),
				'excerpt_length' => array(
					'label'       => __( 'Excerpt Length:', 'mediclean-pro' ),
					'description' => __( 'Applies when Excerpt is selected in Content option.', 'mediclean-pro' ),
					'type'        => 'number',
					'css'         => 'max-width:60px;',
					'default'     => 40,
					'min'         => 1,
					'max'         => 400,
					),
				'featured_image' => array(
					'label'   => __( 'Featured Image:', 'mediclean-pro' ),
					'type'    => 'select',
					'options' => mediclean_get_image_sizes_options(),
					),
				'featured_image_alignment' => array(
					'label'   => __( 'Image Alignment:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 'center',
					'options' => mediclean_get_image_alignment_options(),
					),
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-featured-page', __( 'Mediclean: Featured Page', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			// ID validation.
			$our_post_object = null;
			$our_id = '';
			if ( absint( $params['featured_post'] ) > 0 ) {
				$our_id = absint( $params['featured_post'] );
			}
			if ( absint( $params['featured_page'] ) > 0 ) {
				$our_id = absint( $params['featured_page'] );
			}
			if ( absint( $our_id ) > 0 ) {
				$raw_object = get_post( $our_id );
				if ( ! in_array( $raw_object->post_type, array( 'attachment', 'nav_menu_item', 'revision' ) ) ) {
					$our_post_object = $raw_object;
				}
			}
			if ( ! $our_post_object ) {
				// No valid object; bail now!
				return;
			}

			echo $args['before_widget'];

			global $post;
			// Setup global post.
			$post = $our_post_object;
			setup_postdata( $post );

			// Override title if checkbox is selected.
			if ( true === $params['use_page_title'] ) {
				$params['title'] = get_the_title( $post );
			}

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}
			?>
			<div class="featured-page-widget entry-content">
				<?php if ( 'disable' !== $params['featured_image'] && has_post_thumbnail() ) : ?>
					<?php the_post_thumbnail( esc_attr( $params['featured_image'] ), array( 'class' => 'align' . esc_attr( $params['featured_image_alignment'] ) ) ); ?>
				<?php endif; ?>
				<?php if ( 'excerpt' === $params['content_type'] ) : ?>
					<?php
						$excerpt = mediclean_the_excerpt( absint( $params['excerpt_length'] ) );
						echo wp_kses_post( wpautop( $excerpt ) );
						?>
				<?php else : ?>
					<?php the_content(); ?>
				<?php endif; ?>

			</div><!-- .featured-page-widget -->
			<?php
			// Reset.
			wp_reset_postdata();

			echo $args['after_widget'];

		}
	}
endif;

if ( ! class_exists( 'Mediclean_Latest_News_Widget' ) ) :

	/**
	 * Latest news widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Latest_News_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {
			$opts = array(
				'classname'                   => 'mediclean_widget_latest_news',
				'description'                 => __( 'Displays latest posts in grid.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'post_category' => array(
					'label'           => __( 'Select Category:', 'mediclean-pro' ),
					'type'            => 'dropdown-taxonomies',
					'show_option_all' => __( 'All Categories', 'mediclean-pro' ),
					),
				'post_number' => array(
					'label'   => __( 'Number of Posts:', 'mediclean-pro' ),
					'type'    => 'number',
					'default' => 5,
					'css'     => 'max-width:60px;',
					'min'     => 1,
					'max'     => 100,
					),
				'excerpt_length' => array(
					'label'       => __( 'Excerpt Length:', 'mediclean-pro' ),
					'description' => __( 'in words. Applies for first news block.', 'mediclean-pro' ),
					'type'        => 'number',
					'css'         => 'max-width:60px;',
					'default'     => 80,
					'min'         => 1,
					'max'         => 200,
					'adjacent'    => true,
					),
				'disable_date' => array(
					'label'   => __( 'Disable Date', 'mediclean-pro' ),
					'type'    => 'checkbox',
					'default' => false,
					),
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-latest-news', __( 'Mediclean: Latest News', 'mediclean-pro' ), $opts, array(), $fields );
		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {
			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$qargs = array(
				'posts_per_page' => esc_attr( $params['post_number'] ),
				'no_found_rows'  => true,
				'meta_key'       => '_thumbnail_id',
				);
			if ( absint( $params['post_category'] ) > 0  ) {
				$qargs['category'] = absint( $params['post_category'] );
			}
			$all_posts = get_posts( $qargs );
			?>
			<?php if ( ! empty( $all_posts ) ) : ?>
				<?php global $post; ?>

				<div class="latest-news-widget latest-news-col-3">

					<div class="inner-wrapper">
						<?php $cnt = 1; ?>
						<?php foreach ( $all_posts as $key => $post ) : ?>
							<?php setup_postdata( $post ); ?>

							<?php $featured_class = ( 1 == $cnt ) ? 'news-featured' : ''; ?>
							<div class="latest-news-item <?php echo esc_attr( $featured_class ); ?>">
								<?php if ( has_post_thumbnail() ) : ?>
									<div class="latest-news-thumb">
										<a href="<?php the_permalink(); ?>">
											<?php the_post_thumbnail( 'mediclean-thumb', array( 'class' => 'aligncenter' ) ); ?>
										</a>
									</div><!-- .latest-news-thumb -->
								<?php endif; ?>
								<div class="latest-news-text-wrap">

									<div class="latest-news-text-content">
										<h3 class="latest-news-title">
											<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
										</h3><!-- .latest-news-title -->
										<?php if ( 1 === $cnt ) : ?>
											<div class="latest-news-summary">
												<?php echo wp_kses_post( wpautop( mediclean_the_excerpt( esc_attr( $params['excerpt_length'] ), $post ) ) ); ?>
											</div><!-- .latest-news-summary -->
										<?php endif; ?>

									</div><!-- .latest-news-text-content -->

									<?php if ( false === $params['disable_date'] ) : ?>
										<div class="latest-news-meta">
											<ul>
												<?php if ( false === $params['disable_date'] ) : ?>
													<li><span class="latest-news-date"><?php the_time( 'j M Y' ); ?></span></li>
												<?php endif; ?>
											</ul>
										</div><!-- .latest-news-meta -->
									<?php endif; ?>

								</div><!-- .latest-news-text-wrap -->

							</div><!-- .latest-news-item -->

							<?php $cnt++; ?>
						<?php endforeach; ?>

					</div><!-- .inner-wrapper -->

				</div><!-- .latest-news-widget -->

				<?php wp_reset_postdata(); ?>

			<?php endif; ?>

			<?php echo $args['after_widget'];

		}
	}
endif;

if ( ! class_exists( 'Mediclean_Call_To_Action_Widget' ) ) :

	/**
	 * Call to action widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Call_To_Action_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_call_to_action',
				'description'                 => __( 'Call To Action Widget.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'description' => array(
					'label' => __( 'Description:', 'mediclean-pro' ),
					'type'  => 'textarea',
					'class' => 'widefat',
					),
				'primary_button_text' => array(
					'label'   => __( 'Primary Button Text:', 'mediclean-pro' ),
					'default' => __( 'Learn more', 'mediclean-pro' ),
					'type'    => 'text',
					'class'   => 'widefat',
					),
				'primary_button_url' => array(
					'label' => __( 'Primary Button URL:', 'mediclean-pro' ),
					'type'  => 'url',
					'class' => 'widefat',
					),
				'secondary_button_text' => array(
					'label'   => __( 'Secondary Button Text:', 'mediclean-pro' ),
					'default' => '',
					'type'    => 'text',
					'class'   => 'widefat',
					),
				'secondary_button_url' => array(
					'label' => __( 'Secondary Button URL:', 'mediclean-pro' ),
					'type'  => 'url',
					'class' => 'widefat',
					),
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-call-to-action', __( 'Mediclean: Call To Action', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}
			?>
			<div class="call-to-action-content">
				<?php if ( ! empty( $params['description'] ) ) : ?>
				    <div class="call-to-action-description">
				        <?php echo wp_kses_post( wpautop( $params['description'] ) ); ?>
				    </div><!-- .call-to-action-description -->
				<?php endif; ?>
				<?php if ( ! empty( $params['primary_button_text'] ) || ! empty( $params['secondary_button_text'] ) ) : ?>
					<div class="call-to-action-buttons">
						<?php if ( ! empty( $params['primary_button_text'] ) ) : ?>
							<a href="<?php echo esc_url( $params['primary_button_url'] ); ?>" class="custom-button btn-call-to-action btn-call-to-primary"><?php echo esc_html( $params['primary_button_text'] ); ?></a>
						<?php endif; ?>
						<?php if ( ! empty( $params['secondary_button_text'] ) ) : ?>
							<a href="<?php echo esc_url( $params['secondary_button_url'] ); ?>" class="custom-button btn-call-to-action btn-call-to-secondary"><?php echo esc_html( $params['secondary_button_text'] ); ?></a>
						<?php endif; ?>
					</div><!-- .call-to-action-buttons -->
				<?php endif; ?>
			</div><!-- .call-to-action-content -->
			<?php

			echo $args['after_widget'];

		}
	}
endif;


if ( ! class_exists( 'Mediclean_Services_Widget' ) ) :

	/**
	 * Social widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Services_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_services',
				'description'                 => __( 'Show your services.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'excerpt_length' => array(
					'label'       => __( 'Excerpt Length:', 'mediclean-pro' ),
					'description' => __( 'in words', 'mediclean-pro' ),
					'type'        => 'number',
					'css'         => 'max-width:60px;',
					'default'     => 15,
					'min'         => 1,
					'max'         => 400,
					'adjacent'    => true,
					),
				'disable_excerpt' => array(
					'label'   => __( 'Disable Excerpt', 'mediclean-pro' ),
					'type'    => 'checkbox',
					'default' => false,
					),
				);

			for( $i = 1; $i <= 8; $i++ ) {
				$fields[ 'block_heading_' . $i ] = array(
					'label' => __( 'Block', 'mediclean-pro' ) . ' #' . $i,
					'type'  => 'heading',
					'class' => 'widefat',
					);
				$fields[ 'block_page_' . $i ] = array(
					'label'            => __( 'Select Page:', 'mediclean-pro' ),
					'type'             => 'dropdown-pages',
					'show_option_none' => __( '&mdash; Select &mdash;', 'mediclean-pro' ),
					);
				$fields[ 'block_icon_' . $i ] = array(
					'label'       => __( 'Icon:', 'mediclean-pro' ),
					'description' => __( 'Eg: fa-cogs', 'mediclean-pro' ),
					'type'        => 'text',
					'default'     => 'fa-cogs',
					);
			}

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-services', __( 'Mediclean: Services', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$service_arr = array();
			for ( $i = 0; $i < 8 ; $i++ ) {
				$block = ( $i + 1 );
				$service_arr[ $i ] = array(
					'page' => $params[ 'block_page_' . $block ],
					'icon' => $params[ 'block_icon_' . $block ],
					);
			}
			$refined_arr = array();
			if ( ! empty( $service_arr ) ) {
				foreach ( $service_arr as $item ) {
					if ( ! empty( $item['page'] ) ) {
						$refined_arr[ $item['page'] ] = $item;
					}
				}
			}

			if ( ! empty( $refined_arr ) ) {
				$this->render_widget_content( $refined_arr, $params );
			}

			echo $args['after_widget'];

		}

		/**
		 * Render services content.
		 *
		 * @since 1.0.0
		 *
		 * @param array $service_arr Services array.
		 * @param array $params      Parameters array.
		 */
		function render_widget_content( $service_arr, $params ) {

			$page_ids = array_keys( $service_arr );

			$qargs = array(
				'post__in'       => $page_ids,
				'post_type'      => 'page',
				'posts_per_page' => count( $page_ids ),
				'orderby'        => 'post__in',
				'no_found_rows'  => true,
				);

			$all_posts = get_posts( $qargs );
			?>
			<?php if ( ! empty( $all_posts ) ) : ?>

				<?php global $post; ?>

				<div class="service-block-list">
					<div class="inner-wrapper">

						<?php $cnt = 1; ?>
						<?php foreach ( $all_posts as $post ) : ?>
							<?php setup_postdata( $post ); ?>
							<?php
								$odd_even_class = ( 0 === $cnt % 2 ) ? 'even' : 'odd' ;
								$cnt++;
							?>
							<div class="service-block-item <?php echo esc_attr( $odd_even_class ); ?>">
								<div class="service-block-inner">
									<?php if ( isset( $service_arr[ $post->ID ]['icon'] ) && ! empty( $service_arr[ $post->ID ]['icon'] ) ) : ?>
										<a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><i class="<?php echo 'fa ' . esc_attr( $service_arr[ $post->ID ]['icon'] ); ?>"></i></a>
									<?php endif; ?>
									<div class="service-block-inner-content">
										<h3 class="service-item-title">
											<a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>">
												<?php echo get_the_title( $post->ID ); ?>
											</a>
										</h3>
										<?php if ( true !== $params['disable_excerpt'] ) :  ?>
											<div class="service-block-item-excerpt">
												<?php
												$excerpt = mediclean_the_excerpt( $params['excerpt_length'], $post );
												echo wp_kses_post( wpautop( $excerpt ) );
												?>
											</div><!-- .service-block-item-excerpt -->
										<?php endif; ?>
									</div><!-- .service-block-inner-content -->
								</div><!-- .service-block-inner -->
							</div><!-- .service-block-item -->
						<?php endforeach; ?>

					</div><!-- .inner-wrapper -->

				</div><!-- .service-block-list -->

				<?php wp_reset_postdata(); ?>

			<?php endif; ?>

			<?php
		}

	}
endif;

if ( ! class_exists( 'Mediclean_Appointment_Widget' ) ) :

	/**
	 * Appointment widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Appointment_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_appointment',
				'description'                 => __( 'Displays appointment form.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'form_id' => array(
					'label'   => __( 'Select Form:', 'mediclean-pro' ),
					'type'    => 'select',
					'options' => mediclean_get_contact_form_options(),
					),
				'form_message' => array(
					'label' => _x( 'OR', 'Mediclean Appointment', 'mediclean-pro' ),
					'type'  => 'heading',
					),
				'form_shortcode' => array(
					'label' => __( 'Enter Form Shortcode:', 'mediclean-pro' ),
					'type'  => 'textarea',
					'class' => 'widefat',
					),
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-appointment', __( 'Mediclean: Appointment', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$shortcode_text = null;

			if ( ! empty( $params['form_id'] ) && absint( $params['form_id'] ) > 0 && defined( 'WPCF7_VERSION' ) ) {
				$shortcode_text = '[contact-form-7 id="' . absint( $params['form_id'] ) . '"]';
			}

			if ( empty( $shortcode_text ) ) {
				$shortcode_text = wp_kses_data( $params['form_shortcode'] );
			}

			if ( ! empty( $shortcode_text ) ) {
				echo do_shortcode( $shortcode_text );
			}

			echo $args['after_widget'];

		}
	}
endif;

if ( ! class_exists( 'Mediclean_Testimonial_Slider_Widget' ) ) :

	/**
	 * Testimonial Slider widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Testimonial_Slider_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'   => 'mediclean_widget_testimonial_slider',
				'description' => __( 'Displays Testimonials as a Slider.', 'mediclean-pro' ),
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'post_category' => array(
					'label'           => __( 'Select Category:', 'mediclean-pro' ),
					'type'            => 'dropdown-taxonomies',
					'show_option_all' => __( 'All Categories', 'mediclean-pro' ),
					),
				'post_number' => array(
					'label'   => __( 'Number of Posts:', 'mediclean-pro' ),
					'type'    => 'number',
					'default' => 4,
					'css'     => 'max-width:60px;',
					'min'     => 1,
					'max'     => 100,
					),
				'excerpt_length' => array(
					'label'       => __( 'Excerpt Length:', 'mediclean-pro' ),
					'description' => __( 'in words', 'mediclean-pro' ),
					'type'        => 'number',
					'css'         => 'max-width:60px;',
					'default'     => 30,
					'min'         => 1,
					'max'         => 400,
					'adjacent'    => true,
					),
				'background_image' => array(
					'label'   => __( 'Background Image:', 'mediclean-pro' ),
					'type'    => 'image',
					'default' => '',
					),
				'enable_background_overlay' => array(
					'label'   => __( 'Enable Background Overlay', 'mediclean-pro' ),
					'type'    => 'checkbox',
					'default' => true,
					),
				'slider_heading' => array(
					'label'   => __( 'SLIDER OPTIONS', 'mediclean-pro' ),
					'type'    => 'heading',
					),
				'transition_delay' => array(
					'label'       => __( 'Transition Delay:', 'mediclean-pro' ),
					'description' => __( 'in seconds', 'mediclean-pro' ),
					'type'        => 'number',
					'default'     => 3,
					'css'         => 'max-width:50px;',
					'min'         => 1,
					'max'         => 10,
					'adjacent'         => true,
					),
				'enable_autoplay' => array(
					'label'   => __( 'Enable Autoplay', 'mediclean-pro' ),
					'type'    => 'checkbox',
					'default' => true,
					),
				);

			if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'custom-content-types' ) ) {
				$extra_fields = array(
					'category_message' => array(
						'label' => __( 'OR', 'mediclean-pro' ),
						'type'  => 'message',
						'class' => 'widefat',
						),
					'use_jetpack' => array(
						'label'   => __( 'Use Jetpack Testimonials', 'mediclean-pro' ),
						'type'    => 'checkbox',
						'default' => false,
						),
					);
				mediclean_array_splice_preserve_keys( $fields, 2, 0, $extra_fields );
			}


			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-testimonial-slider', __( 'Mediclean: Testimonial Slider', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			// Add background image.
			if ( ! empty( $params['background_image'] ) ) {
				$background_style = '';
				$background_style .= ' style="background-image:url(' . esc_url( $params['background_image'] ) . ');" ';
				$args['before_widget'] = implode( $background_style . ' ' . 'class="', explode( 'class="', $args['before_widget'], 2 ) );
			}

			// Add overlay class.
			$overlay_class = ( true === $params['enable_background_overlay'] ) ? 'overlay-enabled' : 'overlay-disabled' ;
			$args['before_widget'] = implode( 'class="' . $overlay_class . ' ', explode( 'class="', $args['before_widget'], 2 ) );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$testimonial_posts = $this->get_testimonials( $params );

			if ( ! empty( $testimonial_posts ) ) {
				$this->render_testimonials( $testimonial_posts, $params );
			}

			echo $args['after_widget'];

		}

		/**
		 * Return testimonial posts detail.
		 *
		 * @since 1.0.0
		 *
		 * @param array $params Parameters.
		 * @return array Posts details.
		 */
		function get_testimonials( $params ) {

			$output = array();

			$qargs = array(
				'posts_per_page' => esc_attr( $params['post_number'] ),
				'no_found_rows'  => true,
				);
			if ( absint( $params['post_category'] ) > 0  ) {
				$qargs['category'] = absint( $params['post_category'] );
			}

			// Check if Jetpack enabled.
			if ( isset( $params['use_jetpack'] ) && true === $params['use_jetpack'] && class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'custom-content-types' ) ) {
				$qargs['category']  = null;
				$qargs['post_type'] = 'jetpack-testimonial';
			}

			$all_posts = get_posts( $qargs );

			if ( ! empty( $all_posts ) ) {
				$cnt = 0;
				global $post;
				foreach ( $all_posts as $key => $post ) {

					setup_postdata( $post );

					$item = array();
					$item['title']   = get_the_title( $post->ID );
					$item['excerpt'] = mediclean_the_excerpt( absint( $params['excerpt_length'] ), $post );
					$item['image']   = null;
					if ( has_post_thumbnail( $post->ID ) ) {
						$image_detail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
						if ( ! empty( $image_detail ) ) {
							$item['image'] = $image_detail;
						}
					}
					$output[ $cnt ] = $item;
					$cnt++;

				}
				wp_reset_postdata();
			}

			return $output;

		}

		/**
		 * Render testimonial slider.
		 *
		 * @since 1.0.0
		 *
		 * @param array $testimonials Testimonials.
		 * @param array $params Parameters.
		 * @return void
		 */
		function render_testimonials( $testimonials, $params ) {

			$timeout = 0;
			if ( true === $params['enable_autoplay'] ) {
				$timeout = 1000 * absint( $params['transition_delay'] );
			}
			?>
			<div class="cycle-slideshow"
				data-cycle-slides="> article"
				data-cycle-auto-height="container"
				data-cycle-timeout="<?php echo absint( $timeout ); ?>"
				>
				<div class="cycle-pager"></div>
				<?php foreach ( $testimonials as $testimonial ) : ?>
					<article>
						<div class="testimonial-wrapper">
							<div class="testimonial-content-area">
							<?php if ( ! empty( $testimonial['excerpt'] ) ) : ?>
								<div class="testimonial-excerpt">
									<?php echo wp_kses_post( wpautop( $testimonial['excerpt'] ) ); ?>
								</div><!-- .testimonial-excerpt -->
							<?php endif; ?>
							</div> <!-- .testimonial-content-area -->
							<?php if ( ! empty( $testimonial['image'] ) ) : ?>
								<img src="<?php echo esc_url( $testimonial['image'][0] ); ?>" />
							<?php endif; ?>
							<h4><?php echo esc_html( $testimonial['title'] ); ?></h4>
						</div>
					</article>

				<?php endforeach; ?>

			</div><!-- .cycle-slideshow -->
			<?php

		}

	}
endif;

if ( ! class_exists( 'Mediclean_Portfolio_Widget' ) ) :

	/**
	 * Portfolio widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Portfolio_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_portfolio',
				'description'                 => __( 'Displays portfolios.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'post_category' => array(
					'label'           => __( 'Select Category:', 'mediclean-pro' ),
					'type'            => 'dropdown-taxonomies',
					'show_option_all' => __( 'All Categories', 'mediclean-pro' ),
					),
				'post_column' => array(
					'label'   => __( 'Number of Columns:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 4,
					'options' => mediclean_get_numbers_dropdown_options( 3, 5 ),
					),
				'post_number' => array(
					'label'   => __( 'Number of Portfolios:', 'mediclean-pro' ),
					'type'    => 'number',
					'default' => 4,
					'css'     => 'max-width:60px;',
					'min'     => 1,
					'max'     => 100,
					),
				'featured_image' => array(
					'label'   => __( 'Featured Image:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 'medium',
					'options' => mediclean_get_image_sizes_options( false, array( 'thumbnail', 'medium' ), false ),
					),
				);

			if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'custom-content-types' ) ) {
				$extra_fields = array(
					'category_message' => array(
						'label' => __( 'OR', 'mediclean-pro' ),
						'type'  => 'message',
						'class' => 'widefat',
						),
					'use_jetpack' => array(
						'label'   => __( 'Use Jetpack Portfolio', 'mediclean-pro' ),
						'type'    => 'checkbox',
						'default' => false,
						),
					'portfolio_category' => array(
						'label'           => __( 'Select Jetpack Project Types:', 'mediclean-pro' ),
						'type'            => 'dropdown-taxonomies',
						'taxonomy'        => 'jetpack-portfolio-type',
						'show_option_all' => __( 'All Project Types', 'mediclean-pro' ),
						),
					);
				mediclean_array_splice_preserve_keys( $fields, 2, 0, $extra_fields );
			}



			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-portfolio', __( 'Mediclean: Portfolio', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$portfolio_posts = $this->get_portfolios( $params );

			if ( ! empty( $portfolio_posts ) ) {
				$this->render_portfolio( $portfolio_posts, $params );
			}

			echo $args['after_widget'];

		}

		/**
		 * Return portfolios posts detail.
		 *
		 * @since 1.0.0
		 *
		 * @param array $params Parameters.
		 * @return array Posts details.
		 */
		function get_portfolios( $params ) {

			$output = array();

			$qargs = array(
				'posts_per_page' => esc_attr( $params['post_number'] ),
				'no_found_rows'  => true,
				'meta_key'       => '_thumbnail_id',
			);
			if ( absint( $params['post_category'] ) > 0  ) {
				$qargs['category'] = absint( $params['post_category'] );
			}

			// Check if Jetpack Portfolio enabled.
			if ( isset( $params['use_jetpack'] ) && true === $params['use_jetpack'] && class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'custom-content-types' ) ) {
				$qargs['post_type'] = 'jetpack-portfolio';
				$qargs['category']  = null;
				if ( absint( $params['portfolio_category'] ) > 0  ) {
					$qargs['tax_query'] = array(
						array(
							'taxonomy' => 'jetpack-portfolio-type',
							'field'    => 'term_id',
							'terms'    => absint( $params['portfolio_category'] ),
							),
						);
				}
			}

			$all_posts = get_posts( $qargs );
			if ( ! empty( $all_posts ) ) {
				$cnt = 0;
				global $post;
				foreach ( $all_posts as $key => $post ) {

					setup_postdata( $post );

					$item = array();
					$item['ID']    = $post->ID;
					$item['title'] = get_the_title( $post->ID );
					$item['url']   = get_permalink( $post->ID );
					$item['image'] = null;
					if ( has_post_thumbnail( $post->ID ) ) {
						$image_detail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), esc_attr( $params['featured_image'] ) );
						if ( ! empty( $image_detail ) ) {
							$item['image'] = $image_detail;
						}
					}

					$output[ $cnt ] = $item;
					$cnt++;

				}
				wp_reset_postdata();
			}

			return $output;

		}

		/**
		 * Render portfolios.
		 *
		 * @since 1.0.0
		 *
		 * @param array $portfolios Posts detail.
		 * @param array $params Parameters.
		 * @return void
		 */
		function render_portfolio( $portfolios, $params ) {

			?>
			<div class="portfolio-wrapper portfolio-col-<?php echo absint( $params['post_column'] ); ?>">

				<?php foreach ($portfolios as $portfolio ) : ?>
					<div class="portfolio-image">
						<div class="portfolio-image-inner">
							<a href="<?php echo esc_url( $portfolio['url'] ); ?>">
								<img src="<?php echo esc_url( $portfolio['image'][0] ); ?>" alt="" />
								<h4><?php echo esc_html( $portfolio['title'] ); ?></h4>
							</a>
						</div><!-- .portfolio-image-inner -->
					</div><!-- .portfolio-image -->
				<?php endforeach; ?>

			</div><!-- .portfolio-wrapper -->
			<?php

		}

	}
endif;

if ( ! class_exists( 'Mediclean_Clients_Widget' ) ) :

	/**
	 * Clients widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Clients_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_clients',
				'description'                 => __( 'Displays clients.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				);

			$fields['message'] = array(
				'label' => __( 'This displays client logos entered in the Theme Options. To add/update logos, go to Appearance -> Customize -> Theme Options -> Clients Options', 'mediclean-pro' ),
				'type'  => 'message',
				'class' => 'widefat',
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-clients', __( 'Mediclean: Clients', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$featured_clients_number = absint( mediclean_get_option( 'featured_clients_number' ) );

			if ( absint( $featured_clients_number ) > 0 ) {
				$this->render_clients( $params );
			}

			//
			echo $args['after_widget'];

		}

		/**
		 * Render clients.
		 *
		 * @since 1.0.0
		 *
		 * @param array $params Parameters.
		 * @return void
		 */
		function render_clients( $params ) {

			$featured_clients_number = absint( mediclean_get_option( 'featured_clients_number' ) );

			$clients_logos = array();
			for( $i=1 ; $i <= $featured_clients_number ; $i ++ ){
				$clients_image =   mediclean_get_option( 'featured_clients_image_' .$i);
				$clients_link  =   mediclean_get_option( 'featured_clients_link_' .$i);
					if ( ! empty( $clients_image ) ) {
						$clients_logos[$i]['image'] = $clients_image;
						$clients_logos[$i]['link']  = $clients_link;
					}
			}
			if ( empty( $clients_logos ) ) {
				return;
			}
			?>
			<div class="clients-wrapper">

			<?php foreach ( $clients_logos as $client ) : ?>
				<div class="client-item">
					<?php
					$link_open  = '';
					$link_close = '';
					if ( ! empty( $client['link'] ) ) {
						$link_open  = '<a href="' . esc_url( $client['link'] ) . '" target="_blank">';
						$link_close = '</a>';
					}

					?>
					<?php echo $link_open; ?><img src="<?php echo esc_url( $client['image'] ); ?>" alt="" /><?php echo $link_close; ?>
				</div><!-- .client-item -->

			<?php endforeach; ?>

			</div><!-- .clients-wrapper -->
			<?php
		}

	}
endif;


if ( ! class_exists( 'Mediclean_Pricing_Table_Widget' ) ) :

	/**
	 * Pricing Table widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Pricing_Table_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_pricing_table',
				'description'                 => __( 'Displays Pricing Table.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'form_id' => array(
					'label'   => __( 'Select Pricing Table:', 'mediclean-pro' ),
					'type'    => 'select',
					'options' => mediclean_get_pricing_table_options(),
					),
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			if ( ! shortcode_exists( 'rpt' ) ) {
				$fields = array();
				$fields['message'] = array(
					'label' => __( 'Please activate Responsive Pricing Table plugin to use this widget.', 'mediclean-pro' ),
					'type'  => 'message',
					'class' => 'widefat',
					);
			}

			parent::__construct( 'mediclean-pricing-table', __( 'Mediclean: Pricing Table', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			if ( isset( $params['form_id'] ) && absint( $params['form_id'] ) > 0 && 'publish' === get_post_status( $params['form_id'] ) && shortcode_exists( 'rpt' ) ) {
				$this->render_pricing_table( $params );
			}

			echo $args['after_widget'];

		}

		/**
		 * Render pricing table.
		 *
		 * @since 1.0.0
		 *
		 * @param array $params Parameters.
		 * @return void
		 */
		function render_pricing_table( $params ) {

			$form_id = absint( $params['form_id'] );
			$entries = get_post_meta( $form_id, '_rpt_plan_group', true );

			$currency = get_post_meta( $form_id, '_rpt_currency', true );
			$newcurrentwindow = get_post_meta( $form_id, '_rpt_open_newwindow', true );

			$column = count( $entries );
			if ( $column < 1 ) {
				return;
			}
			?>
			<div class="pricing-table-wrapper">
				<div class="pricing-table-inner pricing-table-grid-<?php echo absint( $column ); ?>">

					<?php foreach ( $entries as $key => $plan ) : ?>

						<?php
						$is_recommended = isset( $plan['_rpt_recommended'] ) ? $plan['_rpt_recommended'] : '';
						$recommended_class = '';
						if ( 'on' === $is_recommended ) {
							$recommended_class = 'pricing-plan-recommended';
						}
						$plan_image_style = '';
						if ( ! empty( $plan['_rpt_plan_image'] ) ) {
							$plan_image_style = 'background-image:url(' . esc_url( $plan['_rpt_plan_image'] ) . ');';
						}
						?>

						<div class="pricing-plan-item <?php echo esc_attr( $recommended_class ); ?>">

							<div class="pricing-plan-header" style="<?php echo $plan_image_style ?>">

								<?php if ( ! empty( $plan['_rpt_price'] ) ) : ?>
									<div class="pricing-plan-cost">
										<?php if ( ! empty( $currency ) ) : ?>
											<span class="pricing-plan-currency"><?php echo esc_html( $currency ); ?></span>
										<?php endif; ?>
										<span class="pricing-plan-price"><?php echo esc_html( $plan['_rpt_price'] ); ?></span>
										<?php if ( ! empty( $plan['_rpt_recurrence'] ) ) : ?>
											<span class="pricing-plan-currency"><?php echo esc_html( $plan['_rpt_recurrence'] ); ?></span>
										<?php endif; ?>
									</div><!-- .pricing-plan-cost -->
								<?php endif; ?>
								<?php if ( ! empty( $plan['_rpt_title'] ) ) : ?>
									<div class="pricing-plan-title">
										<h4><?php echo esc_html( $plan['_rpt_title'] ); ?></h4>
									</div><!-- .pricing-plan-title -->
								<?php endif; ?>
							</div><!-- .pricing-plan-header -->

							<div class="pricing-plan-content">
								<?php if ( ! empty( $plan['_rpt_features'] ) ) : ?>
									<div class="pricing-plan-features">
										<?php echo $this->parse_pricing_feature( $plan['_rpt_features'] ); ?>
									</div><!-- .pricing-plan-features -->
								<?php endif; ?>

							</div><!-- .pricing-plan-content -->

							<div class="pricing-plan-footer">
								<?php if ( ! empty( $plan['_rpt_btn_custom_btn'] ) ) : ?>
									<div class="pricing-plan-custom-button"><?php echo do_shortcode( $plan['_rpt_btn_custom_btn'] ); ?></div><!-- .pricing-plan-custom-button -->
								<?php else : ?>
									<?php if ( ! empty( $plan['_rpt_btn_text'] ) && ! empty( $plan['_rpt_btn_link'] ) ) : ?>
										<div class="pricing-plan-button">
										<?php
											$link_open = '<a class="custom-button" href="' . esc_url( $plan['_rpt_btn_link'] ) . '"';
											if ( 'newwindow' === $newcurrentwindow  ) {
												$link_open .= ' target="_blank"';
											}
											$link_open .= '>';
											$link_close = '</a>';
										?>
										<?php echo $link_open . esc_html( $plan['_rpt_btn_text'] ) . $link_close; ?>
										</div><!-- .pricing-plan-button -->
									<?php endif; ?>

								<?php endif; ?>

							</div><!-- .pricing-plan-footer -->

						</div><!-- .pricing-plan-item -->

					<?php endforeach; ?>

				</div><!-- .pricing-table-inner -->
			</div><!-- .pricing-table-wrapper -->

			<?php

		}

		/**
		 * Parse pricing plan features.
		 *
		 * @since 1.0.0
		 *
		 * @param string $feature Feature.
		 * @return string Parsed feature content.
		 */
		function parse_pricing_feature( $feature ) {

			$output = '';

			$raw_features = explode( "\n", $feature );
			$raw_features = array_filter( $raw_features, 'trim' );

			$features = array();

			foreach ( $raw_features as $f ) {
				$features[] = strip_tags( $f,'<strong></strong><br><br/></br><img><a>' );
			}

			if ( ! empty( $features ) ) {
				foreach ( $features as $fkey => $ft ) {
					$ft = trim( $ft );
					$check = substr( $ft, 0, 2 );
					if ( '-n' === $check ) {
						$ft = substr( $ft, 2 );
						$output .= '<span class="pricing-plan-feature pricing-plan-feature-dim">' . esc_html( $ft ) . '</span>';
					}
					else {
						$output .= '<span class="pricing-plan-feature">' . esc_html( $ft ) . '</span>';
					}
				}
			}

			return $output;

		}

	}
endif;

if ( ! class_exists( 'Mediclean_Recent_Posts_Widget' ) ) :

	/**
	 * Recent posts widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Recent_Posts_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_recent_posts',
				'description'                 => __( 'Displays recent posts.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'post_category' => array(
					'label'           => __( 'Select Category:', 'mediclean-pro' ),
					'type'            => 'dropdown-taxonomies',
					'show_option_all' => __( 'All Categories', 'mediclean-pro' ),
					),
				'post_number' => array(
					'label'   => __( 'Number of Posts:', 'mediclean-pro' ),
					'type'    => 'number',
					'default' => 4,
					'css'     => 'max-width:60px;',
					'min'     => 1,
					'max'     => 100,
					),
				'featured_image' => array(
					'label'   => __( 'Featured Image:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 'thumbnail',
					'options' => mediclean_get_image_sizes_options( true, array( 'disable', 'thumbnail' ), false ),
					),
				'image_width' => array(
					'label'       => __( 'Image Width:', 'mediclean-pro' ),
					'type'        => 'number',
					'description' => __( 'px', 'mediclean-pro' ),
					'css'         => 'max-width:60px;',
					'adjacent'    => true,
					'default'     => 90,
					'min'         => 1,
					'max'         => 150,
					),
				'disable_date' => array(
					'label'   => __( 'Disable Date', 'mediclean-pro' ),
					'type'    => 'checkbox',
					'default' => false,
					),
				);

			parent::__construct( 'mediclean-recent-posts', __( 'Mediclean: Recent Posts', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$qargs = array(
				'posts_per_page' => esc_attr( $params['post_number'] ),
				'no_found_rows'  => true,
				);
			if ( absint( $params['post_category'] ) > 0  ) {
				$qargs['category'] = $params['post_category'];
			}
			$all_posts = get_posts( $qargs );

			?>
			<?php if ( ! empty( $all_posts ) ) :  ?>

				<?php global $post; ?>

				<div class="recent-posts-wrapper">

					<?php foreach ( $all_posts as $key => $post ) :  ?>
						<?php setup_postdata( $post ); ?>

						<div class="recent-posts-item">

							<?php if ( 'disable' !== $params['featured_image'] && has_post_thumbnail() ) :  ?>
								<div class="recent-posts-thumb">
									<a href="<?php the_permalink(); ?>">
										<?php
										$img_attributes = array(
											'class' => 'alignleft',
											'style' => 'max-width:' . esc_attr( $params['image_width'] ). 'px;',
											);
										the_post_thumbnail( esc_attr( $params['featured_image'] ), $img_attributes );
										?>
									</a>
								</div><!-- .recent-posts-thumb -->
							<?php endif ?>
							<div class="recent-posts-text-wrap">
								<h3 class="recent-posts-title">
									<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
								</h3><!-- .recent-posts-title -->

								<?php if ( false === $params['disable_date'] ) :  ?>
									<div class="recent-posts-meta">

										<?php if ( false === $params['disable_date'] ) :  ?>
											<span class="recent-posts-date"><?php the_time( get_option( 'date_format' ) ); ?></span><!-- .recent-posts-date -->
										<?php endif; ?>

									</div><!-- .recent-posts-meta -->
								<?php endif; ?>

							</div><!-- .recent-posts-text-wrap -->

						</div><!-- .recent-posts-item -->

					<?php endforeach; ?>

				</div><!-- .recent-posts-wrapper -->

				<?php wp_reset_postdata(); // Reset. ?>

			<?php endif; ?>

			<?php
			echo $args['after_widget'];

		}
	}
endif;

if ( ! class_exists( 'Mediclean_Teams_Widget' ) ) :

	/**
	 * Teams widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Teams_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_teams',
				'description'                 => __( 'Displays teams.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'post_category' => array(
					'label'           => __( 'Select Category:', 'mediclean-pro' ),
					'type'            => 'dropdown-taxonomies',
					'show_option_all' => __( 'All Categories', 'mediclean-pro' ),
					),
				'post_number' => array(
					'label'   => __( 'Number of Posts:', 'mediclean-pro' ),
					'type'    => 'number',
					'default' => 3,
					'css'     => 'max-width:60px;',
					'min'     => 1,
					'max'     => 100,
					),
				'post_column' => array(
					'label'   => __( 'Number of Columns:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 3,
					'options' => mediclean_get_numbers_dropdown_options( 1, 4 ),
					),
				'featured_image' => array(
					'label'   => __( 'Featured Image:', 'mediclean-pro' ),
					'type'    => 'select',
					'default' => 'medium',
					'options' => mediclean_get_image_sizes_options( false, array( 'thumbnail', 'medium' ), false ),
					),
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-teams', __( 'Mediclean: Teams', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$team_posts = $this->get_teams( $params );

			if ( ! empty( $team_posts ) ) {
				$this->render_teams( $team_posts, $params );
			}

			echo $args['after_widget'];

		}

		/**
		 * Return teams posts detail.
		 *
		 * @since 1.0.0
		 *
		 * @param array $params Parameters.
		 * @return array Posts details.
		 */
		function get_teams( $params ) {

			$output = array();

			$qargs = array(
				'posts_per_page' => esc_attr( $params['post_number'] ),
				'no_found_rows'  => true,
				'meta_key'       => '_thumbnail_id',
			);
			if ( absint( $params['post_category'] ) > 0  ) {
				$qargs['category'] = absint( $params['post_category'] );
			}

			$all_posts = get_posts( $qargs );
			if ( ! empty( $all_posts ) ) {
				$cnt = 0;
				global $post;
				foreach ( $all_posts as $key => $post ) {

					setup_postdata( $post );

					$item = array();
					$item['ID']    = $post->ID;
					$item['title'] = get_the_title( $post->ID );
					$item['url']   = get_permalink( $post->ID );
					$item['image'] = null;
					if ( has_post_thumbnail( $post->ID ) ) {
						$image_detail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), esc_attr( $params['featured_image'] ) );
						if ( ! empty( $image_detail ) ) {
							$item['image'] = $image_detail;
						}
					}
					$item['position'] = null;
					$item['address']  = null;
					$item['phone']    = null;
					$item['social']   = array();

					$output[ $cnt ] = $item;
					$cnt++;

				}
				wp_reset_postdata();
			}

			return $output;

		}

		/**
		 * Render teams.
		 *
		 * @since 1.0.0
		 *
		 * @param array $team_posts Team posts.
		 * @param array $params Parameters.
		 * @return void
		 */
		function render_teams( $team_posts, $params ) {
			?>

			<?php if ( ! empty( $team_posts ) ) : ?>

				<div class="teams-widget teams-col-<?php echo esc_attr( $params['post_column'] ); ?>">
					<div class="inner-wrapper">
						<?php foreach ( $team_posts as $key => $team ) : ?>

							<div class="team-item">
							<?php if ( ! empty( $team['image'] ) ) : ?>
								<div class="thumb-summary-wrap">
									<div class="team-thumb">
										<a href="<?php echo esc_url( $team['url'] ); ?>">
											<img src="<?php echo esc_url( $team['image'][0] ) ?>" alt="" />
										</a>
									</div><!-- .team-thumb-->
									<div class="team-text-wrap">
										<h3 class="team-title"><a href="<?php echo esc_url( $team['url'] ); ?>"><?php echo esc_html( $team['title'] ); ?></a>
										<?php if ( ! empty( $team['position'] ) ) : ?>
											<span class="position"><?php echo esc_html( $team['position'] ); ?></span>
										<?php endif; ?>
										</h3>
									</div><!-- .team-text-wrap -->
								</div><!-- .thumb-summary-wrap-->
								<?php if ( ! empty( $team['phone'] ) || ! empty( $team['address'] ) ) : ?>
									<div class="team-meta">
										<?php if ( ! empty( $team['phone'] ) ) : ?>
											<span class="phone"><?php echo esc_html( $team['phone'] ); ?></span>
										<?php endif; ?>
										<?php if ( ! empty( $team['address'] ) ) : ?>
											<span class="address"><?php echo esc_html( $team['address'] ); ?></span>
										<?php endif; ?>
									</div><!-- .team-meta -->
								<?php endif; ?>
								<?php if ( ! empty( $team['social'] ) ) : ?>
									<div class="team-social">
										<ul>
										<?php foreach ( $team['social'] as $k => $v ) : ?>
											<?php if ( 'email' === $k ) : ?>
												<li><a target="_blank" href="mailto:<?php echo esc_attr( $v ); ?>" class="<?php echo esc_attr( $k ); ?>"></a></li>
											<?php else : ?>
												<li><a target="_blank" href="<?php echo esc_url( $v ); ?>" class="<?php echo esc_attr( $k ); ?>"></a></li>
											<?php endif; ?>
										<?php endforeach; ?>
										</ul>
									</div><!-- .team-social -->
								<?php endif; ?>
							<?php endif; ?>

							</div><!-- .team-item -->
						<?php endforeach; ?>

					</div><!-- .inner-wrapper -->
				</div><!-- .teams-widget -->

				<?php wp_reset_postdata(); ?>

			<?php endif; ?>

			<?php

		}

	}
endif;

if ( ! class_exists( 'Mediclean_Skills_Widget' ) ) :

	/**
	 * Skills widget Class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Skills_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'   => 'mediclean_widget_skills',
				'description' => __( 'Displays skill charts.', 'mediclean-pro' ),
				);
			$fields = array(
				'title' => array(
					'label' => __( 'Title:', 'mediclean-pro' ),
					'type'  => 'text',
					'class' => 'widefat',
					),
				'skill_id' => array(
					'label'   => __( 'Select Skills:', 'mediclean-pro' ),
					'type'    => 'select',
					'options' => mediclean_get_skills_options(),
					),
				'skill_message' => array(
					'label' => _x( 'OR', 'Mediclean Skills', 'mediclean-pro' ),
					'type'  => 'heading',
					),
				'skills_shortcode' => array(
					'label' => __( 'Enter Skills Shortcode:', 'mediclean-pro' ),
					'type'  => 'textarea',
					'class' => 'widefat',
					),
				);

			parent::__construct( 'mediclean-skills', __( 'Mediclean: Skills', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$shortcode_text = null;

			if ( ! empty( $params['skill_id'] ) && absint( $params['skill_id'] ) > 0 && class_exists( 'WEN_Skill_Charts' ) ) {
				$shortcode_text = '[wsc id="' . absint( $params['skill_id'] ) . '"]';
			}

			if ( empty( $shortcode_text ) ) {
				$shortcode_text = wp_kses_data( $params['skills_shortcode'] );
			}

			if ( ! empty( $shortcode_text ) ) {
				echo do_shortcode( $shortcode_text );
			}

			echo $args['after_widget'];

		}
	}
endif;

if ( ! class_exists( 'Mediclean_Information_Widget' ) ) :

	/**
	 * Information widget class.
	 *
	 * @since 1.0.0
	 */
	class Mediclean_Information_Widget extends Mediclean_Widget_Base {

		/**
		 * Sets up a new widget instance.
		 *
		 * @since 1.0.0
		 */
		function __construct() {

			$opts = array(
				'classname'                   => 'mediclean_widget_information',
				'description'                 => __( 'Display information blocks.', 'mediclean-pro' ),
				'customize_selective_refresh' => true,
				);

			$fields = array();

			for( $i = 1; $i <= 3; $i++ ) {
				$fields[ 'block_heading_' . $i ] = array(
					'label' => __( 'Block', 'mediclean-pro' ) . ' #' . $i,
					'type'  => 'heading',
					'class' => 'widefat',
					);
				$fields[ 'block_page_' . $i ] = array(
					'label'            => __( 'Select Page:', 'mediclean-pro' ),
					'type'             => 'dropdown-pages',
					'show_option_none' => __( '&mdash; Select &mdash;', 'mediclean-pro' ),
					);
				$fields[ 'block_icon_' . $i ] = array(
					'label'       => __( 'Icon:', 'mediclean-pro' ),
					'description' => __( 'Eg: fa-cogs', 'mediclean-pro' ),
					'type'        => 'text',
					'default'     => 'fa-cogs',
					);
			}

			// Background options.
			$fields['background_heading'] = array(
				'label' => __( 'Background', 'mediclean-pro' ),
				'type'  => 'heading',
				'class' => 'widefat',
				);
			$fields['background_image'] = array(
				'label'   => __( 'Background Image:', 'mediclean-pro' ),
				'type'    => 'image',
				'default' => '',
				);
			$fields['enable_background_overlay'] = array(
				'label'   => __( 'Enable Background Overlay', 'mediclean-pro' ),
				'type'    => 'checkbox',
				'default' => true,
				);

			$animation_fields = mediclean_get_widget_animation_fields();
			$fields = array_merge( $fields, $animation_fields );

			parent::__construct( 'mediclean-information', __( 'Mediclean: Information', 'mediclean-pro' ), $opts, array(), $fields );

		}

		/**
		 * Outputs the content for the current widget instance.
		 *
		 * @since 1.0.0
		 *
		 * @param array $args     Display arguments.
		 * @param array $instance Settings for the current widget instance.
		 */
		function widget( $args, $instance ) {

			$params = $this->get_params( $instance );
			$args = $this->add_animation( $args, $params );

			// Add background image.
			if ( ! empty( $params['background_image'] ) ) {
				$background_style = '';
				$background_style .= ' style="background-image:url(' . esc_url( $params['background_image'] ) . ');" ';
				$args['before_widget'] = implode( $background_style . ' ' . 'class="', explode( 'class="', $args['before_widget'], 2 ) );
			}

			// Add overlay class.
			$overlay_class = ( true === $params['enable_background_overlay'] ) ? 'overlay-enabled' : 'overlay-disabled' ;
			$args['before_widget'] = implode( 'class="' . $overlay_class . ' ', explode( 'class="', $args['before_widget'], 2 ) );

			echo $args['before_widget'];

			if ( ! empty( $params['title'] ) ) {
				echo $args['before_title'] . $params['title'] . $args['after_title'];
			}

			$information_arr = array();
			for ( $i = 0; $i < 3 ; $i++ ) {
				$block = ( $i + 1 );
				$information_arr[ $i ] = array(
					'page' => $params[ 'block_page_' . $block ],
					'icon' => $params[ 'block_icon_' . $block ],
					);
			}
			$refined_arr = array();
			if ( ! empty( $information_arr ) ) {
				foreach ( $information_arr as $item ) {
					if ( ! empty( $item['page'] ) ) {
						$refined_arr[ $item['page'] ] = $item;
					}
				}
			}

			if ( ! empty( $refined_arr ) ) {
				$this->render_widget_content( $refined_arr, $params );
			}

			echo $args['after_widget'];

		}

		/**
		 * Render information content.
		 *
		 * @since 1.0.0
		 *
		 * @param array $information_arr Information array.
		 * @param array $params          Parameters array.
		 */
		function render_widget_content( $information_arr, $params ) {

			$column = count( $information_arr );

			$page_ids = array_keys( $information_arr );

			$qargs = array(
				'post__in'      => $page_ids,
				'post_type'     => 'page',
				'orderby'       => 'post__in',
				'no_found_rows' => true,
				);

			$all_posts = get_posts( $qargs );
			?>
			<?php if ( ! empty( $all_posts ) ) : ?>

				<?php global $post; ?>

				<div class="information-block-list information-col-<?php echo esc_attr( $column ); ?>">
					<div class="inner-wrapper">

						<?php foreach ( $all_posts as $post ) : ?>
							<?php setup_postdata( $post ); ?>

							<div class="information-block-item">
								<div class="information-block-inner">
									<div class="information-block-inner-content">
										<h3 class="information-item-title">
											<?php if ( isset( $information_arr[ $post->ID ]['icon'] ) && ! empty( $information_arr[ $post->ID ]['icon'] ) ) : ?>
												<i class="<?php echo 'fa ' . esc_attr( $information_arr[ $post->ID ]['icon'] ); ?>"></i>
											<?php endif; ?>
											<?php the_title(); ?>
										</h3>
										<div class="content-wrap">
											<?php the_content(); ?>
										</div>
									</div><!-- .information-block-inner-content -->
								</div><!-- .information-block-inner -->
							</div><!-- .information-block-item -->
						<?php endforeach; ?>

					</div><!-- .inner-wrapper -->

				</div><!-- .information-block-list -->

				<?php wp_reset_postdata(); ?>

			<?php endif; ?>

			<?php
		}

	}
endif;
