"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceForIndexPage = exports.Resource = void 0;
class Resource {
    constructor(uri, basePath, buildId) {
        this.uri = uri;
        this.basePath = basePath;
        this.buildId = buildId;
        this.routes = {};
    }
    isData() {
        return !!this.uri.match(/\/_next\/data/);
    }
    getPagePath() {
        return this.routes.page;
    }
    getHtmlKey() {
        return `${(this.basePath || "").replace(/^\//, "")}${!this.basePath ? "" : "/"}static-pages/${this.buildId}${this.getCanonicalUri()}.html`;
    }
    getHtmlUri() {
        return `${this.basePath || ""}${this.getCanonicalUri()}`;
    }
    getJsonKey() {
        return `${(this.basePath || "").replace(/^\//, "")}${!this.basePath ? "" : "/"}_next/data/${this.buildId}${this.getCanonicalUri()}.json`;
    }
    getJsonUri() {
        return `/${this.getJsonKey()}`;
    }
    getNormalUri() {
        let normalizedUri = this.uri;
        if (this.basePath && this.uri.startsWith(this.basePath)) {
            normalizedUri = normalizedUri.slice(this.basePath.length);
        }
        if (normalizedUri.endsWith("/")) {
            normalizedUri = normalizedUri.slice(0, -1);
        }
        return ["/index", ""].includes(normalizedUri)
            ? "/"
            : decodeURI(normalizedUri);
        return normalizedUri === "" ? "/" : decodeURI(normalizedUri);
    }
    getCanonicalUri() {
        return this.getNormalUri()
            .replace(`${this.basePath}`, "")
            .replace(`_next/data/${this.buildId}/`, "")
            .replace(".json", "")
            .replace(".html", "");
    }
    getUri() {
        return this.uri;
    }
    getBasePath() {
        return this.basePath;
    }
    getBuildId() {
        return this.buildId;
    }
}
exports.Resource = Resource;
class ResourceForIndexPage extends Resource {
    getPagePath() {
        return "pages/index.js";
    }
    getCanonicalUri() {
        return "/index";
    }
    getHtmlUri() {
        return this.getBasePath() || "";
    }
}
exports.ResourceForIndexPage = ResourceForIndexPage;
