<?php

if ( ! defined( 'ABSPATH' ) ) { return; }
if ( ! function_exists( 'is_singular' ) || ! is_singular( 'product' ) ) { return; }
if ( ! class_exists( 'AIEO_DMM_Custom_Slots' ) ) { return; }

$slot_id = isset( $attributes['slotId'] ) ? sanitize_key( (string) $attributes['slotId'] ) : '';
if ( $slot_id === '' ) { return; }

$html = AIEO_DMM_Custom_Slots::render_slot( $slot_id );
if ( $html === '' ) { return; }

$wrapper_attrs = function_exists( 'get_block_wrapper_attributes' )
    ? get_block_wrapper_attributes( array(
        'class'          => 'aieo-custom-slot aieo-custom-slot--' . sanitize_html_class( $slot_id ) . ' aieo-recommendations',
        'data-aieo-reco' => $slot_id,
        'data-section'   => $slot_id,
    ) )
    : 'class="aieo-custom-slot aieo-custom-slot--' . esc_attr( sanitize_html_class( $slot_id ) ) . ' aieo-recommendations" data-aieo-reco="' . esc_attr( $slot_id ) . '" data-section="' . esc_attr( $slot_id ) . '"';

echo '<section ' . $wrapper_attrs . '>' . $html . '</section>';
