/**
 * This is shared between <devvit-surface> <devvit-custom-post> to map the
 * webview assets from their S3 key location to the fully qualified devvit.net
 * URL for use in an iframe.
 *
 * @param template provided by the client; should have {{location}}, {{app}}, and {{path}} fields
 * @param subreddit the subreddit thing ID where the app is installed
 * @param _version the app version currently running
 * @param url the URL from the webview block configuration
 */
export function resolveWebviewUrl(template, subreddit, _version, url) {
    // input: 9b9cfb2e-d7d4-4b35-b6bc-cb8af11ee5e9/path.html
    const segments = url.match(/([a-zA-Z0-9-]+)\/(.*)/) ?? [];
    if (segments.length < 3) {
        return '';
    }
    const [_, app, path] = segments;
    if (!subreddit || !app || !path) {
        return '';
    }
    const subredditId = subreddit.replace(/^t[0-9]_/, '');
    // output: parsed template
    const parsedTemplate = template
        .replace('{{location}}', subredditId)
        .replace('{{app}}', app)
        .replace('{{path}}', path);
    const newUrl = new URL(parsedTemplate);
    // newUrl.search += `v=${version}`;
    return newUrl.toString();
}
//# sourceMappingURL=webview.js.map