<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Sifency Event Single Render
 * Dynamically replaces the default event single template with an Elementor one.
 */
if ( Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) {
final class Sifency_Event_Single_Render {
    public function __construct() {
        if ( is_admin() ) return;

        add_filter( 'template_include', [ $this, 'override_event_single_template' ], 99999 );
    }
    public function override_event_single_template( $template ) {
        if ( ! is_singular( 'event' ) ) {
            return $template;
        }
        remove_filter( 'template_include', [ Sifency_Addons_Theme_Builder_Master::$sifency_addons_frontend_render, 'load_canvas_template' ], 999 );
        $sifency_event_template_id = Sifency_Frontend_Helper::find_matching_template( 'event' );
        if ( empty( $sifency_event_template_id ) ) {
            return $template;
        }
        set_query_var( 'sifency_event_single_template_id', $sifency_event_template_id );
        $canvas_path = defined( 'SIFENCY_TB_PATH' )
            ? trailingslashit( SIFENCY_TB_PATH ) . 'post-type/event/templates/sifency-event-single-canvas.php'
            : plugin_dir_path( __FILE__ ) . 'templates/sifency-event-single-canvas.php';

        return file_exists( $canvas_path ) ? $canvas_path : $template;
    }
}
new Sifency_Event_Single_Render();
}
