<?php

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

if (!class_exists('AIEO_Event_SelfReg') && defined('AIEO_DIR') && file_exists(AIEO_DIR . 'includes/dmm/events/class-aieo-event-selfreg.php')) {
    require_once AIEO_DIR . 'includes/dmm/events/class-aieo-event-selfreg.php';
}
if (!class_exists('AIEO_Event_CPT') || !class_exists('AIEO_Event_SelfReg')) { return; }

$cpt = AIEO_Event_CPT::POST_TYPE;

$pid = isset($attributes['eventId']) ? (int) $attributes['eventId'] : 0;
if ($pid <= 0 && isset($block) && is_object($block) && !empty($block->context['postId'])) {
    $ctx = (int) $block->context['postId'];
    if ($ctx > 0 && get_post_type($ctx) === $cpt) { $pid = $ctx; }
}
if ($pid <= 0 && function_exists('is_singular') && is_singular($cpt)) {
    $pid = (int) get_queried_object_id();
}
if ($pid <= 0 || get_post_type($pid) !== $cpt) {
    return; 
}

$wrapper = function_exists('get_block_wrapper_attributes')
    ? get_block_wrapper_attributes(array('class' => 'aieo-event-registration'))
    : 'class="aieo-event-registration"';

echo '<div ' . $wrapper . '>'; 
echo AIEO_Event_SelfReg::render_form($pid); 
echo '</div>';
