"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ora_1 = __importDefault(require("ora"));
const qrcode_terminal_1 = __importDefault(require("@bdeefe/qrcode-terminal"));
const core_1 = require("../../core");
const open_1 = __importDefault(require("open"));
class Preview extends core_1.PreviewModule {
    displayQRCode(url) {
        const smallSize = process.platform !== 'win32';
        qrcode_terminal_1.default.generate(url, { small: smallSize });
        const page = this.genQcodePage(url);
        this.execute(core_1.ModuleName.ui, core_1.UICmdEnum.showInfo, {
            content: `For Windows user, you can click the link below to scan the QR code in your browser`,
        });
        this.execute(core_1.ModuleName.ui, core_1.UICmdEnum.showInfo, {
            content: `Preview Link: file://${page}`,
        });
        return Promise.resolve();
    }
    onProgress(data) {
        if (!this.spinner) {
            this.spinner = (0, ora_1.default)('Processing').start();
        }
        this.spinner.text = data.step;
        if (data.done) {
            data.status === 'fail'
                ? this.spinner.fail(data.step)
                : this.spinner.succeed(data.step);
            this.spinner = undefined;
        }
    }
    openExternal(url) {
        (0, open_1.default)(url);
    }
}
exports.default = Preview;
