// Default/Classic Synchronet Command Shell turned VBBS Command Shell from Cru Jones @ Virtual Cove
// goes in /sbbs/mods

// @format.tab-size 4

"use strict";

require("sbbsdefs.js", "K_UPPER");
require("userdefs.js", "UFLAG_T");
require("nodedefs.js", "NODE_MAIN");
require("key_defs.js", "KEY_UP");
require("gettext.js", "gettext");
load("termsetup.js");
var shell = load({}, "shell_lib.js");

system.settings &= ~SYS_RA_EMU; // Use (R)e-read and (A)uto-reply keys

shell.help_key = '?';
// If user has unlimited time, display time-used rather than time-remaining
const time_code = user.security.exemptions & UFLAG_T ? "@TUSED@" : "@TLEFT@";
const time_prefix = user.security.exemptions & UFLAG_T ? gettext("Used") : gettext("Left");
var vbbsMenuPath = "vbbsmenu/";

shell.main_menu = {
	file: vbbsMenuPath+"main",
	cls: true,
	eval: 'bbs.main_cmds++',
	node_action: NODE_MAIN,
	prompt: gettext("\x01-\x01c", "shell_prompt_begin")
		+ gettext("\x01h\x01yTopic:\x01n")
		+ gettext(" @GRP@\r\n\x01h\x01y[\x01n@SN@\x01h\x01y] \x01n@SUB@\x01n\x01r\x01h\x01y\r\nTime "+time_prefix+" = "+ time_code + "\x01n: ", "shell_main_prompt_end"),

	num_input: shell.get_sub_num,
	slash_num_input: shell.get_grp_num,
	command: {
	 'A': { eval: 'bbs.auto_msg()' },
	 'Z': { eval: 'bbs.chat_sec()' },
	 'D': { eval: 'bbs.user_config(); exit();' },
//	 'E': { eval: 'menu = email_menu'},
	 'L': { eval: 'upload_user_file()'
			,msg: '\r\n\x01c\x01h' + gettext("Upload File to User") + '\r\n' },
	 'E': { eval: 'send_email()' },
	 'Q': { eval: 'send_netmail()' },
	 'H': { eval: 'bbs.read_mail(MAIL_YOUR, user.number, LM_UNREAD | LM_REVERSE)' },
    'F': { eval: 'bbs.email(undefined, 1, "", "Feedback")'  },
    'Y': { eval: 'bbs.read_mail(MAIL_SENT, user.number, LM_REVERSE)' },
//     'C': { msg: '\r\n\x01y\x01h Sysop not available.\r\n\r\n\x01P' },
	 'C': { eval: 'page_sysop()' },
    'X': { eval: 'bbs.sub_info()' },
	 'B': { eval: 'bbs.text_sec()' },
	 'K': { eval: 'main_info()' },
//	 'I': { exec: 'vbbsstatus.js' },
	 'I': { exec: 'vbbsstatus.js', args: ['-SHOW'] },
	 '$': { eval: 'select_msg_area()' }, 
	 'M': { eval: 'bbs.read_mail(MAIL_YOUR, user.number)' },
	 'N': { eval: 'bbs.scan_subs(SCAN_NEW)'
			,msg: '\r\n\x01y\x01h' + gettext("New Message Scan") + '\r\n' },
	 'P': { eval: 'bbs.post_msg()' },
	'/P': { exec: 'postpoll.js' },
	'/M': { exec: 'postmeme.js' },
	 '!': { eval: 'bbs.qwk_sec()' },
	 'R': { eval: 'bbs.scan_msgs()' },
	 'S': { eval: 'bbs.scan_subs(SCAN_TOYOU)'
			,msg: '\r\n\x01y\x01h' + gettext("Scan for Messages Posted to You") + '\r\n' },
	'/S': { eval: 'bbs.scan_subs(SCAN_TOYOU, /* all */true)' },
	 'U': { eval: 'list_users()' },
//	'U': { eval: 'bbs.list_users(UL_ALL)' },
//	 '/V': { exec: 'scanpolls.js' },
	 'V': { exec: 'scanpolls.js', args: ['all'] },
//    'W': { eval: 'bbs.list_nodes()' },
    'O': { eval: 'bbs.xtrn_sec()' },
    'J': { exec: 'msgscancfg.js' },
	 '&': { exec: 'avatar_chooser.js'
			,ars: 'ANSI and not GUEST'
			,err: '\r\n' + gettext("Sorry, only regular users with ANSI terminals can do that.") + '\r\n' },
//	 'B': { eval: 'bbs.scan_subs(SCAN_BACK)'
//			,msg: '\r\n\x01c\x01h' + gettext("Browse/New Message Scan") + '\r\n' },
	 'W': { eval: 'bbs.whos_online()' }, 
//	 'Z': { eval: 'bbs.scan_subs(SCAN_NEW | SCAN_CONT)'
//			,msg: '\r\n\x01c\x01h' + gettext("Continuous New Message Scan") + '\r\n' },
//	'/Z': { eval: 'bbs.scan_subs(SCAN_NEW | SCAN_CONT, /* all */true)' },
//	 '*': { eval: 'show_subs(bbs.curgrp)' },
//	'/*': { eval: 'show_grps()' },
//	'/N': { eval: 'bbs.scan_subs(SCAN_NEW, /* all */true)' },
//	 'G': { eval: 'logoff(/* fast: */false)' },
	 'G': { exec: 'vbbsstatus.js', args: ['-LOGOFF'] },
	'/G': { eval: 'logoff(/* fast: */true)' },
//	 'M': { eval: 'bbs.time_bank()' },
//	 'L': { eval: 'bbs.list_msgs()' },
//	 'F': { eval: 'bbs.scan_subs(SCAN_FIND)'
//			,msg: '\r\n\x01c\x01h' + gettext("Find Text in Messages") + '\r\n' },
//	'/F': { eval: 'bbs.scan_subs(SCAN_FIND, /* all */true)' },
	 '*': { eval: 'bbs.menu("sysmain")'
			,ars: 'SYSOP or EXEMPT Q or I or N' },
	 '#': {  msg: '\r\n\x01y\x01h' + gettext("Type the actual number to switch, not the symbol.") + '\r\n' },
	'/#': {  msg: '\r\n\x01y\x01h' + gettext("Type the actual number to switch, not the symbol.") + '\r\n' },
	},
	nav: {
	'\r': { },
	 'T': { eval: 'menu = file_menu' },
	 '>': { eval: 'sub_up()' },
	 '.': { eval: 'sub_up()' },
	 '}': { eval: 'sub_up()' },
	 ')': { eval: 'sub_up()' },
	 '+': { eval: 'sub_up()' },
	 '=': { eval: 'sub_up()' },
	 '<': { eval: 'sub_down()' },
	 ',': { eval: 'sub_down()' },
	 '{': { eval: 'sub_down()' },
	 '(': { eval: 'sub_down()' },
	 '-': { eval: 'sub_down()' },
	 ']': { eval: 'grp_up()' },
	 '[': { eval: 'grp_down()' },
	},
};



// Can't do these statically through initialization:
shell.main_menu.nav[KEY_UP] = { eval: 'sub_up()' };
shell.main_menu.nav[KEY_DOWN] = { eval: 'sub_down()' };
shell.main_menu.nav[KEY_RIGHT] = { eval: 'grp_up()' };
shell.main_menu.nav[KEY_LEFT] = { eval: 'grp_down()' };

//if (typeof bbs.email_sec != 'function')
//	shell.main_menu.command['E'] = { exec: 'email_sec.js' };

shell.file_menu = {
	file: vbbsMenuPath+"transfer",
	cls: true,
	eval: 'bbs.file_cmds++',
	node_action: NODE_XFER,
	prompt: gettext("\x01-\x01c", "shell_prompt_begin")
		+ gettext("\x01h\x01yTopic:\x01n")
		+ gettext(" @LIB@\r\n\x01h\x01y[\x01n@DN@\x01h\x01y] \x01n@DIR@\x01n\x01r\x01h\x01y\r\nTime "+time_prefix+" = "+ time_code +"\x01n: ", "shell_file_prompt_end"),

	num_input: shell.get_dir_num,
	slash_num_input: shell.get_lib_num,
	command: {
	 'B': { eval: 'bbs.batch_menu()' },
	 'D': { eval: 'download_files()'
			,msg: '\r\n\x01y\x01h' + gettext("Download File(s)") + '\r\n'
			,ars: 'REST NOT D' },
	'/D': { eval: 'download_user_files()'
			,msg: '\r\n\x01y\x01h' + gettext("Download File(s) from User(s)") + '\r\n'
			,ars: 'REST NOT D' },
	 'E': { eval: 'view_file_info(FI_INFO)'
			,msg: '\r\n\x01y\x01h' + gettext("List Extended File Information") + '\r\n' },
	 'F': { eval: 'bbs.scan_dirs(FL_FINDDESC);'
			,msg: '\r\n\x01y\x01h' + gettext("Find Text in File Descriptions (no wildcards)") + '\r\n' },
	'/F': { eval: 'bbs.scan_dirs(FL_FINDDESC, /* all: */true);' },
	 'I': { eval: 'file_info()' },
	 '$': { eval: 'select_file_area()' },
//	 'C': { eval: 'select_file_area()' },
	 'L': { eval: 'list_files()' },
	 'N': { eval: 'bbs.scan_dirs(FL_ULTIME)'
			,msg: '\r\n\x01y\x01h' + gettext("New File Scan") + '\r\n' }, //
	 'R': { eval: 'view_file_info(FI_REMOVE)'
			,msg: '\r\n\x01y\x01h' + gettext("Remove/Edit File(s)") + '\r\n' },
	 'S': { eval: 'bbs.scan_dirs(FL_NO_HDR)'
			,msg: '\r\n\x01y\x01h' + gettext("Search for Filename(s)") + '\r\n' },
	'/S': { eval: 'bbs.scan_dirs(FL_NO_HDR, /* all */true) ' },
	 'T': { eval: 'bbs.temp_xfer()' },
	 'U': { eval: 'upload_file()'
			,msg: '\r\n\x01y\x01h' + gettext("Upload File") + '\r\n' },
	'K': { eval: 'upload_user_file()'
			,msg: '\r\n\x01c\x01h' + gettext("Upload File to User") + '\r\n' },
	 'V': { eval: 'view_files()'
			,msg: '\r\n\x01y\x01h' + gettext("View File(s)") + '\r\n' },
	 'W': { eval: 'bbs.whos_online()' },
	 'X': { eval: 'upload_sysop_file()'
			,msg: '\r\n\x01y\x01h' + gettext("Upload File to Sysop") + '\r\n' },
	 '*': { eval: 'show_dirs(bbs.curlib)' },
	'/*': { eval: 'show_libs()' },
	 'J': { exec: 'filescancfg.js' },
	 'O': { eval: 'bbs.xtrn_sec()' },
	 '!': { eval: 'bbs.menu("sysxfer")'
			,ars: 'SYSOP' },
	 '#': {  msg: '\r\n\x01y\x01h' + gettext("Type the number to switch, not the symbol.") + '\r\n' },
	'/#': {  msg: '\r\n\x01y\x01h' + gettext("Type the number to switch, not the symbol.") + '\r\n' },
	 'Z': { eval: 'bbs.chat_sec()' },
//	'/N': { eval: 'bbs.scan_dirs(FL_ULTIME, /* all */true)' },
//	 'G': { eval: 'logoff(/* fast: */false)' }, //
//	'/L': { eval: 'bbs.list_nodes()' },
	 'G': { exec: 'vbbsstatus.js', args: ['-LOGOFF'] },
	'/G': { eval: 'logoff(/* fast: */true)' },
	},
	nav: {
	'\r': { },
	 'Q': { eval: 'menu = main_menu' },
	 '>': { eval: 'dir_up()' },
	 '.': { eval: 'dir_up()' },
	 '}': { eval: 'dir_up()' },
	 ')': { eval: 'dir_up()' },
	 '+': { eval: 'dir_up()' },
	 '=': { eval: 'dir_up()' },
	 '<': { eval: 'dir_down()' },
     ',': { eval: 'dir_down()' },
	 '{': { eval: 'dir_down()' },
	 '(': { eval: 'dir_down()' },
	 '-': { eval: 'dir_down()' },
	 ']': { eval: 'lib_up()' },
	 '[': { eval: 'lib_down()' },
	},
};

// Can't do these statically through initialization:
shell.file_menu.nav[KEY_UP] = { eval: 'dir_up()' };
shell.file_menu.nav[KEY_DOWN] = { eval: 'dir_down()' };
shell.file_menu.nav[KEY_RIGHT] = { eval: 'lib_up()' };
shell.file_menu.nav[KEY_LEFT] = { eval: 'lib_down()' };

/*  might as well leave it here for ideas
shell.email_menu = {
	cls: true,
	file: vbbsMenuPath+"email",
	node_action: NODE_RMAL,
	prompt: "\x01h\x01y" + "Time" + " " + time_prefix + ": [\x01n" + time_code + "\x01h\x01y]: ",
//		+ "\x01b\x01h(\x01c" + shell.help_key + "\x01b=\x01c"
//		+ gettext("Help") + "\x01b)\r\n"
//		+ "\r\n"
//		+ "\x01c" + gettext("Email") + " \x01b" + gettext("Menu") + " \x01m: \x01n",

	command: {
		'R': { eval: 'bbs.read_mail(MAIL_YOUR, user.number)' },
		'S': { eval: 'send_email()' },
		'F': { eval: 'send_feedback()' },
		'K': { eval: 'bbs.read_mail(MAIL_SENT, user.number)' },
		'U': { eval: 'bbs.read_mail(MAIL_YOUR, user.number, LM_UNREAD | LM_REVERSE)' },
		'N': { eval: 'send_netmail()' },
	},
	nav: {
	'\r': { },
	 'Q': { eval: 'menu = main_menu' },
	},
};

*/


shell.menu = shell.main_menu;
shell.menu_loop();
