<?php
/**
 * Server-side render for blocksify/icon-list.
 *
 * Icon List is fully server-rendered per FOUNDATION §9.5 — `save.js`
 * returns bare `<InnerBlocks.Content />` and this file wraps the
 * serialized `blocksify/icon-list-item` children in the list shell:
 *
 *   <ul class="bsy-iconlist bsy-iconlist-{uid}" [id="…"]>
 *     {child <li> items via $content}
 *   </ul>
 *
 * Each child renders its own `<li>` (the child is NOT short-circuited —
 * unlike Tabs, every item is self-contained, so we just wrap the
 * concatenated child output). Per-instance CSS (list layout + icon
 * layout + Item/Icon/Text StylingRepeater) flows through
 * `Blocksify_CSS_Pipeline` once the adapter map registers
 * `blocksify/icon-list` (see `Blocksify_CSS_Generator::generate_block_css`).
 *
 * @package Blocksify
 *
 * @var array    $attributes Block attributes.
 * @var string   $content    Serialized inner blocks (item <li> markup).
 * @var WP_Block $block      Parsed block instance.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( isset( $_GET['blocksify_debug'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	$debug_css = Blocksify_CSS_Generator::generate_block_css( 'blocksify/icon-list', $attributes );
	echo "\n<!-- Blocksify Icon List CSS:\n" . esc_html( $debug_css ) . "\n-->\n";
}

$uid        = isset( $attributes['uid'] ) ? (string) $attributes['uid'] : '';
$user_class = isset( $attributes['className'] ) ? trim( (string) $attributes['className'] ) : '';
$anchor     = isset( $attributes['anchor'] ) ? (string) $attributes['anchor'] : '';

// Per-instance class only on the frontend — `supports.className: false`
// strips the WP-auto `wp-block-blocksify-icon-list`. `.bsy-iconlist`
// shared base carries the structural invariants from style.css; the
// per-instance class carries the pipeline CSS. `attributes.className`
// (Inspector → Advanced) merges manually — pure-dynamic save has no
// `useBlockProps.save` to do it.
$classes = array( 'bsy-iconlist' );
if ( '' !== $uid ) {
	$classes[] = 'bsy-iconlist-' . preg_replace( '/[^a-z0-9_-]/i', '', $uid );
}
if ( '' !== $user_class ) {
	$classes[] = $user_class;
}
$class_attr = esc_attr( implode( ' ', $classes ) );

$id_attr = '' !== $anchor ? ' id="' . esc_attr( $anchor ) . '"' : '';

echo '<ul class="' . $class_attr . '"' . $id_attr . ' role="list">' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	. $content // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	. '</ul>';
