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

if ( ! defined( 'ABSPATH' ) ) {
	die( '-1' );
}

/**
 * Shortcode attributes
 *
 * @var $atts
 * @var $el_class
 * @var $css
 * @var $el_id
 * @var $equal_height
 * @var $content_placement
 * @var $content - shortcode content
 * Shortcode class
 * @var WPBakeryShortCode_Vc_Row_Inner $this
 */
$el_class = $equal_height = $content_placement = $css = $el_id = '';
$disable_element = '';
$output = $after_output = '';
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
extract( $atts );

$el_class = $this->getExtraClass( $el_class );
$css_classes = [
	'vc_row',
	'wpb_row',
	// deprecated.
	'vc_inner',
	'vc_row-fluid',
	$el_class,
	vc_shortcode_custom_css_class( $css ),
];
if ( 'yes' === $disable_element ) {
	if ( vc_is_page_editable() ) {
		$css_classes[] = 'vc_hidden-lg vc_hidden-xs vc_hidden-sm vc_hidden-md';
	} else {
		return '';
	}
}

if ( vc_shortcode_custom_css_has_property( $css, [
	'border',
	'background',
] ) ) {
	$css_classes[] = 'vc_row-has-fill';
}

if ( ! empty( $atts['gap'] ) ) {
	$css_classes[] = 'vc_column-gap-' . $atts['gap'];
}

if ( ! empty( $equal_height ) ) {
	$flex_row = true;
	$css_classes[] = 'vc_row-o-equal-height';
}

if ( ! empty( $atts['rtl_reverse'] ) ) {
	$css_classes[] = 'vc_rtl-columns-reverse';
}

if ( ! empty( $content_placement ) ) {
	$flex_row = true;
	$css_classes[] = 'vc_row-o-content-' . $content_placement;
}

if ( ! empty( $flex_row ) ) {
	$css_classes[] = 'vc_row-flex';
}

$wrapper_attributes = [];
// build attributes for wrapper.
if ( ! empty( $el_id ) ) {
	$wrapper_attributes[] = 'id="' . esc_attr( $el_id ) . '"';
}

/*** TOTAL MODS START ***/
	$wrap_css = '';

	// Sticky - added here because not used in parent rows
	if ( isset( $atts['sticky'] ) && 'true' === $atts['sticky'] ) {
		$css_classes[] = 'wpex-sticky';
	}

	// Background color
	if ( ! empty( $atts['wpex_bg_color'] ) ) {
		$bg_color = sanitize_text_field( $atts['wpex_bg_color'] );
		if ( str_starts_with( $bg_color, 'type:linear-gradient' ) || str_starts_with( $bg_color, 'type:radial-gradient' ) ) {
			$bg_color_css = totaltheme_call_static( 'Helpers\Gradient_Parser', 'render_css', $bg_color );
			if ( $bg_color_css ) {
				$wrap_css .= "background:{$bg_color_css}!important;";
			}
		} else {
			$bg_color_parsed = wpex_parse_color( $bg_color );
			if ( $bg_color_parsed ) {
				$wrap_css .= "background-color:{$bg_color_parsed}!important;";
			}
		}
	}

	// Border color
	if ( ! empty( $atts['wpex_border_color'] ) && $border_color_parsed = wpex_parse_color( $atts['wpex_border_color'] ) ) {
		$wrap_css .= "border-color:{$border_color_parsed}!important;";
	}

	// Custom background image
	if ( ! empty( $atts['background_image_id'] )
		&& $background_image_url = wp_get_attachment_image_url( $atts['background_image_id'], 'full' )
	) {
		$wrap_css .= 'background-image:url(' . esc_url( $background_image_url ) . ')!important;';
	}

	// Settings that should only get added if parallax is disabled
	if ( empty( $atts['parallax'] ) ) {

		// Background position
		if ( ! empty( $atts['wpex_bg_position'] ) && $bg_position_safe = sanitize_text_field( $atts['wpex_bg_position'] ) ) {
			$wrap_css .= "background-position:{$bg_position_safe}!important;";
		}

		// Background size
		if ( ! empty( $atts['wpex_bg_size'] ) && $bg_size_safe = sanitize_text_field( $atts['wpex_bg_size'] ) ) {
			$wrap_css .= "background-size:{$bg_size_safe}!important;";
		}

	}

	// Add inline css to attributes
	if ( $wrap_css ) {
		$wrapper_attributes[] = 'style="' . esc_attr( $wrap_css ) . '"';
	}

/*** TOTAL MODS END ***/

$css_class = preg_replace( '/\s+/', ' ', apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, implode( ' ', array_filter( array_unique( $css_classes ) ) ), $this->settings['base'], $atts ) );
$wrapper_attributes[] = 'class="' . esc_attr( trim( $css_class ) ) . '"';

$output .= '<div ' . implode( ' ', $wrapper_attributes ) . '>';
	$output .= apply_filters( 'wpex_hook_vc_row_inner_top', '', $atts ); // Total Mod
	$output .= wpb_js_remove_wpautop( $content );
	$output .= apply_filters( 'wpex_hook_vc_row_inner_bottom', '', $atts ); // Total Mod
$output .= '</div>';
$output .= $after_output;

return $output;
