
import { registerBlockType, createBlock } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

const edit = function () {
	return (
		<div className='book-an-appointment-block-container'>
			You will see a Booking Interface on frontend.
		</div>
	);
};

const save = function () {
	return (
		<div id="book-an-appointment-application"></div>
	);
};

// Register the block under its current, generic name.
registerBlockType('smartslot/book-an-appointment', {
	title: __('SmartSlot Appointment Scheduler - Book An Appointment', 'smartslot-appointment-scheduler'),
	icon: 'schedule',
	category: 'widgets',
	edit,
	save,
});

// Keep the legacy block name registered so pages that already contain it keep
// rendering and remain editable. Hidden from the inserter since new bookings
// should use the block above; editors can use "Transform to" to upgrade it.
registerBlockType('mandy-schedule/book-an-appointment', {
	title: __('SmartSlot Appointment Scheduler - Book An Appointment (legacy)', 'smartslot-appointment-scheduler'),
	icon: 'schedule',
	category: 'widgets',
	supports: {
		inserter: false,
	},
	transforms: {
		to: [
			{
				type: 'block',
				blocks: ['smartslot/book-an-appointment'],
				transform: () => createBlock('smartslot/book-an-appointment'),
			},
		],
	},
	edit,
	save,
});
