<?php
/**
 * YITH WooCommerce Wishlist integration.
 *
 * @package MenuVerse
 */

namespace WPXero\MenuVerse\Compat;

defined( 'ABSPATH' ) || exit;

/**
 * Supplies the wishlist count badge.
 *
 * Unlike WooCommerce, YITH publishes no REST route for the wishlist count, so
 * MenuVerse exposes its own — see Rest\Counts_Controller.
 */
class Yith_Wishlist implements Integration {

	/**
	 * Returns the integration identifier.
	 *
	 * @return string
	 */
	public static function id() {
		return 'yith_wishlist';
	}

	/**
	 * Returns the translated plugin name.
	 *
	 * @return string
	 */
	public static function label() {
		return __( 'YITH WooCommerce Wishlist', 'menuverse' );
	}

	/**
	 * Tells whether the wishlist plugin is active.
	 *
	 * Both the class and the accessor function are checked because the count
	 * below goes through the function, and older releases shipped one without
	 * the other.
	 *
	 * @return bool
	 */
	public static function is_active() {
		return class_exists( 'YITH_WCWL' ) && function_exists( 'YITH_WCWL' );
	}

	/**
	 * Returns the number of products on the current visitor's wishlist.
	 *
	 * @return int
	 */
	public static function count() {
		if ( ! self::is_active() ) {
			return 0;
		}

		return (int) YITH_WCWL()->count_products();
	}
}
