/**
 * maca Table Reservation block – editor
 */
(function () {
    var __ = wp.i18n.__;
    var registerBlockType = wp.blocks.registerBlockType;
    var el = wp.element.createElement;
    var ServerSideRender = wp.serverSideRender;
    var TextControl = wp.components.TextControl;

    registerBlockType('maca-restu/maca-table-booking', {
        title: __('maca Table Reservation', 'maca-restu-pro'),
        description: __('Button that opens a table reservation form.', 'maca-restu-pro'),
        category: 'maca-restu-pro',
        icon: 'calendar-alt',
        supports: {
            html: false
        },
        attributes: {
            button: { type: 'string', default: '' },
            title: { type: 'string', default: '' }
        },
        example: {
            attributes: {
                button: 'Book a table',
                title: 'Table Reservation'
            }
        },
        edit: function (props) {
            var attributes = props.attributes;
            var setAttributes = props.setAttributes;

            return el(
                'div',
                { className: 'maca-restu-block-editor' },
                el(ServerSideRender, {
                    block: 'maca-restu/maca-table-booking',
                    attributes: attributes
                }),
                el(
                    'div',
                    { className: 'maca-restu-block-controls' },
                    el(TextControl, {
                        label: __('Button text', 'maca-restu-pro'),
                        help: __('Leave empty to use the text from maca Restu → Table Reservations → Table settings.', 'maca-restu-pro'),
                        value: attributes.button || '',
                        onChange: function (value) {
                            setAttributes({ button: value });
                        }
                    }),
                    el(TextControl, {
                        label: __('Modal title', 'maca-restu-pro'),
                        help: __('Leave empty to use the title from maca Restu → Table Reservations → Table settings.', 'maca-restu-pro'),
                        value: attributes.title || '',
                        onChange: function (value) {
                            setAttributes({ title: value });
                        }
                    })
                )
            );
        },
        save: function () {
            return null;
        }
    });
})();
