<?php
if ( ! defined( 'ABSPATH' ) ) exit;
final class Sifency_Portfolio_Archive_Render {
    public function __construct() {
        if ( is_admin() ) return;
        add_filter( 'template_include', [ $this, 'override_portfolio_archive_template' ], 999 );
    }
    public function override_portfolio_archive_template( $template ) {
        if ( ! is_post_type_archive( 'portfolio' ) ) {
            return $template;
        }
        $canvas_path = SIFENCY_TB_PATH . 'post-type/portfolio/templates/sifency-portfolio-archive-canvas.php';
        if ( ! file_exists( $canvas_path ) ) {
            return $template;
        }
        $sifency_addons_template_id = Sifency_Frontend_Helper::find_matching_template( 'portfolio-archive' );
        set_query_var( 'sifency_portfolio_archive_template_id', $sifency_addons_template_id );
        return $canvas_path;
    }
}
