<?php
if ( ! defined( 'ABSPATH' ) ) exit;

$code = isset( $attributes['code'] ) ? $attributes['code'] : '';

$id = wp_unique_id( 'bhcCodeHighlight-' );

// Everything except the (potentially large) code string is exposed to the
// frontend view script via data-attributes; the code itself rides in the <pre>.
$filtered_attributes = $attributes;
unset( $filtered_attributes['code'] );
?>
<div
    <?php echo get_block_wrapper_attributes(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped by core. ?>
    id="<?php echo esc_attr( $id ); ?>"
    data-attributes='<?php echo esc_attr( wp_json_encode( $filtered_attributes ) ); ?>'
>
    <pre class="bchCodeData" style="display:none;"><?php echo esc_html( wp_json_encode( $code ) ); ?></pre>
</div>
