#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const argv = require("yargs").argv;
exports.default = () => {
    /**
     * @param {string} lng  Get Language
     */
    const removeLanguage = (lng) => {
        const workingDir = path.resolve(process.cwd());
        try {
            fs.rm(`public/locales/${lng}`, { recursive: true }, (err) => {
                if (err) {
                    console.error(err);
                    return;
                }
            });
        }
        catch (error) {
            console.log("error", error);
        }
        /* settings.js */
        const settingsPath = path.resolve(workingDir, "src/settings.js");
        if (!fs.existsSync(settingsPath)) {
            return;
        }
        const settingsData = fs.readFileSync(settingsPath, {
            encoding: "utf8",
            flag: "r",
        });
        const data = `{ label: '${lng.toUpperCase()}', value: '${lng.toLowerCase()}', apiValue: '${lng.toLowerCase()}-${lng.toLowerCase()}' },`;
        let updatedData = settingsData.replace(data.toString(), "");
        updatedData = updatedData.replace(/^\s*$(?:\r\n?|\n)/gm, "");
        fs.writeFileSync(settingsPath, updatedData);
        /* next-i18next.config.js */
        const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
        if (!fs.existsSync(i18nPath)) {
            return;
        }
        const i18nData = fs.readFileSync(i18nPath, {
            encoding: "utf8",
            flag: "r",
        });
        fs.writeFileSync(i18nPath, i18nData.replace(`'${lng}',\u0020`, ""));
        console.log("\x1b[32m%s\x1b[0m", `\n✓ Remove language option ${lng.toUpperCase()}.\n`);
        console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
    };
    const init = () => {
        if (!argv.removeLanguage)
            return;
        let lng = argv.removeLanguage;
        try {
            removeLanguage(lng);
        }
        catch (err) {
            const typedError = err;
            console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
                ? typedError.message + "\n"
                : "Something went wrong.\n"}`);
        }
    };
    init();
};
