<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_toggles_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_toggles_theme_setup' );
	function seohub_sc_toggles_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_toggles_reg_shortcodes');
		if (function_exists('seohub_exists_visual_composer') && seohub_exists_visual_composer())
			add_action('seohub_action_shortcodes_list_vc','seohub_sc_toggles_reg_shortcodes_vc');
	}
}



/* Shortcode implementation
-------------------------------------------------------------------- */

if (!function_exists('seohub_sc_toggles')) {	
	function seohub_sc_toggles($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"counter" => "off",
			"icon_closed" => "icon-plus",
			"icon_opened" => "icon-minus",
			// Common params
			"id" => "",
			"class" => "",
			"animation" => "",
			"css" => "",
			"top" => "",
			"bottom" => "",
			"left" => "",
			"right" => ""
		), $atts)));
		$class .= ($class ? ' ' : '') . seohub_get_css_position_as_classes($top, $right, $bottom, $left);
		global $SEOHUB_GLOBALS;
		$SEOHUB_GLOBALS['sc_toggle_counter'] = 0;
		$SEOHUB_GLOBALS['sc_toggle_show_counter'] = seohub_param_is_on($counter);
		$SEOHUB_GLOBALS['sc_toggles_icon_closed'] = empty($icon_closed) || seohub_param_is_inherit($icon_closed) ? "icon-plus" : $icon_closed;
		$SEOHUB_GLOBALS['sc_toggles_icon_opened'] = empty($icon_opened) || seohub_param_is_inherit($icon_opened) ? "icon-minus" : $icon_opened;
		seohub_enqueue_script('jquery-effects-slide', false, array('jquery','jquery-effects-core'), null, true);
		$output = '<div' . ($id ? ' id="'.esc_attr($id).'"' : '') 
				. ' class="sc_toggles'
					. (!empty($class) ? ' '.esc_attr($class) : '')
					. (seohub_param_is_on($counter) ? ' sc_show_counter' : '') 
					. '"'
				. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
				. ($css!='' ? ' style="'.esc_attr($css).'"' : '') 
				. '>'
				. do_shortcode($content)
				. '</div>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_toggles', $atts, $content);
	}
	seohub_require_shortcode('trx_toggles', 'seohub_sc_toggles');
}


if (!function_exists('seohub_sc_toggles_item')) {	
	function seohub_sc_toggles_item($atts, $content=null) {
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts( array(
			// Individual params
			"title" => "",
			"open" => "",
			"icon_closed" => "",
			"icon_opened" => "",
			// Common params
			"id" => "",
			"class" => "",
			"css" => ""
		), $atts)));
		global $SEOHUB_GLOBALS;
		$SEOHUB_GLOBALS['sc_toggle_counter']++;
		if (empty($icon_closed) || seohub_param_is_inherit($icon_closed)) $icon_closed = $SEOHUB_GLOBALS['sc_toggles_icon_closed'] ? $SEOHUB_GLOBALS['sc_toggles_icon_closed'] : "icon-plus";
		if (empty($icon_opened) || seohub_param_is_inherit($icon_opened)) $icon_opened = $SEOHUB_GLOBALS['sc_toggles_icon_opened'] ? $SEOHUB_GLOBALS['sc_toggles_icon_opened'] : "icon-minus";
		$css .= seohub_param_is_on($open) ? 'display:block;' : '';
		$output = '<div' . ($id ? ' id="'.esc_attr($id).'"' : '') 
					. ' class="sc_toggles_item'.(seohub_param_is_on($open) ? ' sc_active' : '')
					. (!empty($class) ? ' '.esc_attr($class) : '')
					. ($SEOHUB_GLOBALS['sc_toggle_counter'] % 2 == 1 ? ' odd' : ' even') 
					. ($SEOHUB_GLOBALS['sc_toggle_counter'] == 1 ? ' first' : '')
					. '">'
					. '<h5 class="sc_toggles_title'.(seohub_param_is_on($open) ? ' ui-state-active' : '').'">'
					. (!seohub_param_is_off($icon_closed) ? '<span class="sc_toggles_icon sc_toggles_icon_closed '.esc_attr($icon_closed).'"></span>' : '')
					. (!seohub_param_is_off($icon_opened) ? '<span class="sc_toggles_icon sc_toggles_icon_opened '.esc_attr($icon_opened).'"></span>' : '')
					. ($SEOHUB_GLOBALS['sc_toggle_show_counter'] ? '<span class="sc_items_counter">'.($SEOHUB_GLOBALS['sc_toggle_counter']).'</span>' : '')
					. ($title) 
					. '</h5>'
					. '<div class="sc_toggles_content"'
						. ($css!='' ? ' style="'.esc_attr($css).'"' : '') 
						.'>' 
						. do_shortcode($content) 
					. '</div>'
				. '</div>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_toggles_item', $atts, $content);
	}
	seohub_require_shortcode('trx_toggles_item', 'seohub_sc_toggles_item');
}


/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_toggles_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_toggles_reg_shortcodes');
	function seohub_sc_toggles_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_toggles"] = array(
			"title" => esc_html__("Toggles", "seohub"),
			"desc" => wp_kses( __("Toggles items", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => true,
			"container" => false,
			"params" => array(
				"counter" => array(
					"title" => esc_html__("Counter", "seohub"),
					"desc" => wp_kses( __("Display counter before each toggles title", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "off",
					"type" => "switch",
					"options" => $SEOHUB_GLOBALS['sc_params']['on_off']
				),
				"icon_closed" => array(
					"title" => esc_html__("Icon while closed",  'seohub'),
					"desc" => wp_kses( __('Select icon for the closed toggles item from Fontello icons set',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "icons",
					"options" => $SEOHUB_GLOBALS['sc_params']['icons']
				),
				"icon_opened" => array(
					"title" => esc_html__("Icon while opened",  'seohub'),
					"desc" => wp_kses( __('Select icon for the opened toggles item from Fontello icons set',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "icons",
					"options" => $SEOHUB_GLOBALS['sc_params']['icons']
				),
				"top" => $SEOHUB_GLOBALS['sc_params']['top'],
				"bottom" => $SEOHUB_GLOBALS['sc_params']['bottom'],
				"left" => $SEOHUB_GLOBALS['sc_params']['left'],
				"right" => $SEOHUB_GLOBALS['sc_params']['right'],
				"id" => $SEOHUB_GLOBALS['sc_params']['id'],
				"class" => $SEOHUB_GLOBALS['sc_params']['class'],
				"animation" => $SEOHUB_GLOBALS['sc_params']['animation'],
				"css" => $SEOHUB_GLOBALS['sc_params']['css']
			),
			"children" => array(
				"name" => "trx_toggles_item",
				"title" => esc_html__("Toggles item", "seohub"),
				"desc" => wp_kses( __("Toggles item", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
				"container" => true,
				"params" => array(
					"title" => array(
						"title" => esc_html__("Toggles item title", "seohub"),
						"desc" => wp_kses( __("Title for current toggles item", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "text"
					),
					"open" => array(
						"title" => esc_html__("Open on show", "seohub"),
						"desc" => wp_kses( __("Open current toggles item on show", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "no",
						"type" => "switch",
						"options" => $SEOHUB_GLOBALS['sc_params']['yes_no']
					),
					"icon_closed" => array(
						"title" => esc_html__("Icon while closed",  'seohub'),
						"desc" => wp_kses( __('Select icon for the closed toggles item from Fontello icons set',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "icons",
						"options" => $SEOHUB_GLOBALS['sc_params']['icons']
					),
					"icon_opened" => array(
						"title" => esc_html__("Icon while opened",  'seohub'),
						"desc" => wp_kses( __('Select icon for the opened toggles item from Fontello icons set',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "icons",
						"options" => $SEOHUB_GLOBALS['sc_params']['icons']
					),
					"_content_" => array(
						"title" => esc_html__("Toggles item content", "seohub"),
						"desc" => wp_kses( __("Current toggles item content", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"rows" => 4,
						"value" => "",
						"type" => "textarea"
					),
					"id" => $SEOHUB_GLOBALS['sc_params']['id'],
					"class" => $SEOHUB_GLOBALS['sc_params']['class'],
					"css" => $SEOHUB_GLOBALS['sc_params']['css']
				)
			)
		);
	}
}


/* Add shortcode in the VC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_toggles_reg_shortcodes_vc' ) ) {
	//add_action('seohub_action_shortcodes_list_vc', 'seohub_sc_toggles_reg_shortcodes_vc');
	function seohub_sc_toggles_reg_shortcodes_vc() {
		global $SEOHUB_GLOBALS;
	
		vc_map( array(
			"base" => "trx_toggles",
			"name" => esc_html__("Toggles", "seohub"),
			"description" => wp_kses( __("Toggles items", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"category" => esc_html__('Content', 'js_composer'),
			'icon' => 'icon_trx_toggles',
			"class" => "trx_sc_collection trx_sc_toggles",
			"content_element" => true,
			"is_container" => true,
			"show_settings_on_create" => false,
			"as_parent" => array('only' => 'trx_toggles_item'),
			"params" => array(
				array(
					"param_name" => "counter",
					"heading" => esc_html__("Counter", "seohub"),
					"description" => wp_kses( __("Display counter before each toggles title", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array("Add item numbers before each element" => "on" ),
					"type" => "checkbox"
				),
				array(
					"param_name" => "icon_closed",
					"heading" => esc_html__("Icon while closed", "seohub"),
					"description" => wp_kses( __("Select icon for the closed toggles item from Fontello icons set", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				array(
					"param_name" => "icon_opened",
					"heading" => esc_html__("Icon while opened", "seohub"),
					"description" => wp_kses( __("Select icon for the opened toggles item from Fontello icons set", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				$SEOHUB_GLOBALS['vc_params']['id'],
				$SEOHUB_GLOBALS['vc_params']['class'],
				$SEOHUB_GLOBALS['vc_params']['margin_top'],
				$SEOHUB_GLOBALS['vc_params']['margin_bottom'],
				$SEOHUB_GLOBALS['vc_params']['margin_left'],
				$SEOHUB_GLOBALS['vc_params']['margin_right']
			),
			'default_content' => '
				[trx_toggles_item title="' . esc_html__( 'Item 1 title', 'seohub' ) . '"][/trx_toggles_item]
				[trx_toggles_item title="' . esc_html__( 'Item 2 title', 'seohub' ) . '"][/trx_toggles_item]
			',
			"custom_markup" => '
				<div class="wpb_accordion_holder wpb_holder clearfix vc_container_for_children">
					%content%
				</div>
				<div class="tab_controls">
					<button class="add_tab" title="'.esc_attr__("Add item", "seohub").'">'.esc_html__("Add item", "seohub").'</button>
				</div>
			',
			'js_view' => 'VcTrxTogglesView'
		) );
		
		
		vc_map( array(
			"base" => "trx_toggles_item",
			"name" => esc_html__("Toggles item", "seohub"),
			"description" => wp_kses( __("Single toggles item", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"show_settings_on_create" => true,
			"content_element" => true,
			"is_container" => true,
			'icon' => 'icon_trx_toggles_item',
			"as_child" => array('only' => 'trx_toggles'),
			"as_parent" => array('except' => 'trx_toggles'),
			"params" => array(
				array(
					"param_name" => "title",
					"heading" => esc_html__("Title", "seohub"),
					"description" => wp_kses( __("Title for current toggles item", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "open",
					"heading" => esc_html__("Open on show", "seohub"),
					"description" => wp_kses( __("Open current toggle item on show", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array("Opened" => "yes" ),
					"type" => "checkbox"
				),
				array(
					"param_name" => "icon_closed",
					"heading" => esc_html__("Icon while closed", "seohub"),
					"description" => wp_kses( __("Select icon for the closed toggles item from Fontello icons set", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				array(
					"param_name" => "icon_opened",
					"heading" => esc_html__("Icon while opened", "seohub"),
					"description" => wp_kses( __("Select icon for the opened toggles item from Fontello icons set", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				$SEOHUB_GLOBALS['vc_params']['id'],
				$SEOHUB_GLOBALS['vc_params']['class'],
				$SEOHUB_GLOBALS['vc_params']['css']
			),
			'js_view' => 'VcTrxTogglesTabView'
		) );
		class WPBakeryShortCode_Trx_Toggles extends SEOHUB_VC_ShortCodeToggles {}
		class WPBakeryShortCode_Trx_Toggles_Item extends SEOHUB_VC_ShortCodeTogglesItem {}
	}
}
?>