<?php
/**
 * Single property template wrapper for Palace Properties.
 * Loads the active template's single.php.
 */
if ( ! defined( 'ABSPATH' ) ) exit;

get_header();

$template_slug = sanitize_text_field( get_option( 'ipp_select_template', 'palace-property' ) );
$post_id = get_the_ID();
$prop = new IPP_Property_Helper( $post_id );
?>

<?php
$single_classes = apply_filters( 'ipp_single_classes', [ 'ipp-single-page' ], $post_id );
?>
<div class="<?php echo esc_attr( implode( ' ', $single_classes ) ); ?>">
    <?php do_action( 'ipp_before_single', $post_id, $prop ); ?>

    <?php
    $single_path = INTEGRATE_PALACE_P_PLUGIN_DIR . 'public/templates/' . sanitize_file_name( $template_slug ) . '/single.php';
    $theme_single = get_stylesheet_directory() . '/palace-properties/single.php';
    if ( file_exists( $theme_single ) ) {
        $single_path = $theme_single;
    }
    $single_path = apply_filters( 'ipp_single_template', $single_path, $template_slug );
    if ( file_exists( $single_path ) ) {
        include $single_path;
    } else {
        // Legacy fallback
        include INTEGRATE_PALACE_P_PLUGIN_DIR . 'public/single-palace_property.php';
    }
    ?>

    <?php do_action( 'ipp_after_single', $post_id, $prop ); ?>
</div>

<?php
// Schema.org structured data — filterable
$schema = $prop->schema_json_ld();
echo apply_filters( 'ipp_property_schema', $schema, $post_id );

get_footer();
?>
