<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
 * Server-side render callback for the SimplyConf Dashboard block.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block content.
 * @param WP_Block $block      Block instance.
 * @return string Rendered block HTML.
 */

// Enqueue the full-width CSS
wp_enqueue_style(
	'simplyconf-dashboard-block',
	SIMPLYCONF_URL . 'blocks/dashboard/style.css',
	array(),
	SIMPLYCONF_VERSION
);

// Get the event ID from block attributes or use default
$event_id = isset($attributes['eventId']) ? intval($attributes['eventId']) : 1;

// Get the hideTitle attribute
$hide_title = isset($attributes['hideTitle']) ? (bool) $attributes['hideTitle'] : false;

// Reuse the existing dashboard rendering logic
if (class_exists('SimplyConf_Frontend_Dashboard')) {
	$dashboard = new SimplyConf_Frontend_Dashboard();
	$dashboard_html = $dashboard->render_dashboard($event_id, $hide_title);
} else {
	$dashboard_html = '<p>' . esc_html__('SimplyConf Dashboard is not available.', 'simplyconf') . '</p>';
}

// Output the dashboard directly without additional wrapper
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is generated by SimplyConf_Frontend_Dashboard::render_dashboard() which handles its own escaping.
echo $dashboard_html;
