"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makePreview = void 0;
const path_1 = require("path");
const blocks_renderer_1 = require("@ewizardjs/blocks-renderer");
const WizError_1 = require("../../modules/WizError");
const utils_1 = require("./utils");
const Logger_1 = require("./../../modules/Logger");
const I18n_1 = require("./../../modules/I18n");
const requirePuppeteer_1 = require("../../bin/utils/requirePuppeteer");
const PREVIEW_ICON_NAME = 'preview.jpg';
function makePreview(opts, presentationPath) {
    return __awaiter(this, void 0, void 0, function* () {
        const { id, all, theme, clm, rendererOptions } = opts;
        if (id || all || theme || clm)
            throw new WizError_1.WizError('UNRESOLVED_ARGUMENTS');
        try {
            const { serverPort, server } = yield (0, utils_1.createServer)(presentationPath);
            const url = `http://localhost:${serverPort}`;
            const puppeteer = blocks_renderer_1.FacadePuppeteer.create();
            Logger_1.default.info(I18n_1.default.info('SCREENSHOTER_LOADING'));
            yield puppeteer.createPage(url, requirePuppeteer_1.requirePuppeteer, { waitUntil: 'networkidle0' }, rendererOptions);
            Logger_1.default.info(I18n_1.default.info('SCREENSHOTER_LOADED'));
            yield puppeteer.screenshot({ path: (0, path_1.join)(presentationPath, PREVIEW_ICON_NAME), fullPage: true });
            Logger_1.default.info(I18n_1.default.info('SCREEN_PREVIEW_GENERATING'));
            yield (0, utils_1.destroyBrowserAndServer)(puppeteer, server);
            Logger_1.default.info(I18n_1.default.info('SCREEN_PREVIEW_READY'));
        }
        catch (err) {
            Logger_1.default.error(err.message);
        }
    });
}
exports.makePreview = makePreview;
//# sourceMappingURL=optionPreviewMakeScreen.js.map