"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createShareableUrl = void 0;
const constants_1 = require("./constants");
const fetch_1 = require("./fetch");
async function createShareableUrl(results, config) {
    const sharedResults = {
        data: {
            version: 2,
            // TODO(ian): Take date from results, if applicable.
            createdAt: new Date().toISOString(),
            results,
            config,
        },
    };
    const apiBaseUrl = typeof config.sharing === 'object' ? config.sharing.apiBaseUrl : constants_1.REMOTE_API_BASE_URL;
    const response = await (0, fetch_1.fetchWithProxy)(`${apiBaseUrl}/api/eval`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(sharedResults),
    });
    const responseJson = (await response.json());
    if (responseJson.error) {
        throw new Error(`Failed to create shareable URL: ${responseJson.error}`);
    }
    const appBaseUrl = typeof config.sharing === 'object' ? config.sharing.appBaseUrl : constants_1.REMOTE_APP_BASE_URL;
    return `${appBaseUrl}/eval/${responseJson.id}`;
}
exports.createShareableUrl = createShareableUrl;
//# sourceMappingURL=share.js.map