import isFunction_default from "../../../../../lodash-es/isFunction.js";
import isArray_default from "../../../../../lodash-es/isArray.js";
import isEmpty_default from "../../../../../lodash-es/isEmpty.js";
import keys_default from "../../../../../lodash-es/keys.js";
import compact_default from "../../../../../lodash-es/compact.js";
import forEach_default from "../../../../../lodash-es/forEach.js";
import filter_default from "../../../../../lodash-es/filter.js";
import map_default from "../../../../../lodash-es/map.js";
import isUndefined_default from "../../../../../lodash-es/isUndefined.js";
import { defineNameProp } from "../../lang/lang_extensions.js";
function defaultVisit(e, d) {
	let f = keys_default(e), m = f.length;
	for (let p = 0; p < m; p++) {
		let m = e[f[p]], h = m.length;
		for (let e = 0; e < h; e++) {
			let f = m[e];
			f.tokenTypeIdx === void 0 && this[f.name](f.children, d);
		}
	}
}
function createBaseSemanticVisitorConstructor(e, p) {
	let m = function() {};
	return defineNameProp(m, e + "BaseSemantics"), m.prototype = {
		visit: function(e, f) {
			if (isArray_default(e) && (e = e[0]), !isUndefined_default(e)) return this[e.name](e.children, f);
		},
		validateVisitor: function() {
			let e = validateVisitor(this, p);
			if (!isEmpty_default(e)) {
				let d = map_default(e, (e) => e.msg);
				throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:\n\t${d.join("\n\n").replace(/\n/g, "\n	")}`);
			}
		}
	}, m.prototype.constructor = m, m._RULE_NAMES = p, m;
}
function createBaseVisitorConstructorWithDefaults(e, d, f) {
	let p = function() {};
	defineNameProp(p, e + "BaseSemanticsWithDefaults");
	let m = Object.create(f.prototype);
	return forEach_default(d, (e) => {
		m[e] = defaultVisit;
	}), p.prototype = m, p.prototype.constructor = p, p;
}
var CstVisitorDefinitionError;
(function(e) {
	e[e.REDUNDANT_METHOD = 0] = "REDUNDANT_METHOD", e[e.MISSING_METHOD = 1] = "MISSING_METHOD";
})(CstVisitorDefinitionError ||= {});
function validateVisitor(e, d) {
	return validateMissingCstMethods(e, d);
}
function validateMissingCstMethods(d, f) {
	return compact_default(map_default(filter_default(f, (f) => isFunction_default(d[f]) === !1), (e) => ({
		msg: `Missing visitor method: <${e}> on ${d.constructor.name} CST Visitor.`,
		type: CstVisitorDefinitionError.MISSING_METHOD,
		methodName: e
	})));
}
export { createBaseSemanticVisitorConstructor, createBaseVisitorConstructorWithDefaults };
