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

/**
 * Sifency Event Archive Render
 * Uses a dedicated Elementor template for the Event archive.
 */
if ( Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) {
final class Sifency_Event_Archive_Render {

    public function __construct() {
        if ( is_admin() ) return;
        add_filter( 'template_include', [ $this, 'override_event_archive_template' ], 999 );
    }

    /**
     * Replaces the default archive template for the 'event' CPT with a canvas.
     */
    public function override_event_archive_template( $template ) {
        if ( ! is_post_type_archive( 'event' ) ) {
            return $template;
        }
        remove_filter('template_include', [ Sifency_Addons_Theme_Builder_Master::$sifency_addons_frontend_render, 'load_canvas_template' ], 999);

        $canvas_path = SIFENCY_TB_PATH . 'post-type/event/templates/sifency-event-archive-canvas.php';

        if ( ! file_exists( $canvas_path ) ) {
            return $template;
        }
        $sifency_addons_template_id = Sifency_Frontend_Helper::find_matching_template( 'event-archive' );
        set_query_var( 'sifency_event_archive_template_id', $sifency_addons_template_id );
        return $canvas_path;
        
    }
}
}


