<?php
$pantry_woocommerce_sc = pantry_get_theme_option( 'front_page_woocommerce_products' );
if ( ! empty( $pantry_woocommerce_sc ) ) {
	?><div class="front_page_section front_page_section_woocommerce<?php
		$pantry_scheme = pantry_get_theme_option( 'front_page_woocommerce_scheme' );
		if ( ! empty( $pantry_scheme ) && ! pantry_is_inherit( $pantry_scheme ) ) {
			echo ' scheme_' . esc_attr( $pantry_scheme );
		}
		echo ' front_page_section_paddings_' . esc_attr( pantry_get_theme_option( 'front_page_woocommerce_paddings' ) );
		if ( pantry_get_theme_option( 'front_page_woocommerce_stack' ) ) {
			echo ' sc_stack_section_on';
		}
	?>"
			<?php
			$pantry_css      = '';
			$pantry_bg_image = pantry_get_theme_option( 'front_page_woocommerce_bg_image' );
			if ( ! empty( $pantry_bg_image ) ) {
				$pantry_css .= 'background-image: url(' . esc_url( pantry_get_attachment_url( $pantry_bg_image ) ) . ');';
			}
			if ( ! empty( $pantry_css ) ) {
				echo ' style="' . esc_attr( $pantry_css ) . '"';
			}
			?>
	>
	<?php
		// Add anchor
		$pantry_anchor_icon = pantry_get_theme_option( 'front_page_woocommerce_anchor_icon' );
		$pantry_anchor_text = pantry_get_theme_option( 'front_page_woocommerce_anchor_text' );
		if ( ( ! empty( $pantry_anchor_icon ) || ! empty( $pantry_anchor_text ) ) && shortcode_exists( 'trx_sc_anchor' ) ) {
			echo do_shortcode(
				'[trx_sc_anchor id="front_page_section_woocommerce"'
											. ( ! empty( $pantry_anchor_icon ) ? ' icon="' . esc_attr( $pantry_anchor_icon ) . '"' : '' )
											. ( ! empty( $pantry_anchor_text ) ? ' title="' . esc_attr( $pantry_anchor_text ) . '"' : '' )
											. ']'
			);
		}
	?>
		<div class="front_page_section_inner front_page_section_woocommerce_inner
			<?php
			if ( pantry_get_theme_option( 'front_page_woocommerce_fullheight' ) ) {
				echo ' pantry-full-height sc_layouts_flex sc_layouts_columns_middle';
			}
			?>
				"
				<?php
				$pantry_css      = '';
				$pantry_bg_mask  = pantry_get_theme_option( 'front_page_woocommerce_bg_mask' );
				$pantry_bg_color_type = pantry_get_theme_option( 'front_page_woocommerce_bg_color_type' );
				if ( 'custom' == $pantry_bg_color_type ) {
					$pantry_bg_color = pantry_get_theme_option( 'front_page_woocommerce_bg_color' );
				} elseif ( 'scheme_bg_color' == $pantry_bg_color_type ) {
					$pantry_bg_color = pantry_get_scheme_color( 'bg_color', $pantry_scheme );
				} else {
					$pantry_bg_color = '';
				}
				if ( ! empty( $pantry_bg_color ) && $pantry_bg_mask > 0 ) {
					$pantry_css .= 'background-color: ' . esc_attr(
						1 == $pantry_bg_mask ? $pantry_bg_color : pantry_hex2rgba( $pantry_bg_color, $pantry_bg_mask )
					) . ';';
				}
				if ( ! empty( $pantry_css ) ) {
					echo ' style="' . esc_attr( $pantry_css ) . '"';
				}
				?>
		>
			<div class="front_page_section_content_wrap front_page_section_woocommerce_content_wrap content_wrap woocommerce">
				<?php
				// Content wrap with title and description
				$pantry_caption     = pantry_get_theme_option( 'front_page_woocommerce_caption' );
				$pantry_description = pantry_get_theme_option( 'front_page_woocommerce_description' );
				if ( ! empty( $pantry_caption ) || ! empty( $pantry_description ) || ( current_user_can( 'edit_theme_options' ) && is_customize_preview() ) ) {
					// Caption
					if ( ! empty( $pantry_caption ) || ( current_user_can( 'edit_theme_options' ) && is_customize_preview() ) ) {
						?>
						<h2 class="front_page_section_caption front_page_section_woocommerce_caption front_page_block_<?php echo ! empty( $pantry_caption ) ? 'filled' : 'empty'; ?>">
						<?php
							echo wp_kses( $pantry_caption, 'pantry_kses_content' );
						?>
						</h2>
						<?php
					}

					// Description (text)
					if ( ! empty( $pantry_description ) || ( current_user_can( 'edit_theme_options' ) && is_customize_preview() ) ) {
						?>
						<div class="front_page_section_description front_page_section_woocommerce_description front_page_block_<?php echo ! empty( $pantry_description ) ? 'filled' : 'empty'; ?>">
						<?php
							echo wp_kses( wpautop( $pantry_description ), 'pantry_kses_content' );
						?>
						</div>
						<?php
					}
				}

				// Content (widgets)
				?>
				<div class="front_page_section_output front_page_section_woocommerce_output list_products shop_mode_thumbs">
					<?php
					if ( 'products' == $pantry_woocommerce_sc ) {
						$pantry_woocommerce_sc_ids      = pantry_get_theme_option( 'front_page_woocommerce_products_per_page' );
						$pantry_woocommerce_sc_per_page = count( explode( ',', $pantry_woocommerce_sc_ids ) );
					} else {
						$pantry_woocommerce_sc_per_page = max( 1, (int) pantry_get_theme_option( 'front_page_woocommerce_products_per_page' ) );
					}
					$pantry_woocommerce_sc_columns = max( 1, min( $pantry_woocommerce_sc_per_page, (int) pantry_get_theme_option( 'front_page_woocommerce_products_columns' ) ) );
					echo do_shortcode(
						"[{$pantry_woocommerce_sc}"
										. ( 'products' == $pantry_woocommerce_sc
												? ' ids="' . esc_attr( $pantry_woocommerce_sc_ids ) . '"'
												: '' )
										. ( 'product_category' == $pantry_woocommerce_sc
												? ' category="' . esc_attr( pantry_get_theme_option( 'front_page_woocommerce_products_categories' ) ) . '"'
												: '' )
										. ( 'best_selling_products' != $pantry_woocommerce_sc
												? ' orderby="' . esc_attr( pantry_get_theme_option( 'front_page_woocommerce_products_orderby' ) ) . '"'
													. ' order="' . esc_attr( pantry_get_theme_option( 'front_page_woocommerce_products_order' ) ) . '"'
												: '' )
										. ' per_page="' . esc_attr( $pantry_woocommerce_sc_per_page ) . '"'
										. ' columns="' . esc_attr( $pantry_woocommerce_sc_columns ) . '"'
						. ']'
					);
					?>
				</div>
			</div>
		</div>
	</div>
	<?php
}
