Macro.add('textboxRand', {

		handler() {
            let output = "";
			if (this.args.length < 2) {
				const errors = [];
				if (this.args.length < 1) { errors.push('variable name'); }
				if (this.args.length < 2) { errors.push('default value'); }
				return this.error(`no ${errors.join(' or ')} specified`);
			}

			// Ensure that the variable name argument is a string.
			if (typeof this.args[0] !== 'string') {
				return this.error('variable name argument is not a string');
			}

			const varName = this.args[0].trim();
            const defaultValue = this.args[1];

			// Try to ensure that we receive the variable's name (incl. sigil), not its value.
			if (varName[0] !== '$' && varName[0] !== '_') {
				return this.error(`variable name "${this.args[0]}" is missing its sigil ($ or _)`);
			}


			const varId = Util.slugify(varName);

            output = `<span class="textboxRand"><<textbox "${varName}" ${defaultValue}>><<button '⚄'>><<set _textboxRandValue = ${this.args[2]}>><<run $("#textbox-${varId}").val(_textboxRandValue)>><<run State.setVar("${varName}",_textboxRandValue)>><</button>></span>`;

            jQuery(this.output).wiki(output);

			/*const el    = document.createElement('input');
			let autofocus = false;
			let passage;

			if (this.args.length > 3) {
				passage   = this.args[2];
				autofocus = this.args[3] === 'autofocus';
			}
			else if (this.args.length > 2) {
				if (this.args[2] === 'autofocus') {
					autofocus = true;
				}
				else {
					passage = this.args[2];
				}
			}

			if (typeof passage === 'object') {
				// Argument was in wiki link syntax.
				passage = passage.link;
			}

			// Set up and append the input element to the output buffer.
			jQuery(el)
				.attr({
					id        : `${this.name}-${varId}`,
					name      : `${this.name}-${varId}`,
					type      : asNumber ? 'number' : 'text',
					inputmode : asNumber ? 'decimal' : 'text',
					tabindex  : 0 // for accessiblity
				})
				.addClass(`macro-${this.name}`)
				.on('change.macros', this.createShadowWrapper(function () {
					State.setVar(varName, asNumber ? Number(this.value) : this.value);
				}))
				.on('keypress.macros', this.createShadowWrapper(function (ev) {
					// If Return/Enter is pressed, set the variable and, optionally, forward to another passage.
					if (ev.which === 13) { // 13 is Return/Enter
						ev.preventDefault();
						State.setVar(varName, asNumber ? Number(this.value) : this.value);

						if (passage != null) { // lazy equality for null
							Engine.play(passage);
						}
					}
				}))
				.appendTo(this.output);
            */
			// Set the variable and input element to the default value.
			//State.setVar(varName, defaultValue);
			//el.value = defaultValue;

		}
	});