import {
	__,
	_x,
	getLocaleData,
	hasTranslation,
	resetLocaleData,
} from "@wordpress/i18n";
import "./editor.scss";
import { useSelect } from "@wordpress/data";
import { useBlockProps } from "@wordpress/block-editor";
import { useEffect, useState } from "@wordpress/element";

import { useEntityProp } from "@wordpress/core-data";

export default function Edit({ attributes, setAttributes }) {
	const { blockName, test } = attributes;
	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");

	useEffect(() => {
		const localBlockName =
			currentLang === "fr" ? "Vocabulaire" : "Vocabulairen";

		setAttributes({ blockName: localBlockName });
	}, [currentLang]);

	const [post, setPost] = useEntityProp("postType", "post");

	// Assurez-vous que la publication est définie avant d'accéder à la langue

	const language = post;

	return null;

	return (
		<p
			{...useBlockProps({
				className: `homegrade-blocks-starter`,
			})}
		>
			<p>{blockName}</p>
		</p>
	);
}
