<?php

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

/**
 * Wishlist Widget
 *
 * Displays wishlist widget
 *
 * @author   develoved
 * @category Widgets
 * @package  WooCommerce/Widgets
 * @version  1.0.0
 * @extends  WC_Widget
 */
if ( !class_exists('YITH_Widget_wishlist' ) && class_exists('WC_Widget' ) ) {
	class YITH_Widget_wishlist extends WC_Widget {

		/**
		 * Constructor
		 */
		public function __construct() {
			$this->widget_cssclass    = 'woocommerce widget_wishlist widget_shopping_cart';
			$this->widget_description = esc_html__( "Display the user's Wishlist in the sidebar.", 'ux-shop' );
			$this->widget_id          = 'shrk_widget_wishlist';
			$this->widget_name        = esc_html__( 'YITH Wishlist', 'ux-shop' );
			$this->settings           = array(
				'title'  => array(
					'type'  => 'text',
					'std'   => esc_html__( 'Wishlist', 'ux-shop' ),
					'label' => esc_html__( 'Title', 'ux-shop' )
				),
				'hide_if_empty' => array(
					'type'  => 'checkbox',
					'std'   => 0,
					'label' => esc_html__( 'Hide if wishlist is empty', 'ux-shop' )
				)
			);

			parent::__construct();
		}

		/**
		 * widget function.
		 *
		 * @see WP_Widget
		 *
		 * @param array $args
		 * @param array $instance
		 */
		public function widget( $args, $instance ) {
			$hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;

			$this->widget_start( $args, $instance );

			if ( $hide_if_empty ) {
				echo '<div class="hide_wishlist_widget_if_empty">';
			}

			// Insert wishlist widget placeholder - code in yith-wishlist.js will update this on page load
			echo '<div class="widget_wishlist_content"></div>';

			if ( $hide_if_empty ) {
				echo '</div>';
			}

			$this->widget_end( $args );
		}
	}

	add_action( 'widgets_init', function () {
		register_widget( 'YITH_Widget_wishlist' );
	});
}

?>