<?php
/**
 * Formats unit price / Grundpreis (PAngV) for label output.
 *
 * @package PhoenixWP\PriceLabels
 */

declare(strict_types=1);

namespace PhoenixWP\PriceLabels\Compliance;

use WC_Product;

defined( 'ABSPATH' ) || exit;

/**
 * Resolves Grundpreis text from WooCommerce and common compliance plugins.
 */
final class Unit_Price_Formatter {

	/**
	 * Returns formatted unit price line or empty string when not applicable.
	 *
	 * @param WC_Product $product Product.
	 */
	public static function format( WC_Product $product ): string {
		$text = Unit_Price_Resolver::resolve( $product );

		/**
		 * Filters formatted unit price line for the label.
		 *
		 * @param string     $text    Formatted line.
		 * @param WC_Product $product Product.
		 */
		return (string) apply_filters( 'phoenix_wp_price_labels_unit_price', $text, $product );
	}
}
