import "../../devlop/lib/default.js";
import { markdownTable as e } from "../../markdown-table/index.js";
import { handle as t } from "../../mdast-util-to-markdown/lib/handle/index.js";
//#region ../../node_modules/mdast-util-gfm-table/lib/index.js
function n() {
	return {
		enter: {
			table: r,
			tableData: s,
			tableHeader: s,
			tableRow: a
		},
		exit: {
			codeText: c,
			table: i,
			tableData: o,
			tableHeader: o,
			tableRow: o
		}
	};
}
function r(e) {
	let t = e._align;
	this.enter({
		type: "table",
		align: t.map(function(e) {
			return e === "none" ? null : e;
		}),
		children: []
	}, e), this.data.inTable = !0;
}
function i(e) {
	this.exit(e), this.data.inTable = void 0;
}
function a(e) {
	this.enter({
		type: "tableRow",
		children: []
	}, e);
}
function o(e) {
	this.exit(e);
}
function s(e) {
	this.enter({
		type: "tableCell",
		children: []
	}, e);
}
function c(e) {
	let t = this.resume();
	this.data.inTable && (t = t.replace(/\\([\\|])/g, l));
	let n = this.stack[this.stack.length - 1];
	n.type, n.value = t, this.exit(e);
}
function l(e, t) {
	return t === "|" ? t : e;
}
function u(n) {
	let r = n || {}, i = r.tableCellPadding, a = r.tablePipeAlign, o = r.stringLength, s = i ? " " : "|";
	return {
		unsafe: [
			{
				character: "\r",
				inConstruct: "tableCell"
			},
			{
				character: "\n",
				inConstruct: "tableCell"
			},
			{
				atBreak: !0,
				character: "|",
				after: "[	 :-]"
			},
			{
				character: "|",
				inConstruct: "tableCell"
			},
			{
				atBreak: !0,
				character: ":",
				after: "-"
			},
			{
				atBreak: !0,
				character: "-",
				after: "[:|-]"
			}
		],
		handlers: {
			inlineCode: m,
			table: c,
			tableCell: u,
			tableRow: l
		}
	};
	function c(e, t, n, r) {
		return d(f(e, n, r), e.align);
	}
	function l(e, t, n, r) {
		let i = d([p(e, n, r)]);
		return i.slice(0, i.indexOf("\n"));
	}
	function u(e, t, n, r) {
		let i = n.enter("tableCell"), a = n.enter("phrasing"), o = n.containerPhrasing(e, {
			...r,
			before: s,
			after: s
		});
		return a(), i(), o;
	}
	function d(t, n) {
		return e(t, {
			align: n,
			alignDelimiters: a,
			padding: i,
			stringLength: o
		});
	}
	function f(e, t, n) {
		let r = e.children, i = -1, a = [], o = t.enter("table");
		for (; ++i < r.length;) a[i] = p(r[i], t, n);
		return o(), a;
	}
	function p(e, t, n) {
		let r = e.children, i = -1, a = [], o = t.enter("tableRow");
		for (; ++i < r.length;) a[i] = u(r[i], e, t, n);
		return o(), a;
	}
	function m(e, n, r) {
		let i = t.inlineCode(e, n, r);
		return r.stack.includes("tableCell") && (i = i.replace(/\|/g, "\\$&")), i;
	}
}
//#endregion
export { n as gfmTableFromMarkdown, u as gfmTableToMarkdown };
