import { whitespace } from "../../../hast-util-whitespace/lib/index.js";
import { siblingAfter, siblingBefore } from "./util/siblings.js";
import { omission } from "./omission.js";
import { closing } from "./closing.js";
const opening = omission({
	body,
	colgroup,
	head,
	html,
	tbody
});
function html(e) {
	let o = siblingAfter(e, -1);
	return !o || o.type !== "comment";
}
function head(e) {
	let a = /* @__PURE__ */ new Set();
	for (let o of e.children) if (o.type === "element" && (o.tagName === "base" || o.tagName === "title")) {
		if (a.has(o.tagName)) return !1;
		a.add(o.tagName);
	}
	let o = e.children[0];
	return !o || o.type === "element";
}
function body(o) {
	let s = siblingAfter(o, -1, !0);
	return !s || s.type !== "comment" && !(s.type === "text" && whitespace(s.value.charAt(0))) && !(s.type === "element" && (s.tagName === "meta" || s.tagName === "link" || s.tagName === "script" || s.tagName === "style" || s.tagName === "template"));
}
function colgroup(e, s, c) {
	let l = siblingBefore(c, s), u = siblingAfter(e, -1, !0);
	return c && l && l.type === "element" && l.tagName === "colgroup" && closing(l, c.children.indexOf(l), c) ? !1 : !!(u && u.type === "element" && u.tagName === "col");
}
function tbody(e, s, c) {
	let l = siblingBefore(c, s), u = siblingAfter(e, -1);
	return c && l && l.type === "element" && (l.tagName === "thead" || l.tagName === "tbody") && closing(l, c.children.indexOf(l), c) ? !1 : !!(u && u.type === "element" && u.tagName === "tr");
}
export { opening };
