(function(blocks, data, compose, element, blockEditor, components, serverSideRender) {
	const el = element.createElement;
	const __ = wp.i18n.__;
	const registerBlockType = blocks.registerBlockType;
	const { InspectorControls } = blockEditor;
	const { Fragment } = element;
	const { PanelBody, PanelRow, SelectControl } = components;
	const useBlockProps = blockEditor.useBlockProps;
	const { withSelect } = data;
	const { subscribe } = data.subscribe;
	
	registerBlockType('ics-calendar-pro/shortcode', {
		attributes: {
			calendar_id: {
				type: 'integer'
			}
		},
		edit: function(props) {
			const onChangePostId = (id) => {
				props.setAttributes({ calendar_id: parseInt(id) });
			};
			const { calendar_id } = props.attributes;

			const PostsDropdownControl = compose.compose(
				withSelect(function(select) {
					return {
						posts: select('core').getEntityRecords('postType', 'r34icspro_calendar')
					}
				}))(function(props) {
					let options = [];

					if (props.posts) {
						options.push({ value: 0, label: __('Select a Saved Calendar', 'ics-calendar-pro') });
						props.posts.forEach((post) => {
							// @todo Determine why we can't access 'view' meta value here
							const title = post.title.rendered + ' (ID: ' + post.id + ')';
							options.push({ value: post.id, label: title });
						});
					} else {
						options.push({ value: 0, label: __('Loading...', 'ics-calendar-pro') })
					}
					
					return el(SelectControl, {
						label: '',
						options: options,
						onChange: onChangePostId,
						value: calendar_id,
					});

				}
			);

			const MyServerSideRender = (props) => (
				el(serverSideRender, {
					block: 'ics-calendar-pro/shortcode',
					attributes: {
						calendar_id: props.attributes.calendar_id
					}
				})
			);

			return (el(Fragment, {},
				el(InspectorControls, {},
					el(PanelBody, { title: __('Saved Calendar', 'ics-calendar-pro'), initialOpen: true },
						el(PanelRow, {},
							el(PostsDropdownControl, { calendar_id: calendar_id })
						),
					),
				),
				el('div', useBlockProps(),
					el(MyServerSideRender, props)
				)
			));
		},
		save() {
			return null;
		}
	});
})(
	window.wp.blocks,
	window.wp.data,
	window.wp.compose,
	window.wp.element,
	window.wp.blockEditor,
	window.wp.components,
	window.wp.serverSideRender
);