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

/**
 * Sifency Team Archive Render
 * Uses a dedicated Elementor template for the Team archive.
 */
/**
 * Conditionally loads the Sifency Team Single Render functionality.
 * This function acts as a safe loader, ensuring dependencies are met.
 */
final class Sifency_Team_Archive_Render {

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

    /**
     * Replaces the default archive template for the 'team' CPT with a canvas.
     */
    public function override_team_archive_template( $template ) {
        if ( ! is_post_type_archive( 'team' ) ) {
            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/member/templates/sifency-team-archive-canvas.php';

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