<?php 

/**
 * Wise Chat admin advanced settings tab class.
 *
 * @author Kainex <contact@kaine.pl>
 */
class WiseChatAdvancedTab extends WiseChatAbstractTab {

	public function getFields() {
		return array(
			array('_section', 'Advanced Settings'),
			array(
				'ajax_engine', 'AJAX Engine', 'selectCallback', 'string', 
				"Engine for AJAX requests generated by the chat. <br />The Default engine is the most compatible but it has a poor performance. The Lightweight AJAX and Ultra Lightweight AJAX engines are a lot faster and consume less CPU, however, it is slightly possible that they could be unstable in future versions of WordPress.",
				WiseChatAdvancedTab::getAllEngines()
			),
			array(
				'messages_refresh_time', 'Refresh Time', 'selectCallback', 'string', 
				"Determines how often the chat should check for new messages. Lower value means higher CPU usage and more HTTP requests.", 
				WiseChatAdvancedTab::getRefreshTimes()
			),
			array('enabled_debug', 'Enable Debug Mode', 'booleanFieldCallback', 'boolean', "Displays extended error log. It is useful when reporting issues."),
			array('enabled_errors', 'Enable Errors Reporting', 'booleanFieldCallback', 'boolean', "Determines if all run-time errors should be displayed to chat users. It is useful when detecting issues."),
			array(
				'ajax_validity_time', 'AJAX Validity Time', 'stringFieldCallback', 'integer',
				'Determines how many minutes AJAX requests are considered as valid. It is useful to prevent indexing internal API calls by search engines and Web crawlers.<br />
				<strong>Warning:</strong> Too low value may cause errors on mobile devices. The default value is: 1 day (1440 minutes). '
			),
			array(
				'enabled_xhr_check', 'Enable XHR Request Check', 'booleanFieldCallback', 'boolean',
				'Enabled check for "X-Requested-With" header in AJAX requests'
			),
		);
	}
	
	public function getDefaultValues() {
		return array(
			'ajax_engine' => 'ultralightweight',
			'messages_refresh_time' => 3000,
			'enabled_debug' => 0,
			'enabled_errors' => 0,
			'ajax_validity_time' => 1440,
			'enabled_xhr_check' => 1,
		);
	}
	
	public static function getAllEngines() {
		return array(
			'' => 'Default',
			'lightweight' => 'Lightweight AJAX',
			'ultralightweight' => 'Ultra Lightweight AJAX'
		);
	}
	
	public static function getRefreshTimes() {
		return array(
			1000 => '1s',
			2000 => '2s',
			3000 => '3s',
			4000 => '4s',
			5000 => '5s',
			10000 => '10s',
			15000 => '15s',
			20000 => '20s',
			30000 => '30s',
			60000 => '60s',
			120000 => '120s',
		);
	}
}