import.meta.glob('../../blocks/**/*.js', { eager: true });

window.onload = (event) => {
    if (wp.blocks !== undefined) {
        const allowedCoreBlocks = [
            'core/block',
            'core/group',
            'core/shortcode',
            'core/heading',
            'core/paragraph',
            'core/image',
            'core/gallery',
            'core/list',
            'core/video',
            'core/button',
            'core/buttons',
            'core/embed',
            'core/list-item',
            'core/columns',
            'core/column'
        ];

        const allowedEmbedBlocks = ['vimeo', 'youtube', 'spotify', 'twitter', 'facebook', 'instagram'];

        const widthAdjustableBlocks = ['core/paragraph', 'core/list', 'core/heading', 'core/embed'];

        wp.blocks.getBlockTypes().forEach(function (block) {
            if (-1 === allowedCoreBlocks.indexOf(block.name) && !block.name.includes('acf/')) {
                wp.blocks.unregisterBlockType(block.name);
            }
        });

        wp.blocks.getBlockVariations('core/embed').forEach(function (blockVariation) {
            if (-1 === allowedEmbedBlocks.indexOf(blockVariation.name)) {
                wp.blocks.unregisterBlockVariation('core/embed', blockVariation.name);
            }
        });

        widthAdjustableBlocks.forEach(function (block) {
            wp.blocks.registerBlockStyle(block, {
                name: 'small',
                label: 'Smalle container'
            });

            wp.blocks.registerBlockStyle(block, {
                name: 'medium',
                label: 'Medium container'
            });
        });

        wp.blocks.registerBlockStyle('core/button', {
            name: 'link',
            label: 'Link'
        });
    }
};
