<?php
/**
 * vcex_post_excerpt shortcode output.
 *
 * @package Total WordPress Theme
 * @subpackage Total Theme Core
 * @version 1.4.6
 */

defined( 'ABSPATH' ) || exit;

$atts = vcex_shortcode_atts( 'vcex_post_excerpt', $atts, 'VCEX_Post_Excerpt_Shortcode' );
$html = '';
$post = get_post( vcex_get_the_ID() );

if ( ! $post ) {
	return;
}

if ( vcex_is_template_edit_mode() ) {
	$excerpt = esc_html( 'This is a sample post excerpt for working in the frontend editor.', 'total-theme-core' );
	if ( ! empty( $atts['length'] ) ) {
		$excerpt = wp_trim_words( $excerpt, $atts['length'] );
	}
} else if ( ! empty( $atts['length'] ) ) {
	$excerpt = vcex_get_excerpt( array(
		'length'  => $atts['length'],
		'context' => 'vcex_post_excerpt',
		'post_id' => vcex_get_the_ID(),
	) );
} else {
	$excerpt = get_the_excerpt( $post );
}

if ( empty( $excerpt ) ) {
	return;
}

$shortcode_class = array(
	'vcex-module',
	'vcex-post-excerpt',
	'wpex-last-mb-0',
);

// Custom user classes.
$extra_classes = vcex_get_shortcode_extra_classes( $atts, 'vcex_post_excerpt' );

if ( $extra_classes ) {
	$shortcode_class = array_merge( $shortcode_class, $extra_classes );
}

// Filters shortcode classes.
$shortcode_class = vcex_parse_shortcode_classes( $shortcode_class, 'vcex_post_excerpt', $atts );

// Inline styles.
$shortcode_style = vcex_inline_style( array(
	'color'              => $atts['color'] ?? null,
	'font_family'        => $atts['font_family'] ?? null,
	'font_size'          => $atts['font_size'] ?? null,
	'line_height'        => $atts['line_height'] ?? null,
	'font_weight'        => $atts['font_weight'] ?? null,
	'text_transform'     => $atts['text_transform'] ?? null,
	'letter_spacing'     => $atts['letter_spacing'] ?? null,
	'animation_delay'    => $atts['animation_delay'] ?? null,
	'animation_duration' => $atts['animation_duration'] ?? null,
), true );

// Begin output.
$html .= '<div class="' . esc_attr( trim( $shortcode_class ) ) . '"' . $shortcode_style . '>';

	$html .= wpautop( wp_kses_post( $excerpt ) );

$html .= '</div>';

// @codingStandardsIgnoreLine
echo $html;