<?php
defined( 'ABSPATH' ) || exit;

class Ecafe_Theme_Template {

	function __construct() {

		$headers = Ecafe_Condition_Rules::get_instance()->ec_get_location_type( 'header' );
		$footers = Ecafe_Condition_Rules::get_instance()->ec_get_location_type( 'footer' );

		if ( ! empty( $headers ) ) {
			add_action( 'get_header', array( $this, 'get_header_render' ) );
		}
		if ( ! empty( $footers ) ) {
			add_action( 'get_footer', array( $this, 'get_footer_render' ) );
		}
	}

	public function get_header_render( $temp_name ) {

		require ECAFE_CLASSES_URL . 'builders/theme-header.php';

		$temp_name      = (string) $temp_name;
		$load_templates = array();
		if ( $temp_name !== '' ) {
			$load_templates[] = "header-{$temp_name}.php";
		}

		$load_templates[] = 'header.php';

		remove_all_actions( 'wp_head' );
		ob_start();
		locate_template( $load_templates, true );
		ob_get_clean();
	}

	public function get_footer_render( $temp_name ) {

		require ECAFE_CLASSES_URL . 'builders/theme-footer.php';
		$temp_name      = (string) $temp_name;
		$load_templates = array();
		if ( $temp_name !== '' ) {
			$load_templates[] = "footer-{$temp_name}.php";
		}

		$load_templates[] = 'footer.php';
		remove_all_actions( 'wp_footer' );
		ob_start();
		locate_template( $load_templates, true );
		ob_get_clean();
	}
}
