// #region Imports
// #endregion
/**
 * A location strategy for standard path-based routing.
 *
 * URLs follow the pattern `http://example.com/path?query#fragment`.
 * The application path lives in `window.location.pathname`.
 *
 * This strategy requires server-side support (e.g. a rewrite rule that redirects
 * all requests to `index.html`) so that deep links resolve correctly.
 *
 * @public
 */
export class PathLocationStrategy {
    // #region Properties
    /** @inheritdoc */
    get pathname() {
        return window.location.pathname || '/';
    }
    /** @inheritdoc */
    get href() {
        return window.location.href;
    }
    /** @inheritdoc */
    get search() {
        return window.location.search;
    }
    /** @inheritdoc */
    get hash() {
        const hash = window.location.hash;
        return hash.startsWith('#') ? hash.substring(1) : hash;
    }
    /** @inheritdoc */
    get hostname() {
        return window.location.hostname;
    }
    /** @inheritdoc */
    get origin() {
        return window.location.origin;
    }
    /** @inheritdoc */
    get host() {
        return window.location.host;
    }
    /** @inheritdoc */
    get port() {
        return window.location.port;
    }
    /** @inheritdoc */
    get protocol() {
        return window.location.protocol;
    }
    // #endregion
    // #region Methods
    /** @inheritdoc */
    pushState(path) {
        window.history.pushState({}, '', path);
    }
    /** @inheritdoc */
    replaceState(path) {
        window.history.replaceState({}, '', path);
    }
    /** @inheritdoc */
    prepareExternalUrl(pathname) {
        return pathname;
    }
    /** @inheritdoc */
    getSearchParam(name) {
        const params = new URLSearchParams(window.location.search);
        return params.get(name);
    }
    /** @inheritdoc */
    setSearchParam(name, value) {
        const params = new URLSearchParams(window.location.search);
        params.set(name, value);
        this.applySearchParams(params);
    }
    /** @inheritdoc */
    deleteSearchParam(name) {
        const params = new URLSearchParams(window.location.search);
        params.delete(name);
        this.applySearchParams(params);
    }
    /**
     * Applies the given search params by replacing the browser URL via `history.replaceState`.
     */
    applySearchParams(params) {
        const search = params.toString();
        const newUrl = search
            ? `${window.location.pathname}?${search}${window.location.hash}`
            : `${window.location.pathname}${window.location.hash}`;
        window.history.replaceState({}, '', newUrl);
    }
}
//# sourceMappingURL=PathLocationStrategy.js.map