"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    getMetadataRouteSuffix: function() {
        return getMetadataRouteSuffix;
    },
    normalizeMetadataRoute: function() {
        return normalizeMetadataRoute;
    }
});
const _ismetadataroute = require("./is-metadata-route");
const _path = /*#__PURE__*/ _interop_require_default(require("../../shared/lib/isomorphic/path"));
const _hash = require("../../shared/lib/hash");
const _utils = require("../../shared/lib/router/utils");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function getMetadataRouteSuffix(page) {
    let suffix = "";
    if (page.includes("(") && page.includes(")") || page.includes("@")) {
        suffix = (0, _hash.djb2Hash)(page).toString(36).slice(0, 6);
    }
    return suffix;
}
function normalizeMetadataRoute(page) {
    let route = page;
    let suffix = "";
    if ((0, _ismetadataroute.isMetadataRoute)(page)) {
        if (route === "/robots") {
            route += ".txt";
        } else if (route === "/manifest") {
            route += ".webmanifest";
        } else if (route.endsWith("/sitemap")) {
            route += ".xml";
        } else {
            // Remove the file extension, e.g. /route-path/robots.txt -> /route-path
            const pathnamePrefix = page.slice(0, -(_path.default.basename(page).length + 1));
            suffix = getMetadataRouteSuffix(pathnamePrefix);
        }
        // Support both /<metadata-route.ext> and custom routes /<metadata-route>/route.ts.
        // If it's a metadata file route, we need to append /[id]/route to the page.
        if (!route.endsWith("/route")) {
            const isStaticMetadataFile = (0, _ismetadataroute.isMetadataRouteFile)(route, [], true);
            const { dir , name: baseName , ext  } = _path.default.parse(route);
            // If it's dynamic routes, we need to append [[...__metadata_id__]] to the page;
            // If it's static routes, we need to append nothing to the page.
            // If its special routes like robots.txt and manifest.webmanifest, we leave them as static routes.
            const isStaticRoute = !(0, _utils.isDynamicRoute)(route) && (page.startsWith("/robots") || page.startsWith("/manifest") || isStaticMetadataFile);
            route = _path.default.posix.join(dir, `${baseName}${suffix ? `-${suffix}` : ""}${ext}`, isStaticRoute ? "" : "[[...__metadata_id__]]", "route");
        }
    }
    return route;
}

//# sourceMappingURL=get-metadata-route.js.map