<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template variables are scoped when required inside the block render callback.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once dirname( __DIR__, 3 ) . '/includes/block-css-generator.php';

// ─── Identity ───────────────────────────────────────────────────────────────

$tag_name     = isset( $attributes['tagName'] ) ? tag_escape( $attributes['tagName'] ) : 'div';
$anchor       = isset( $attributes['anchor'] ) ? sanitize_title( $attributes['anchor'] ) : '';
$unique_class = ! empty( $attributes['uniqueClass'] ) ? sanitize_html_class( $attributes['uniqueClass'] ) : '';
if ( empty( $unique_class ) ) {
	$unique_class = sanitize_html_class( 'axb-' . wp_unique_id() );
}

// ─── Wrapper attributes ───────────────────────────────────────────────────────

$extra_attrs = [ 'class' => trim( 'axcelersblocks-columns ' . $unique_class ) ];
if ( $anchor ) {
	$extra_attrs['id'] = $anchor;
}
$wrapper_attrs = get_block_wrapper_attributes( $extra_attrs );

// ─── CSS generation & collection (no hover state for this block) ──────────────

$devices    = axcelersblocks_get_responsive_devices();
$styles_css = axcelersblocks_generate_block_styles( $unique_class, $devices, $attributes );
axcelersblocks_collect_block_styles( $unique_class, $block, $styles_css );

// ─── Output (container prints its inner block content) ────────────────────────

printf(
	'<%1$s %2$s>%3$s</%1$s>',
	esc_attr( $tag_name ),
	$wrapper_attrs, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns escaped output.
	$content        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Inner block content is already rendered/sanitized by each inner block's own render callback.
);
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
