import { whitespace } from "../../../hast-util-whitespace/lib/index.js";
import { siblingAfter } from "./util/siblings.js";
import { omission } from "./omission.js";
const closing = omission({
	body,
	caption: headOrColgroupOrCaption,
	colgroup: headOrColgroupOrCaption,
	dd,
	dt,
	head: headOrColgroupOrCaption,
	html,
	li,
	optgroup,
	option,
	p,
	rp: rubyElement,
	rt: rubyElement,
	tbody,
	td: cells,
	tfoot,
	th: cells,
	thead,
	tr
});
function headOrColgroupOrCaption(g, _, v) {
	let y = siblingAfter(v, _, !0);
	return !y || y.type !== "comment" && !(y.type === "text" && whitespace(y.value.charAt(0)));
}
function html(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type !== "comment";
}
function body(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type !== "comment";
}
function p(e, g, _) {
	let v = siblingAfter(_, g);
	return v ? v.type === "element" && (v.tagName === "address" || v.tagName === "article" || v.tagName === "aside" || v.tagName === "blockquote" || v.tagName === "details" || v.tagName === "div" || v.tagName === "dl" || v.tagName === "fieldset" || v.tagName === "figcaption" || v.tagName === "figure" || v.tagName === "footer" || v.tagName === "form" || v.tagName === "h1" || v.tagName === "h2" || v.tagName === "h3" || v.tagName === "h4" || v.tagName === "h5" || v.tagName === "h6" || v.tagName === "header" || v.tagName === "hgroup" || v.tagName === "hr" || v.tagName === "main" || v.tagName === "menu" || v.tagName === "nav" || v.tagName === "ol" || v.tagName === "p" || v.tagName === "pre" || v.tagName === "section" || v.tagName === "table" || v.tagName === "ul") : !_ || !(_.type === "element" && (_.tagName === "a" || _.tagName === "audio" || _.tagName === "del" || _.tagName === "ins" || _.tagName === "map" || _.tagName === "noscript" || _.tagName === "video"));
}
function li(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && v.tagName === "li";
}
function dt(e, g, _) {
	let v = siblingAfter(_, g);
	return !!(v && v.type === "element" && (v.tagName === "dt" || v.tagName === "dd"));
}
function dd(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && (v.tagName === "dt" || v.tagName === "dd");
}
function rubyElement(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && (v.tagName === "rp" || v.tagName === "rt");
}
function optgroup(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && v.tagName === "optgroup";
}
function option(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && (v.tagName === "option" || v.tagName === "optgroup");
}
function thead(e, g, _) {
	let v = siblingAfter(_, g);
	return !!(v && v.type === "element" && (v.tagName === "tbody" || v.tagName === "tfoot"));
}
function tbody(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && (v.tagName === "tbody" || v.tagName === "tfoot");
}
function tfoot(e, g, _) {
	return !siblingAfter(_, g);
}
function tr(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && v.tagName === "tr";
}
function cells(e, g, _) {
	let v = siblingAfter(_, g);
	return !v || v.type === "element" && (v.tagName === "td" || v.tagName === "th");
}
export { closing };
