/**
 * User menu block — inspector + server-side preview.
 */
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import ServerSideRender from '@wordpress/server-side-render';
import { Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

import UserMenuInspector from './user-menu-inspector';
import './editor.scss';

export default function Edit({ attributes, setAttributes }) {
	const props = useBlockProps({
		className: 'movie-engine-user-menu-block-editor',
	});

	return (
		<>
			<InspectorControls>
				<UserMenuInspector attributes={attributes} setAttributes={setAttributes} />
			</InspectorControls>
			<div {...props}>
				<div className="movie-engine-user-menu-block-editor__preview movie-engine-plugin">
					<ServerSideRender
						block="cine-movie-engine/user-menu"
						attributes={attributes}
						LoadingResponsePlaceholder={() => (
							<p className="movie-engine-user-menu-block-editor__preview-loading">
								<Spinner />
								{__('Loading preview…', 'cine-movie-engine')}
							</p>
						)}
						ErrorResponsePlaceholder={() => (
							<p className="movie-engine-user-menu-block-editor__preview-loading">
								{__(
									'Preview unavailable. Check the front end or try saving the page.',
									'cine-movie-engine'
								)}
							</p>
						)}
					/>
				</div>
			</div>
		</>
	);
}
