<?php

/**
 * Class ShipmentFunctionality
 *
 * @package WPDesk\FS\Shipment
 */
namespace DhlPolskaVendor\WPDesk\FS\Shipment;

use DhlPolskaVendor\Psr\Log\LoggerInterface;
use DhlPolskaVendor\WPDesk\FS\Shipment\Label\SingleLabelFileDispatcher;
use DhlPolskaVendor\WPDesk\FS\Shipment\Manifest\ManifestCustomPostType;
use DhlPolskaVendor\WPDesk\FS\Shipment\Metabox\Ajax;
use DhlPolskaVendor\WPDesk\FS\Shipment\Order\AddShippingMetabox;
use DhlPolskaVendor\WPDesk\FS\Shipment\RestApi\OrderResponseDataAppender;
use DhlPolskaVendor\WPDesk\FS\Shipment\Subscriptions\SubscriptionsIntegration;
use DhlPolskaVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
 * Can load shipment functionality.
 */
class Assets implements Hookable
{
    const HANDLE = 'fs_shipment_admin';
    /**
     * @var string
     */
    private $assets_url;
    /**
     * @var string
     */
    private $scripts_version;
    /**
     * Assets constructor.
     *
     * @param string $assets_url .
     * @param string $scripts_version .
     */
    public function __construct($assets_url, $scripts_version)
    {
        $this->assets_url = $assets_url;
        $this->scripts_version = $scripts_version;
    }
    /**
     * Hooks.
     */
    public function hooks()
    {
        add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']);
    }
    /**
     * Admin enqueue scripts.
     */
    public function admin_enqueue_scripts()
    {
        if ($this->should_enqueue_admin_scripts()) {
            wp_register_script(self::HANDLE, trailingslashit($this->assets_url) . 'js/admin.js', array('jquery'), $this->scripts_version);
            wp_localize_script(self::HANDLE, self::HANDLE, array('ajax_url' => admin_url('admin-ajax.php')));
            wp_enqueue_script(self::HANDLE);
            wp_enqueue_style(self::HANDLE, trailingslashit($this->assets_url) . 'css/admin.css', array(), $this->scripts_version);
        }
    }
    /**
     * Should enqueue admin scripts?
     */
    private function should_enqueue_admin_scripts()
    {
        $current_screen = get_current_screen();
        $wc_screen_id = sanitize_title(__('WooCommerce', 'woocommerce'));
        if (!$current_screen) {
            return \false;
        }
        if ('woocommerce_page_wc-orders' === $current_screen->id || in_array($current_screen->post_type, array('shop_order', 'shop_subscription'), \true) || $wc_screen_id . '_page_wc-settings' === $current_screen->id) {
            return \true;
        }
        return \false;
    }
}
