<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_hide_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_hide_theme_setup' );
	function seohub_sc_hide_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_hide_reg_shortcodes');
	}
}



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

/*
[trx_hide selector="unique_id"]
*/

if (!function_exists('seohub_sc_hide')) {	
	function seohub_sc_hide($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"selector" => "",
			"hide" => "on",
			"delay" => 0
		), $atts)));
		$selector = trim(chop($selector));
		$output = $selector == '' ? '' : 
			'<script type="text/javascript">
				jQuery(document).ready(function() {
					'.($delay>0 ? 'setTimeout(function() {' : '').'
					jQuery("'.esc_attr($selector).'").' . ($hide=='on' ? 'hide' : 'show') . '();
					'.($delay>0 ? '},'.($delay).');' : '').'
				});
			</script>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_hide', $atts, $content);
	}
	seohub_require_shortcode('trx_hide', 'seohub_sc_hide');
}



/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_hide_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_hide_reg_shortcodes');
	function seohub_sc_hide_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_hide"] = array(
			"title" => esc_html__("Hide/Show any block", "seohub"),
			"desc" => wp_kses( __("Hide or Show any block with desired CSS-selector", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => false,
			"container" => false,
			"params" => array(
				"selector" => array(
					"title" => esc_html__("Selector", "seohub"),
					"desc" => wp_kses( __("Any block's CSS-selector", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"hide" => array(
					"title" => esc_html__("Hide or Show", "seohub"),
					"desc" => wp_kses( __("New state for the block: hide or show", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "yes",
					"size" => "small",
					"options" => $SEOHUB_GLOBALS['sc_params']['yes_no'],
					"type" => "switch"
				)
			)
		);
	}
}
?>