"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 });
const commander = require("commander");
const ensureAuth_1 = require("./utils/ensureAuth");
const Logger_1 = require("../modules/Logger");
const listr2_1 = require("listr2");
const I18n_1 = require("../modules/I18n");
const thumbnails_1 = require("../Api/thumbnails");
const utils_1 = require("./../utils");
const configureHelpOptions_1 = require("../utils/configureHelpOptions");
const chalk_1 = require("chalk");
const settings_1 = require("@ewizardjs/settings");
commander
    .name('wiz thumbs')
    .description('Generate thumbnails for e-Detailer slides. To verify thumbnails are up-to-date, run "wiz dev" before "wiz thumbs". Re-run these commands every time you change your project')
    .option('-s, --slides <slides>', 'generate thumbnails for given slides')
    .option('-d, --delay <delay>', 'delay before screenshot in ms')
    .configureHelp({
    optionDescription: configureHelpOptions_1.capitalizeOptionDescription,
})
    .parse(process.argv);
thumbnails(commander.opts(), process.cwd())
    .catch(err => Logger_1.default.error(err.message));
function thumbnails(opts, presentationPath) {
    return __awaiter(this, void 0, void 0, function* () {
        yield ensureAuth_1.default();
        if (yield utils_1.ensureDevBuild(presentationPath)) {
            Logger_1.default.info(chalk_1.default.yellow(I18n_1.default.info('THUMBNAILS_REMINDER')));
        }
        const options = {
            root: presentationPath,
            settings: yield settings_1.getRaw(presentationPath),
            disableLogs: true,
        };
        if (opts.slides)
            options.requiredSlides = opts.slides.split(/\s/);
        if (opts.delay)
            options.delay = parseInt(opts.delay, 10);
        const { SlidesWalker, getThumbScreener, } = yield thumbnails_1.getScreenshoter(presentationPath);
        const task = new listr2_1.Listr([
            {
                title: I18n_1.default.info('THUMBNAILS_GENERATING'),
                task: () => __awaiter(this, void 0, void 0, function* () {
                    const slidesWalker = new SlidesWalker(options);
                    const thumbScreener = yield getThumbScreener({
                        root: presentationPath,
                        disableLogs: true,
                    });
                    return yield slidesWalker.walk([thumbScreener]);
                }),
            },
        ]);
        task
            .run()
            .then(() => Logger_1.default.info(I18n_1.default.info('THUMBNAILS_READY')))
            .catch((err) => Logger_1.default.error(I18n_1.default.error('THUMBNAILS_CREATION_FAILED')));
    });
}
//# sourceMappingURL=wiz-thumbs.js.map