import * as child from 'child_process';
import { UtilsVSCode__NS__vscodeImport } from '../utils-vscode';
export const getVscode = () => {
    return UtilsVSCode__NS__vscodeImport();
};
/**
 * @deprecated
 */
export function valueFromCommand({ command, cwd, bigBuffer, }) {
    const decode = true;
    // const shell = UtilsProcess__NS__getGitBashPath();
    let res = child
        .execSync(command, {
        cwd,
        // shell,
        encoding: 'utf8',
        maxBuffer: bigBuffer ? 50 * 1024 * 1024 : void 0,
    })
        .toString()
        .trim();
    const splited = (res || '').split('\n');
    res = splited.pop() || '';
    if (decode) {
        res = decodeURIComponent(res);
    }
    return res;
}
/**
 * @deprecated
 */
export function deepClone(obj, hash = new WeakMap()) {
    if (Object(obj) !== obj) {
        return obj;
    } // primitives
    if (hash.has(obj)) {
        return hash.get(obj);
    } // cyclic reference
    const result = obj instanceof Set
        ? new Set(obj) // See note about this!
        : obj instanceof Map
            ? new Map(Array.from(obj, ([key, val]) => [key, deepClone(val, hash)]))
            : obj instanceof Date
                ? new Date(obj)
                : obj instanceof RegExp
                    ? new RegExp(obj.source, obj.flags)
                    : // ... add here any specific treatment for other classes ...
                        // and finally a catch-all:
                        obj.constructor
                            ? new obj.constructor()
                            : Object.create(null);
    hash.set(obj, result);
    return Object.assign(result, ...Object.keys(obj).map(key => ({ [key]: deepClone(obj[key], hash) })));
}
/**
 * @deprecated
 */
export function capitalizeFirstLetter(str) {
    return str.charAt(0).toUpperCase() + str.slice(1);
}
/**
 * @deprecated
 */
export function escapeStringForRegEx(s) {
    return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
/**
 * @deprecated
 */
export function fixJSONString(s) {
    s = s.trim();
    if (s.endsWith(']')) {
        return s;
    }
    if (s.endsWith('}')) {
        return `${s}]`;
    }
    if (s.endsWith('"')) {
        return `${s}}]`;
    }
    return `${s}"}]`;
}
/**
 * @deprecated
 */
export function optionsFix(options) {
    //#region handle args
    if (!options) {
        options = {};
    }
    if (typeof options.findNearestProject === 'undefined') {
        options.findNearestProject = false;
    }
    if (typeof options.syncProcess === 'undefined') {
        options.syncProcess = false;
    }
    if (typeof options.reloadAfterSuccesFinish === 'undefined') {
        options.reloadAfterSuccesFinish = false;
    }
    if (typeof options.cancellable === 'undefined') {
        options.cancellable = true;
    }
    if (typeof options.tnpNonInteractive === 'undefined') {
        options.tnpNonInteractive = true;
    }
    if (typeof options.debug === 'undefined') {
        options.debug = false;
    }
    if (typeof options.askBeforeExecute === 'undefined') {
        options.askBeforeExecute = false;
    }
    if (typeof options.tnpShowProgress === 'undefined') {
        options.tnpShowProgress = true;
    }
    if (typeof options.showOutputDataOnSuccess === 'undefined') {
        options.showOutputDataOnSuccess = false;
    }
    if (typeof options.showSuccessMessage === 'undefined') {
        options.showSuccessMessage = true;
    }
    if (typeof options.progressLocation === 'undefined') {
        options.progressLocation = 'notification';
    }
    //#endregion
    return options;
}
/**
 * @deprecated
 */
export async function getModuleName(value = 'Filename') {
    const vscode = getVscode();
    const result = await vscode.window.showInputBox({
        value,
        placeHolder: value,
    });
    return !result ? '' : result;
}
/**
 * @deprecated
 */
// export class Log {
//   outputChannel: OutputChannel;
//   constructor(
//     private name: string,
//     private mode: LogMode = 'dialog',
//     private debugMode = false,
//   ) {
//     const vscode = getVscode();
//     if (!vscode.window) {
//       return;
//     }
//     this.outputChannel = vscode.window.createOutputChannel(name);
//     if (debugMode) {
//       this.outputChannel.show();
//     }
//   }
//   setDebugMode(debug:boolean) {
//     this.debugMode = debug;
//   }
//   public static instance(name: string, mode: LogMode, debugMode = false) {
//     return new Log(name, mode, debugMode);
//   }
//   public data(data: string) {
//     if (!this.debugMode) {
//       return;
//     }
//     const message = `[${this.name}] ${data}`;
//     if (this.mode === 'dialog') {
//       const vscode = getVscode();
//       vscode.window.showInformationMessage(message);
//     } else {
//       this.outputChannel.appendLine(message);
//     }
//   }
//   public info(data: string) {
//     const message = `[${this.name}] ${data}`;
//     if (this.mode === 'dialog') {
//       const vscode = getVscode();
//       vscode.window.showInformationMessage(message);
//     } else {
//       this.outputChannel.appendLine(message);
//     }
//   }
//   public error(data: string) {
//     const message = `[${this.name}] ${data}`;
//     if (this.mode === 'dialog') {
//       const vscode = getVscode();
//       vscode.window.showErrorMessage(message);
//     } else {
//       this.outputChannel.appendLine(`[error] ${message}`);
//     }
//   }
// }
//# sourceMappingURL=c:/Users/darek/projects/npm/taon-dev/tnp-helpers/dist-nocutsrc-prod/lib/old/helpers.js.map