<?php

namespace WPDesk\DropshippingExportFree\Action\Loader\Assets;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Helper\PluginHelper;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Listener\Items\Conditional\Conditional;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Listener\Items\Hookable\Hookable;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Config\Config;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Request\Request;

class PluginAssetsLoaderAction implements Hookable, Conditional {

	/**
	 * @var Config
	 */
	private $config;

	/**
	 * @var Request
	 */
	private $request;

	/**
	 * @var PluginHelper
	 */
	private $plugin_helper;
	public function __construct( Config $config, Request $request, PluginHelper $helper ) {
		$this->config        = $config;
		$this->request       = $request;
		$this->plugin_helper = $helper;
	}
	public function isActive(): bool {
		return $this->plugin_helper->is_plugin_page( $this->request->get_param( 'get.page' )->getAsString(), $this->request->get_param( 'get.action' )->getAsString() );
	}
	public function hooks() {
		\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ], 90 );
	}
	public function enqueue_scripts() {
		$suffix  = \true === $this->config->get_param( 'plugin.development' )->get() ? '' : '.min';
		$version = $this->config->get_param( 'plugin.version' )->get();
		\wp_register_style( 'dropshipping_export_free_admin', $this->config->get_param( 'assets.css.dir_url' )->get() . 'admin' . $suffix . '.css', [], $version );
		\wp_enqueue_style( 'dropshipping_export_free_admin' );
	}
}
