Macro.add('succession', {
	tags     : ['then'],
	handler  : function () {
		try {
			const successions = (State.variables.successions ??= {});
			let successionId = this.args[0];

			State.variables.successions[successionId] ??= {i:0};
			
			let currentIteration = State.variables.successions[successionId].i;
			
			var output;

			if(currentIteration < this.payload.length){
				output = this.payload[currentIteration].contents;
				State.variables.successions[successionId].i += 1;
			}else{
				output = this.payload.last().contents;
			}

			jQuery(this.output).wiki(output);
		}
		catch (ex) {
			return this.error('ERROR in either-widget: ' + ex.message);
		}
	}
});
