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

if ( ! function_exists( 'qode_badges_for_woocommerce_filter_sale_flash_empty' ) ) {
	/*
	 * * Removes Sale from WooCommerce single and Lists not used in blocks
	 */
	function qode_badges_for_woocommerce_filter_sale_flash_empty( $html ) {
		$option_value = qode_badges_for_woocommerce_get_option_value( 'admin', 'qode_badges_for_woocommerce_hide_sale_badge' );

		if ( 'yes' === $option_value ) {
			return '';
		}

		return $html;
	}
	add_filter( 'woocommerce_sale_flash', 'qode_badges_for_woocommerce_filter_sale_flash_empty', 1000, 3 );
}

if ( ! function_exists( 'qode_badges_for_woocommerce_filter_block_sale_flash_empty' ) ) {
	/*
	 * * Removes Sale from WooCommerce single and Lists used as blocks
	 */
	function qode_badges_for_woocommerce_filter_block_sale_flash_empty( $block ) {
		if ( 'woocommerce/product-image' === $block['blockName'] ) {
			$option_value = qode_badges_for_woocommerce_get_option_value( 'admin', 'qode_badges_for_woocommerce_hide_sale_badge' );

			if ( 'yes' === $option_value ) {
				$block['attrs']['showSaleBadge'] = false;
			}
		}

		return $block;
	}
	add_filter( 'render_block_data', 'qode_badges_for_woocommerce_filter_block_sale_flash_empty', 20 );
}

if ( ! function_exists( 'qode_badges_for_woocommerce_default_value' ) ) {
	function qode_badges_for_woocommerce_default_value( $field_type = '' ) {
		$default_value = apply_filters( 'qode_badges_for_woocommerce_filter_default_value', '', $field_type );

		return $default_value;
	}
}
