<?php

// Global variables


// Default SC attributes
$defaults = array(
	'color' => '',
	'text_color' => '',
	'border_color' => '',
	'bg_opacity' => '',
);
// Extract all attributes
$sc_atts = $this->extract_sc_attributes( $defaults, $atts );

// Handle the opacity number
if ( '' != $sc_atts['bg_opacity'] ) {

	if ( is_numeric( $sc_atts['bg_opacity'] ) ){
		if ( $sc_atts['bg_opacity'] > 100 ) { $sc_atts['bg_opacity'] = 100; }
		else if ( $sc_atts['bg_opacity'] < 0 ) { $sc_atts['bg_opacity'] = 0; }
		else if ( $sc_atts['bg_opacity'] > 0 && $sc_atts['bg_opacity'] < 1  ) { $sc_atts['bg_opacity'] = $sc_atts['bg_opacity'] * 100; }
	}
	else {
		$sc_atts['bg_opacity'] = '';
	}
}

// SHORTCODE BEGIN
$return = '';
$return .= '<div class="';

// CLASSES
$class = 'ish-sc_box';
$class .= ( '' != $sc_atts['css_class'] ) ? ' ' . esc_attr( $sc_atts['css_class'] ) : '' ;
$class .= ( '' != $sc_atts['color'] ) ? ' ish-' . esc_attr( $sc_atts['color'] ) : '' ;
$class .= ( '' != $sc_atts['text_color'] ) ? ' ish-text-' . esc_attr( $sc_atts['text_color'] ) : '' ;
$class .= ( '' != $sc_atts['border_color'] ) ? ' ish-border-' . esc_attr( $sc_atts['border_color'] ) : '' ;
$class .= ( '' != $sc_atts['tooltip'] && '' != $sc_atts['tooltip_color'] ) ? ' ish-tooltip-' . esc_attr( $sc_atts['tooltip_color'] ) : '';
$class .= ( '' != $sc_atts['tooltip'] && '' != $sc_atts['tooltip_text_color'] ) ? ' ish-tooltip-text-' . esc_attr( $sc_atts['tooltip_text_color'] ) : '';
$return .= apply_filters( 'ish_sc_classes', $class, $tag );
$return .= '"' ;

// ID
$return .= ( '' != $sc_atts['id'] ) ? ' id="' . esc_attr( $sc_atts['id'] ) . '"' : '';


// STYLE
if ( '' != $sc_atts['style'] || '' != $sc_atts['bg_opacity'] ){

	$return .= ' style="';

	//Remove the default BG color if row opacity set
	if ( '' != $sc_atts['bg_opacity'] && '' != $sc_atts['color'] ){
		$return .= ' background-color: transparent;';
	}

	$return .= ( '' != $sc_atts['style'] ) ? ' ' . esc_attr( $sc_atts['style'] ) : '';
	$return .= '"';
}

// TOOLTIP
$return .= ( '' != $sc_atts['tooltip'] ) ? ' data-type="tooltip" title="' . esc_attr( $sc_atts['tooltip'] ) . '"' : ''  ;
$return .= '>';

if ( ( '' != $sc_atts['bg_opacity'] ) && '' != $sc_atts['color'] ){
	$o_class =  ( '' != $sc_atts['color']) ? ( ' ish-' . $sc_atts['color'] ) : '';
	$return .= '<div class="ish-box-overlay' . $o_class . '" style="opacity: ' . ( $sc_atts['bg_opacity'] / 100 ) . ';"></div>';
}

$content = wpb_js_remove_wpautop($content, true);

// CONTENT
$return .= do_shortcode( $content );

// SHORTCODE END
$return .= '</div>';

echo $return;