<?php

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

if ( ! class_exists( 'Qode_Badges_For_WooCommerce_Qode_Essential' ) ) {
	class Qode_Badges_For_WooCommerce_Qode_Essential {
		private static $instance;

		public function __construct() {

			if ( qode_badges_for_woocommerce_is_installed( 'qode-essential' ) ) {

				$hide_sale = qode_badges_for_woocommerce_get_option_value( 'admin', 'qode_badges_for_woocommerce_hide_sale_badge' );

				if ( 'yes' === $hide_sale ) {
					remove_action( 'qode_essential_addons_action_woo_product_mark_info', 'qi_add_sale_flash_on_product', 10 );
				}

				// 1000 position is to make sure it is on last place in before_shop_loop_item_title.
				remove_action( 'woocommerce_before_shop_loop_item_title', 'qode_badges_for_woocommerce_before_title_html', 1000 );
				add_action( 'woocommerce_shop_loop_item_title', 'qode_badges_for_woocommerce_before_title_html', 6 );
			}
		}

		/**
		 * Instance of module class
		 *
		 * @return Qode_Badges_For_WooCommerce_Qode_Essential
		 */
		public static function get_instance() {
			if ( is_null( self::$instance ) ) {
				self::$instance = new self();
			}

			return self::$instance;
		}
	}
}

if ( ! function_exists( 'qode_badges_for_woocommerce_init_qode_essential_module' ) ) {
	/**
	 * Init quick view module instance.
	 */
	function qode_badges_for_woocommerce_init_qode_essential_module() {
		Qode_Badges_For_WooCommerce_Qode_Essential::get_instance();
	}

	// Permission 15 is set in order to load after option initialization ( init_options method).
	add_action( 'init', 'qode_badges_for_woocommerce_init_qode_essential_module', 15 );
}
