/**
 * Site Editor canvas support.
 *
 * The canvas replaces every block wrapper's id with its own block uuid, so
 * the classic ID-keyed CSS (#wrapper, #main-nav, #ticker, ...) never matches
 * there. This filter mirrors each block's anchor onto an
 * `informer-anchor-<anchor>` class, which css/editor-classic.css targets
 * with the same rules rewritten from the id selectors.
 */
( function ( wp ) {
	'use strict';

	if ( ! wp || ! wp.hooks || ! wp.compose || ! wp.element ) {
		return;
	}

	var withInformerAnchor = wp.compose.createHigherOrderComponent( function ( BlockListBlock ) {
		return function ( props ) {
			var anchor = props.attributes && props.attributes.anchor;

			if ( ! anchor ) {
				return wp.element.createElement( BlockListBlock, props );
			}

			var merged = ( props.className ? props.className + ' ' : '' ) + 'informer-anchor-' + anchor;

			return wp.element.createElement(
				BlockListBlock,
				Object.assign( {}, props, { className: merged } )
			);
		};
	}, 'withInformerAnchor' );

	wp.hooks.addFilter( 'editor.BlockListBlock', 'informer/anchor-class', withInformerAnchor );
} )( window.wp );
