<?php
if ( ! defined( 'ABSPATH' ) ) exit;
final class Sifency_Blog_Single_Render {
    public function __construct() {
        if ( is_admin() ) return;
        add_filter( 'template_include', [ $this, 'override_single_template' ], 999 );
    }
    public function override_single_template( $template ) {
        if ( ! is_single() || get_post_type() !== 'post' ) {
            return $template;
        }
        $sifency_addons_template_id = Sifency_Frontend_Helper::find_matching_template( 'post' );
        if ( empty( $sifency_addons_template_id ) ) {
            return $template;
        }
        set_query_var( 'sifency_template_id', $sifency_addons_template_id );
        $blank_template = defined( 'SIFENCY_TB_PATH' )
            ? trailingslashit( SIFENCY_TB_PATH ) . 'post-type/blog/templates/sifency-single-canvas.php'
            : plugin_dir_path( __FILE__ ) . 'templates/sifency-single-canvas.php';

        return file_exists( $blank_template ) ? $blank_template : $template;
    }
}
new Sifency_Blog_Single_Render();
