/**
 * @file assets/js/blocks/block-search.js
 * Registers the mbs/search Gutenberg block.
 * Depends on mbs-blocks-editor (wp.* globals + window.mbsBlocksCore helpers).
 * Helpers used: none
 * @package MyBookShowroom
 * @since   1.0.0
 */

( function ( wp, mbsCore ) {
    'use strict';

    const { registerBlockType } = wp.blocks;
    const { InspectorControls, useBlockProps } = wp.blockEditor;
    const { ServerSideRender } = wp.serverSideRender;
    const { PanelBody, SelectControl, TextControl, RangeControl, ToggleControl } = wp.components;
    const { createElement: el, Fragment } = wp.element;

    // ============================================================================
    registerBlockType('mbs/search', {
        apiVersion: 3,
        title: 'Book Search',
        description: 'Live AJAX search widget for the book catalog.',
        icon: 'search',
        category: 'mbs',
        keywords: [ 'search', 'find', 'books', 'lookup', 'filter' ],

        attributes: {},

        edit: function (props) {
            return el(
                'div',
                useBlockProps({ className: 'mbs-block mbs-block-search' }),
                el(ServerSideRender, {
                    block: 'mbs/search',
                    attributes: {},
                })
            );
        },

        save: function () {
            return null; // Dynamic block - rendered by PHP via render_callback
        },
    });

} )( window.wp, window.mbsBlocksCore || {} );
