import { __ } from "@wordpress/i18n";
import {
	InspectorControls,
	__experimentalLinkControl as LinkControl,
} from "@wordpress/block-editor";
import {
	PanelBody,
	ComboboxControl,
	__experimentalToggleGroupControl as ToggleGroupControl,
	__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from "@wordpress/components";
import "./editor.scss";
import { useSelect } from "@wordpress/data";
import { useEffect, useState } from "@wordpress/element";
import { decodeEntities } from "@wordpress/html-entities";

export default function OptionsSelectControl({
	setAttributes,
	chapterLinkRelatedPostId,
	chapterLinkRelatedPost,
}) {
	let [relatedQuestionPages, setRelatedQuestionPages] = useState(null);
	let [childTermsIdArray, setChildTermsIdArray] = useState(null);

	const lang = getAdminLanguageFromCookie("wp-wpml_current_language");

	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;
	}

	function handleRelatedPostChange(chapterLinkRelatedPost) {
		setAttributes({ chapterLinkRelatedPost });
	}

	return (
		<InspectorControls>
			<PanelBody
				className="related-conseil-panel-body"
				title={__("Page de lien de ce Chapitre ", "homegrade-blocks")}
			>
				<LinkControl
					value={chapterLinkRelatedPost}
					onChange={handleRelatedPostChange}
				/>
			</PanelBody>
		</InspectorControls>
	);
}
