<?php
extract(shortcode_atts(array(
    'visibility'      => 'all',
    'class'           => '',
    'id'              => '',
    'custom_style'    => '',
    'title'           => '',
    'type'            => 'info',
    'dismissible'     => '',
    'icon_type'       => '',
    'color'       => '',
), $atts));

$class            = ( $class         != ''    ) ? 'vc_message_box noo-message alert ' . esc_attr( $class ) : 'vc_message_box noo-message alert';
$class           .= " alert-{$type}";
$class           .= ( $dismissible   == 'true') ? ' alert-dimissible' : '';
$visibility       = ( $visibility    != ''    ) && ( $visibility != 'all' ) ? esc_attr( $visibility ) : '';
$class           .= noo_visibility_class( $visibility );

$id           = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
$class        = ( $class != '' ) ? 'class="' . $class . '"' : '';
$custom_style = ( $custom_style    != ''     ) ? ' style="' . $custom_style . '"' : '';


$defaultIconClass = 'fa fa-adjust';

// Pick up icons
$iconClass = isset( ${'icon_' . $icon_type} ) ? ${'icon_' . $icon_type} : $defaultIconClass;
switch ( $color ) {
	case 'info':
		$icon_type = 'fontawesome';
		$iconClass = 'fa fa-info-circle';
		break;
	case 'alert-info':
		$icon_type = 'pixelicons';
		$iconClass = 'vc_pixel_icon vc_pixel_icon-info';
		break;
	case 'success':
		$icon_type = 'fontawesome';
		$iconClass = 'fa fa-check';
		break;
	case 'alert-success':
		$icon_type = 'pixelicons';
		$iconClass = 'vc_pixel_icon vc_pixel_icon-tick';
		break;
	case 'warning':
		$icon_type = 'fontawesome';
		$iconClass = 'fa fa-exclamation-triangle';
		break;
	case 'alert-warning':
		$icon_type = 'pixelicons';
		$iconClass = 'vc_pixel_icon vc_pixel_icon-alert';
		break;
	case 'danger':
		$icon_type = 'fontawesome';
		$iconClass = 'fa fa-times';
		break;
	case 'alert-danger':
		$icon_type = 'pixelicons';
		$iconClass = 'vc_pixel_icon vc_pixel_icon-explanation';
		break;
	case 'alert-custom':
	default:
		break;
}

// Enqueue needed font for icon element
if ( 'pixelicons' !== $icon_type ) {
	vc_icon_element_fonts_enqueue( $icon_type );
}

$html   = array();
$html[] = "<div {$id} {$class} {$custom_style} role=\"alert\">";
$html[] = "<div class=\"vc_message_box-icon\">";
$html[] = "<i class=\"". esc_attr( $iconClass ) . "\"></i>";
$html[] = "</div>";
$html[] = "<div class=\"noo-content-message\">";
if( $dismissible == 'true' ) {
	$html[] = '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">' . __( 'Close', 'noo' ) . '</span></button>';
}
if( $title != '' ) {
	$html[] = '  <h4>' . esc_attr( $title ) . '</h4>';
}

$html[] = noo_handler_shortcode_content( $content, true );
$html[] = "</div>";
$html[] = "</div>";

echo implode( "\n", $html );
