<?php

/**
 * Handles assets.
 *
 * @package northmill-online-shared
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Modules;

use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Helpers\General_Helpers;
use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Abstract_Shared_Base;
use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Helpers\Hook_Helpers;
use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Modules\Assets\Enquer;
defined('ABSPATH') || exit;
/**
 * Class Assets_Module
 */
class Assets_Module extends Abstract_Module
{
    /**
     * The URL to the assets' directory.
     * With trailing slash.
     *
     * @var string
     */
    private string $shared_assets_url;
    /**
     * The path to the assets' directory.
     * With trailing slash.
     *
     * @var string
     */
    private string $shared_assets_path;
    /**
     * The URL to the package's assets' directory.
     * With trailing slash.
     *
     * @var string
     */
    private string $package_assets_url;
    /**
     * The URL to the package's assets' directory.
     * With trailing slash.
     *
     * @var string
     */
    private string $package_assets_path;
    /**
     * The enquer instance.
     *
     * @var Enquer
     */
    public Enquer $enquer;
    /**
     * __construct method.
     *
     * @param Abstract_Shared_Base $shared The shared object to be passed as an argument to the parent constructor.
     *
     * @return void
     */
    public function __construct(Abstract_Shared_Base $shared)
    {
        parent::__construct($shared);
        $this->enquer = new Enquer($shared);
    }
    /**
     * Module setup.
     *
     * @return void
     */
    public function setup(): void
    {
        $this->shared_assets_url = $this->shared->package_info->paths->get_shared_url() . 'assets/';
        $this->shared_assets_path = $this->shared->package_info->paths->get_shared_path() . 'assets/';
        $package_assets_path = Hook_Helpers::apply_scoped_filters('northmill_online_shared_assets_dir', 'assets');
        $this->package_assets_url = General_Helpers::ensure_trailing_slash($this->shared->package_info->paths->get_url() . $package_assets_path);
        $this->package_assets_path = General_Helpers::ensure_trailing_slash($this->shared->package_info->paths->get_path() . $package_assets_path);
    }
    /**
     * Returns the URL of an image file.
     *
     * @param string $filename The name of the image file.
     *
     * @return string The URL of the image file.
     */
    public function get_shared_img_url(string $filename): string
    {
        return $this->shared_assets_url . 'img/' . $filename;
    }
    /**
     * Returns the URL of the package assets with trailing slash.
     *
     * @return string The URL of the package assets.
     */
    public function get_package_assets_url(): string
    {
        return $this->package_assets_url;
    }
    /**
     * Retrieves the path to the assets directory of the package.
     * With trailing slash.
     *
     * @return string The path to the assets directory of the package.
     */
    public function get_package_assets_path(): string
    {
        return $this->package_assets_path;
    }
    /**
     * Retrieves the URL of the shared assets directory.
     * With trailing slash.
     *
     * @return string The URL of the shared assets directory.
     */
    public function get_shared_assets_url(): string
    {
        return $this->shared_assets_url;
    }
    /**
     * Retrieves the path to the shared assets directory.
     * With trailing slash.
     *
     * @return string The path to the shared assets directory.
     */
    public function get_shared_assets_path(): string
    {
        return $this->shared_assets_path;
    }
}
