<?php

class template {

	public static $BLANK_PAGE = false;
	public static $classes = array();
	public static $logo;
	
	private static $init;
	
	public static function init() {
		global $settings;
		if( self::$init ) return;
		$logo = $settings->get('logo');
		self::$logo = help::url( TEMP_DIR . "/assets/logo/{$logo}" );
	}
	
	private static function slash($el) {
		return str_replace("\\", "/", $el);
	}
	
	public static function get_header() {
		global $title, $settings;
		if( defined('PANEL_DIR') && self::slash(PANEL_DIR) == self::slash(USERS_DIR) ) require TEMP_DIR . '/user-header.php';
		else require TEMP_DIR . '/header.php';
	}
	
	public static function get_footer() {
		global $settings;
		if( defined('PANEL_DIR') && self::slash(PANEL_DIR) == self::slash(USERS_DIR) ) require TEMP_DIR . '/user-footer.php';
		else require TEMP_DIR . '/footer.php';
	}
	
	public static function alert( ?string $message, $type = null, bool $dismissible = false ) {
		if( empty($message) ) return;
		require TEMP_DIR . '/alert.php';
	}
	
	public static function add_script($type, $link, $position = true) {
		if( $type == 'css' )
			$script = "<link rel='stylesheet' href='{$link}'/>";
		else $script = "<script src='{$link}'></script>";
		$position = $position ? "@header" : "@footer";
		events::addListener($position, function() use($script) {
			print_r( "{$script} \n" );
		});
	}
	
	public static function title( $content ) {
		require TEMP_DIR . '/title.php';
	}

}