"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compositionsCommand = exports.COMPOSITIONS_COMMAND = void 0;
const cli_1 = require("@remotion/cli");
const lambda_client_1 = require("@remotion/lambda-client");
const constants_1 = require("@remotion/lambda-client/constants");
const client_1 = require("@remotion/renderer/client");
const args_1 = require("../../args");
const get_aws_region_1 = require("../../get-aws-region");
const find_function_name_1 = require("../../helpers/find-function-name");
const quit_1 = require("../../helpers/quit");
const log_1 = require("../../log");
exports.COMPOSITIONS_COMMAND = 'compositions';
const { enableMultiprocessOnLinuxOption, glOption, delayRenderTimeoutInMillisecondsOption, headlessOption, darkModeOption, } = client_1.BrowserSafeApis.options;
const compositionsCommand = async ({ args, logLevel, providerSpecifics, }) => {
    const serveUrl = args[0];
    if (!serveUrl) {
        log_1.Log.error({ indent: false, logLevel }, 'No serve URL passed.');
        log_1.Log.info({ indent: false, logLevel }, 'Pass an additional argument specifying a URL where your Remotion project is hosted.');
        log_1.Log.info({ indent: false, logLevel });
        log_1.Log.info({ indent: false, logLevel }, `${constants_1.BINARY_NAME} ${exports.COMPOSITIONS_COMMAND} <serve-url>`);
        (0, quit_1.quit)(1);
    }
    const { envVariables, inputProps, ignoreCertificateErrors, userAgent, disableWebSecurity, } = cli_1.CliInternals.getCliOptions({
        isStill: false,
        logLevel,
        indent: false,
    });
    const enableMultiProcessOnLinux = enableMultiprocessOnLinuxOption.getValue({
        commandLine: cli_1.CliInternals.parsedCli,
    }).value;
    const gl = glOption.getValue({ commandLine: cli_1.CliInternals.parsedCli }).value;
    const puppeteerTimeout = delayRenderTimeoutInMillisecondsOption.getValue({
        commandLine: cli_1.CliInternals.parsedCli,
    }).value;
    const headless = headlessOption.getValue({
        commandLine: cli_1.CliInternals.parsedCli,
    }).value;
    const darkMode = darkModeOption.getValue({
        commandLine: cli_1.CliInternals.parsedCli,
    }).value;
    const chromiumOptions = {
        disableWebSecurity,
        enableMultiProcessOnLinux,
        gl,
        headless,
        ignoreCertificateErrors,
        userAgent,
        darkMode,
    };
    const region = (0, get_aws_region_1.getAwsRegion)();
    lambda_client_1.LambdaClientInternals.validateServeUrl(serveUrl);
    const functionName = await (0, find_function_name_1.findFunctionName)({ logLevel, providerSpecifics });
    const comps = await (0, lambda_client_1.getCompositionsOnLambda)({
        functionName,
        serveUrl,
        inputProps,
        region,
        chromiumOptions,
        envVariables,
        logLevel,
        timeoutInMilliseconds: puppeteerTimeout,
        forceBucketName: args_1.parsedLambdaCli['force-bucket-name'],
        requestHandler: null,
    });
    cli_1.CliInternals.printCompositions(comps, logLevel);
};
exports.compositionsCommand = compositionsCommand;
