/**
 * Retrieves the translation of text.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
 */
import { __ } from "@wordpress/i18n";

/**
 * Use Effect Hook
 */
import { useEffect } from "@wordpress/element";

/**
 * React hook that is used to mark the block wrapper element.
 * It provides all the necessary props like the class name.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
 */
import { useBlockProps } from "@wordpress/block-editor";

/**
 * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
 * Those files can contain any CSS code that gets applied to the editor.
 *
 * @see https://www.npmjs.com/package/@wordpress/scripts#using-css
 */
import "./editor.scss";
import SidePanel from "./side-panel";

/**
 * The edit function describes the structure of your block in the context of the
 * editor. This represents what the editor will render when the block is used.
 *
 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
 *
 * @return {Element} Element to render.
 */
export default function Edit({ attributes, setAttributes }) {
	return (
		<div {...useBlockProps()}>
			<SidePanel attributes={attributes} setAttributes={setAttributes} />
			{!attributes.images.length && <p>Please add images in the sidebar</p>}
			{!!attributes.images.length && (
				<>
					<div className="">
						<div class="animated-background">
							<img
								src={attributes.images[0]["url"]}
								alt={attributes.images[0]["alt"]}
							/>
						</div>

						{attributes.images.map((image, index) => {
							if (index > 0) {
								return (
									<div class="animated-layer">
										<img src={image["url"]} alt={image["alt"]} />
									</div>
								);
							}
							return <></>;
						})}
					</div>
				</>
			)}
		</div>
	);
}
