<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Loader\Assets;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Config\MenuConfig;
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 WooAssetsLoaderAction, loads woocommerce assets.
 */
class WooAssetsLoaderAction implements Hookable, Conditional
{
    const INTEGRATION_SCREEN_IDS = ['dropshipping-export_page_dropshipping_export_type', 'dropshipping-export_page_dropshipping_export_settings'];
    /**
     * @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
    {
        $action = $this->request->get_param('get.action')->getAsString();
        $action = empty($action) ? 'index' : $action;
        return $this->plugin_helper->is_plugin_page($this->request->get_param('get.page')->getAsString(), $action);
    }
    public function hooks()
    {
        add_filter('woocommerce_screen_ids', [$this, 'update_woo_screen_ids'], 10, 1);
        add_action('admin_enqueue_scripts', [$this, 'load_woocommerce_scripts'], 90);
        add_filter('woocommerce_display_admin_footer_text', function () {
            return \false;
        });
    }
    public function update_woo_screen_ids($screen_ids)
    {
        return array_merge($screen_ids, self::INTEGRATION_SCREEN_IDS);
    }
    public function load_woocommerce_scripts()
    {
        $version = $this->config->get_param('plugin.version')->get();
        wp_enqueue_media();
        wp_register_style('jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', [], $version);
        wp_enqueue_script('jquery-ui-accordion');
    }
}
