//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

abstract class chatbox_hook_loadJSandCSS extends _HOOK_CLASS_
{

	public static function baseCss()
	{
		try
		{
			parent::baseCss();
				
			\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'main.css', 'chatbox', 'front' ) );
			\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'skins.css', 'chatbox', 'front' ) );
		}
		catch ( \Error | \RuntimeException $e )
		{
			if ( method_exists( get_parent_class(), __FUNCTION__ ) )
			{
				return \call_user_func_array( 'parent::' . __FUNCTION__, \func_get_args() );
			}
			else
			{
				throw $e;
			}
		}
	}
	
	protected static function baseJs()
	{
		try
		{
			parent::baseJS();
			
			if ( \IPS\Dispatcher::i()->controllerLocation != 'admin' )
			{
				\IPS\Output::i()->jsVars['chatbox_member_name'] 		= \IPS\Member::loggedIn()->member_id > 0 ? \IPS\Member::loggedIn()->name : \IPS\Request::i()->cookie[ 'chatbox_guestName' ];
				\IPS\Output::i()->jsVars['chatbox_popup_height'] 		= 480;
				\IPS\Output::i()->jsVars['chatbox_bar_full'] 			= \IPS\Settings::i()->chatbox_bar_full;
				\IPS\Output::i()->jsVars['chatbox_bar_mini'] 			= \IPS\Settings::i()->chatbox_bar_mini_devices;
				\IPS\Output::i()->jsVars['chatbox_bar_pos'] 			= \IPS\Settings::i()->chatbox_bar_pos;
				\IPS\Output::i()->jsVars['chatbox_force_scroll_down'] 	= \IPS\Settings::i()->chatbox_force_scroll_down;
				\IPS\Output::i()->jsVars['chatbox_tabCount'] 			= \IPS\Settings::i()->chatbox_tabCount == 1 && ( \IPS\Request::i()->do != "initialMfa" || \IPS\Request::i()->_mfaLogin > 0 ) ? \IPS\chatbox\Rooms\Room::onlineInRooms() : -1;		
				\IPS\Output::i()->jsVars['chatbox_no_disconnect'] 		= \IPS\Settings::i()->chatbox_no_disconnect;		
				\IPS\Output::i()->jsVars['chatbox_timeago'] 			= \IPS\Settings::i()->chatbox_time_moment;		
				\IPS\Output::i()->jsVars['chatbox_no_emoji'] 			= \IPS\Settings::i()->chatbox_noEmoji;
				\IPS\Output::i()->jsVars['chatbox_version'] 			= \IPS\Application::load('chatbox')->version;
	
				if ( ! \IPS\Request::i()->isAjax() )
				{
					\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'jquery/jquery-ui.js', 'core', 'interface' ) );			
					\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_chatbox.js', 'chatbox', 'front' ) );				
				}
			}
		}
		catch ( \Error | \RuntimeException $e )
		{
			if ( method_exists( get_parent_class(), __FUNCTION__ ) )
			{
				return \call_user_func_array( 'parent::' . __FUNCTION__, \func_get_args() );
			}
			else
			{
				throw $e;
			}
		}
	}

	
}
