// #region Imports
import { PathLocationStrategy } from './Strategies/PathLocationStrategy';
// #endregion
/**
 * Provides an abstraction over `window.location` that automatically adapts
 * to the currently active routing strategy (hash vs. path-based routing).
 *
 * This class delegates all URL access and manipulation to the underlying
 * `ILocationStrategy`, keeping it free of `if (useHash)` branching.
 *
 * @example
 * const strategy = new HashLocationStrategy();
 * const location = new RouterLocation(strategy);
 * const path = location.pathname;
 * const query = location.search;
 *
 * @public
 */
export class RouterLocation {
    // #region Fields
    /**
     * The location strategy that handles URL reading and manipulation.
     */
    _strategy;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `RouterLocation` class.
     *
     * @param strategy - The location strategy to delegate to.
     */
    constructor(strategy) {
        this._strategy = strategy;
    }
    // #endregion
    // #region Properties
    /**
     * Gets the current full document location URL.
     */
    get href() {
        return this._strategy.href;
    }
    /**
     * Gets the normalized pathname of the application route.
     */
    get pathname() {
        return this._strategy.pathname;
    }
    /**
     * Gets the normalized search string (query parameters) for the current route.
     */
    get search() {
        return this._strategy.search;
    }
    /**
     * Gets the app-level route, which combines `pathname` and `search`.
     */
    get route() {
        return this.pathname + this.search;
    }
    /**
     * Gets the application-level fragment/hash.
     */
    get hash() {
        return this._strategy.hash;
    }
    /**
     * Gets the hostname (e.g. "localhost").
     */
    get hostname() {
        return this._strategy.hostname;
    }
    /**
     * Gets the full origin (e.g. "http://localhost:8080").
     */
    get origin() {
        return this._strategy.origin;
    }
    /**
     * Gets the host (hostname + port).
     */
    get host() {
        return this._strategy.host;
    }
    /**
     * Gets the port number (e.g. "8080").
     */
    get port() {
        return this._strategy.port;
    }
    /**
     * Gets the protocol used (e.g. "http:").
     */
    get protocol() {
        return this._strategy.protocol;
    }
    // #endregion
    // #region Methods
    /**
     * Navigates programmatically to a new route.
     *
     * @param path - The route path to navigate to.
     */
    navigate(path) {
        this._strategy.pushState(path);
    }
    /**
     * Returns the value of a query parameter from the current route URL.
     *
     * @param name - The parameter name.
     * @returns The parameter value, or `null` if not present.
     */
    getSearchParam(name) {
        return this._strategy.getSearchParam(name);
    }
    /**
     * Sets a query parameter on the current route URL without triggering navigation.
     *
     * @param name  - The parameter name.
     * @param value - The parameter value.
     */
    setSearchParam(name, value) {
        this._strategy.setSearchParam(name, value);
    }
    /**
     * Removes a query parameter from the current route URL without triggering navigation.
     *
     * @param name - The parameter name to remove.
     */
    deleteSearchParam(name) {
        this._strategy.deleteSearchParam(name);
    }
}
/**
 * Service locator for accessing the current `RouterLocation` instance globally.
 * Intended for use in scenarios where dependency injection is not available.
 *
 * @example
 * const currentPath = RouterLocationServiceLocator.current.pathname;
 *
 * @public
 */
export class RouterLocationServiceLocator {
    /**
     * Internal storage for the registered location instance.
     */
    static _current = null;
    /**
     * Gets the globally registered `RouterLocation` instance.
     * Throws an error if not set.
     */
    static get current() {
        if (!RouterLocationServiceLocator.isSet()) {
            throw new Error('\'RouterLocation\' not set.');
        }
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        return RouterLocationServiceLocator._current;
    }
    /**
     * Returns whether a `RouterLocation` instance is registered.
     */
    static isSet() {
        return RouterLocationServiceLocator._current !== null;
    }
    /**
     * Registers the current `RouterLocation` instance.
     *
     * @param current - The location instance to register globally.
     */
    static set(current) {
        RouterLocationServiceLocator._current = current;
    }
}
/**
 * @public
 */
RouterLocationServiceLocator.set(new RouterLocation(new PathLocationStrategy()));
//# sourceMappingURL=RouterLocation.js.map