import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor";
import { __ } from "@wordpress/i18n";
import arrow from "../img/arrow-right-circle.svg";
import getAdminLanguageFromCookies from "../../../../utils/getAdminLanguageFromCookies.js";

export default function save({ attributes }) {
	let { chapterLinkTitle, chapterLinkDescription, chapterLinkRelatedPost } =
		attributes;

	const currentLang = getAdminLanguageFromCookies("wp-wpml_current_language");
	const localVersionTextDescription =
		currentLang === "nl" ? "Meer weten" : "En savoir plus";
	return (
		<div
			{...useBlockProps.save({
				className: `homegrade-blocks-lien-chapitre`,
			})}
		>
			<RichText.Content
				tagName="h4"
				value={chapterLinkTitle}
				className="homegrade-blocks-lien-chapitre__title"
			/>
			<RichText.Content
				tagName="p"
				value={chapterLinkDescription}
				className="homegrade-blocks-lien-chapitre__description"
			/>

			{chapterLinkRelatedPost && chapterLinkRelatedPost.url && (
				<a
					className="homegrade-blocks-lien-chapitre__cta"
					href={chapterLinkRelatedPost.url}
					target={chapterLinkRelatedPost.opensInNewTab ? "_blank" : "_self"}
					rel="noopener"
				>
					{localVersionTextDescription}
					<div class="cta_arrow_button">
						<img src={arrow} alt="" />
					</div>
				</a>
			)}
		</div>
	);
}
