"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * components: information.tsx
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
const react_1 = tslib_1.__importDefault(require("react"));
const ink_1 = require("ink");
const settings_1 = tslib_1.__importDefault(require("../../classes/settings"));
const pacman_1 = tslib_1.__importDefault(require("../../classes/pacman"));
const utils_1 = tslib_1.__importDefault(require("../../classes/utils"));
const title_1 = tslib_1.__importDefault(require("./title"));
/**
 *
 */
async function information(verbose = false) {
    const echo = utils_1.default.setEcho(verbose);
    console.clear();
    const settings = new settings_1.default();
    settings.load();
    const Wait = () => (react_1.default.createElement(ink_1.Box, { marginRight: 2 },
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null, " E G G S: the reproductive system of penguins"))));
    (0, ink_1.render)(react_1.default.createElement(Wait, null));
    /**
     * nest
     */
    const Nest = () => (react_1.default.createElement(ink_1.Box, { borderStyle: "round", marginRight: 2 },
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "nest: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, settings.config.snapshot_dir))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "name: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" },
                    settings.config.snapshot_prefix,
                    settings.config.snapshot_basename))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "ovarium: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, settings.config.snapshot_dir)))));
    // render(<Nest />)
    /**
     * Boot
     * @returns
     */
    const Boot = () => (react_1.default.createElement(ink_1.Box, { borderStyle: "round", marginRight: 2 },
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "kernel: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, settings.kernel_image))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "initrd.img: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, settings.initrd_image)))));
    // render(<Boot />)
    /**
     * Live
     */
    const Live = () => (react_1.default.createElement(ink_1.Box, { borderStyle: "round", marginRight: 2 },
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "live user/passwd: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" },
                    settings.config.user_opt,
                    "/",
                    settings.config.user_opt_passwd))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "root passwd: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, settings.config.root_passwd)))));
    // render(<Live />)
    const distroId = shelljs_1.default.exec('lsb_release -is', { silent: true }).stdout.trim();
    const releaseId = shelljs_1.default.exec('lsb_release -rs', { silent: true }).stdout.trim();
    const codenameId = shelljs_1.default.exec('lsb_release -cs', { silent: true }).stdout.trim();
    const Distro = () => (react_1.default.createElement(ink_1.Box, { flexDirection: 'column' },
        react_1.default.createElement(ink_1.Box, { borderStyle: "round", marginRight: 2, flexDirection: 'row' },
            react_1.default.createElement(ink_1.Box, { marginRight: 2 },
                react_1.default.createElement(ink_1.Text, null,
                    "distro: ",
                    react_1.default.createElement(ink_1.Text, { color: "cyan" },
                        distroId,
                        " ",
                        releaseId,
                        " ",
                        codenameId))),
            react_1.default.createElement(ink_1.Box, { marginRight: 2 },
                react_1.default.createElement(ink_1.Text, null,
                    "compatible: ",
                    react_1.default.createElement(ink_1.Text, { color: "cyan" },
                        settings.distro.distroLike,
                        " ",
                        settings.distro.codenameLikeId))))));
    // render(<Distro />)
    const dependencies = await pacman_1.default.prerequisitesCheck();
    const configurations = pacman_1.default.configurationCheck();
    let uefi = pacman_1.default.isUefi();
    let installer = false;
    if (pacman_1.default.isInstalledGui()) {
        installer = pacman_1.default.calamaresExists();
    }
    const Ok = () => (react_1.default.createElement(ink_1.Text, { backgroundColor: "green" }, "OK"));
    // render(<Ok />)
    const Ko = () => (react_1.default.createElement(ink_1.Text, { backgroundColor: "red", color: "white" }, "KO"));
    // render(<Ko />)
    /**
     * CLI va verde se naked, altrimenti giallo
     */
    const CLI = () => (react_1.default.createElement(ink_1.Text, { backgroundColor: "green" }, "CLI"));
    // render(<CLI />)
    const GUI = () => (react_1.default.createElement(ink_1.Text, { backgroundColor: "green" }, "GUI"));
    // render(<GUI />)
    let initType = '';
    if (utils_1.default.isSysvinit()) {
        initType = 'sysvinit';
    }
    if (utils_1.default.isSystemd()) {
        if (initType === 'sysvinit') {
            initType += '/';
        }
        initType = 'systemd';
    }
    const sysvinit = utils_1.default.isSysvinit();
    const systemd = utils_1.default.isSystemd();
    const Checks = () => (react_1.default.createElement(ink_1.Box, { borderStyle: "round", marginRight: 2, flexDirection: "row" },
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "dependencies: ",
                dependencies ? react_1.default.createElement(Ok, null) : react_1.default.createElement(Ko, null))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "configurations: ",
                configurations ? react_1.default.createElement(Ok, null) : react_1.default.createElement(Ko, null))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "installer: ",
                installer ? react_1.default.createElement(GUI, null) : react_1.default.createElement(CLI, null))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "uefi: ",
                uefi ? react_1.default.createElement(Ok, null) : react_1.default.createElement(Ko, null))),
        react_1.default.createElement(ink_1.Box, { marginRight: 2 },
            react_1.default.createElement(ink_1.Text, null,
                "init: ",
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, initType)))));
    // render(<Checks />)
    const Presentation = () => (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(ink_1.Box, null,
            react_1.default.createElement(ink_1.Text, null, " ")),
        react_1.default.createElement(ink_1.Box, { borderStyle: "round", marginRight: 2, flexDirection: "column" },
            react_1.default.createElement(ink_1.Box, null,
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, "eggs install"),
                react_1.default.createElement(ink_1.Text, null, " install your CLI iso with TUI installer krill, on GUI prefere calamares")),
            react_1.default.createElement(ink_1.Box, null,
                react_1.default.createElement(ink_1.Text, { color: "cyan" }, "eggs wardrobe"),
                react_1.default.createElement(ink_1.Text, null, " build your personal system starting from cli")),
            react_1.default.createElement(ink_1.Box, null,
                react_1.default.createElement(ink_1.Text, null, " ")),
            react_1.default.createElement(ink_1.Box, { flexDirection: "row" },
                react_1.default.createElement(ink_1.Box, { marginRight: 1 },
                    react_1.default.createElement(ink_1.Text, null, "Info: ")),
                react_1.default.createElement(ink_1.Box, { flexDirection: "column" },
                    react_1.default.createElement(ink_1.Box, { marginRight: 2 },
                        react_1.default.createElement(ink_1.Text, null, "blog    "),
                        react_1.default.createElement(ink_1.Text, { color: "cyan" }, "https://penguins-eggs.net")),
                    react_1.default.createElement(ink_1.Box, { marginRight: 2 },
                        react_1.default.createElement(ink_1.Text, null, "sources "),
                        react_1.default.createElement(ink_1.Text, { color: "cyan" }, "https://github.com/pieroproietti/penguins-eggs")),
                    react_1.default.createElement(ink_1.Box, { marginRight: 2 },
                        react_1.default.createElement(ink_1.Text, null, "wardrobe "),
                        react_1.default.createElement(ink_1.Text, { color: "cyan" }, "https://github.com/pieroproietti/penguins-wardrobe")))))));
    // render(<Presentation />)
    /**
     *
     */
    const Main = () => (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(title_1.default, null),
        react_1.default.createElement(ink_1.Box, null,
            react_1.default.createElement(Live, null),
            react_1.default.createElement(Nest, null),
            react_1.default.createElement(Boot, null)),
        react_1.default.createElement(ink_1.Box, null,
            react_1.default.createElement(Distro, null),
            react_1.default.createElement(Checks, null)),
        react_1.default.createElement(Presentation, null)));
    (0, ink_1.render)(react_1.default.createElement(Main, null));
}
exports.default = information;
