<?php

namespace HulkPlugins\Woo\ProductDescriptionInLoop\Frontend\Services;

use HulkPlugins\Woo\ProductDescriptionInLoop\Core\SingletonTrait;
use const HulkPlugins\Woo\ProductDescriptionInLoop\VERSION;

defined( 'ABSPATH' ) || exit;

class ArchivePagesService {
	use SingletonTrait;

	protected function isMainNotInLoop(): bool {
		return is_main_query() && ! in_the_loop();
	}

	public function isShopPage(): bool {
		return (is_shop() || is_product()) && $this->isMainNotInLoop();
	}

	public function isCategoryPages(): bool {
		return is_product_category() && $this->isMainNotInLoop();
	}

	public function isTagPages(): bool {
		return is_product_tag() && $this->isMainNotInLoop();
	}

	public function isAllArchivePages(): bool {
		return $this->isShopPage() || $this->isCategoryPages() || $this->isTagPages();
	}

	/**
	 * Add inline style
	 */
	public function addInlineStyle( $data ): ?bool {
		static $cache = null;

		if ( $cache !== null ) {
			return $cache;
		}

		wp_register_style( 'hulk_woo_pdil_inline_style', false, [], VERSION );
		wp_enqueue_style( 'hulk_woo_pdil_inline_style' );
		$cache = wp_add_inline_style( 'hulk_woo_pdil_inline_style', esc_attr( $data ) );
		return $cache;
	}
}
