import { __ } from "@wordpress/i18n";
import "./editor.scss";

import { useBlockProps, InnerBlocks } from "@wordpress/block-editor";

export default function Edit({ attributes, setAttributes }) {
	function getAdminLanguageFromCookie(c_name) {
		var c_value = document.cookie,
			c_start = c_value.indexOf(" " + c_name + "=");
		if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
		if (c_start == -1) {
			c_value = null;
		} else {
			c_start = c_value.indexOf("=", c_start) + 1;
			var c_end = c_value.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = c_value.length;
			}
			c_value = unescape(c_value.substring(c_start, c_end));
		}
		return c_value;
	}
	const currentLang = getAdminLanguageFromCookie("wp-wpml_current_language");
	const localBlockName =
		currentLang === "fr"
			? "Publications et liens utiles"
			: "Publicaties en nuttige links";
	return (
		<>
			<section
				id="aller-plus-loin"
				{...useBlockProps({ className: `homegrade-blocks-plus-loin` })}
			>
				{localBlockName && (
					<h2 className="homegrade-blocks-plus-loin__block-title">
						{localBlockName}
					</h2>
				)}

				<InnerBlocks
					allowedBlocks={[
						"core/paragraph",
						"homegrade-blocks/content-heading",
						"core/list",
						"core/buttons",
						"core/button",
						"core/colums",
						"core/colum",
						"homegrade-content-blocks/content-heading",
					]}
					template={[["core/paragraph"]]}
				/>
			</section>
		</>
	);
}
