<?php

namespace PixelioCartAbandonRecoveryMore\Admin\Services;


use PixelioCartAbandonRecoveryMore\Includes\Utils\Pixelio_Cart_Abandon_Recovery_More_Util;

class Pixelio_Cart_Abandon_Recovery_More_Head_Meta_Renderer_Service
{
	private $wordpress_wrapper;
	private $woocommerce_wrapper;

	public function __construct($wordpress_wrapper, $woocommerce_wrapper)
	{
		$this->wordpress_wrapper = $wordpress_wrapper;
		$this->woocommerce_wrapper = $woocommerce_wrapper;
	}

	public function render_head_meta(): string
	{
		$html = '';

		// UUID meta
		$html .= $this->wordpress_wrapper->pixelio_wp_kses(
			"<meta name='pixelio-uuid' content=''>",
			Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html
		);

		// Product ID meta
		if ($this->woocommerce_wrapper->pixelio_is_product()) {
			$post = $this->wordpress_wrapper->pixelio_get_current_post();
			if ($post && isset($post->ID)) {
				$product_id = $this->wordpress_wrapper->pixelio_sanitize_text_field(
					$this->wordpress_wrapper->pixelio_wp_unslash($post->ID)
				);

				$html .= $this->wordpress_wrapper->pixelio_wp_kses(
					"<meta name='pixelio-product-id' content='" . $this->wordpress_wrapper->pixelio_esc_attr($product_id) . "'>",
					Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html
				);
			}
		}

		return $html;
	}
}
