<?php
/**
 * The template for displaying [vc_message] shortcode output of 'Message box' element.
 *
 * This template can be overridden by copying it to yourtheme/vc_templates/vc_message.php.
 *
 * @version 9.0
 *
 * @see https://kb.wpbakery.com/docs/developers-how-tos/change-shortcodes-html-output
 */

if ( ! defined( 'ABSPATH' ) ) {
	die( '-1' );
}
/**
 * Shortcode attributes
 *
 * @todo add $icon_... defaults
 * @todo add $icon_typicons and etc
 *
 * @var array $atts
 * @var string $el_class
 * @var string $el_id
 * @var string $message_box_style
 * @var string $style
 * @var string $color
 * @var string $message_box_color
 * @var string $css_animation
 * @var string $icon_type
 * @var string $icon_fontawesome
 * @var string $content - shortcode content
 * @var string $css
 * Shortcode class
 * @var WPBakeryShortCode_Vc_Message $this
 */
$el_class = $el_id = $message_box_color = $message_box_style = $style = $css = $color = $css_animation = $icon_type = '';
$icon_fontawesome = $icon_linecons = $icon_openiconic = $icon_typicons = $icon_entypo = $icon_monosocial = $icon_material = $icon_pixelicons = '';
$default_icon_class = 'fa fa-adjust';
$atts = $this->convertAttributesToMessageBox2( $atts );
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
extract( $atts );

$color_class = '';
$hex_color_style = '';
if ( strlen( $color ) > 0 ) {
	$color_class = 'vc_color-' . $color;
} elseif ( strlen( $message_box_color ) > 0 ) {
	$color_class = $this->resolveColorClass( $message_box_color );
	$hex_color_style = $this->buildHexColorStyle( $message_box_color );
} else {
	$color_class = 'vc_color-info';
}

$settings = $this->getSettings();
$element_class_list = [
	'base' => apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'vc_message_box', $settings['base'], $atts ),
	'style' => 'vc_message_box-' . $message_box_style,
	'shape' => 'vc_message_box-' . $style,
	'color' => $color_class,
	'css_animation' => $this->getCSSAnimation( $css_animation ),
];

$element_class = empty( $settings['element_default_class'] ) ? '' : $settings['element_default_class'];
$class_to_filter = preg_replace( [
	'/\s+/',
	'/^\s|\s$/',
], [
	' ',
	'',
], implode( ' ', $element_class_list ) );
$class_to_filter .= vc_shortcode_custom_css_class( $css, ' ' ) . ' ' . esc_attr( $element_class ) . $this->getExtraClass( $el_class );
$css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $class_to_filter, $settings['base'], $atts );

// Pick up icons.
$icon_class = isset( ${'icon_' . $icon_type} ) ? ${'icon_' . $icon_type} : $default_icon_class;
switch ( $color ) {
	case 'info':
		$icon_type = 'fontawesome';
		$icon_class = 'fas fa-info-circle';
		break;
	case 'alert-info':
		$icon_type = 'pixelicons';
		$icon_class = 'vc_pixel_icon vc_pixel_icon-info';
		break;
	case 'success':
		$icon_type = 'fontawesome';
		$icon_class = 'fas fa-check';
		break;
	case 'alert-success':
		$icon_type = 'pixelicons';
		$icon_class = 'vc_pixel_icon vc_pixel_icon-tick';
		break;
	case 'warning':
		$icon_type = 'fontawesome';
		$icon_class = 'fas fa-exclamation-triangle';
		break;
	case 'alert-warning':
		$icon_type = 'pixelicons';
		$icon_class = 'vc_pixel_icon vc_pixel_icon-alert';
		break;
	case 'danger':
		$icon_type = 'fontawesome';
		$icon_class = 'fas fa-times';
		break;
	case 'alert-danger':
		$icon_type = 'pixelicons';
		$icon_class = '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 );
}
$wrapper_attributes = [];
if ( ! empty( $el_id ) ) {
	$wrapper_attributes[] = 'id="' . esc_attr( $el_id ) . '"';
}
$output = $hex_color_style;
$output .= '<div class="' . esc_attr( $css_class ) . '" ' . implode( ' ', $wrapper_attributes ) . '><div class="vc_message_box-icon"><i class="' . esc_attr( $icon_class ) . '"></i></div>' . wpb_js_remove_wpautop( $content, true ) . '</div>';

return $output;
