<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $wpcb_step_count;

$wpcb_totals_class = '';
if ( wpcb_get_option( 'wpcb_border_style' ) ) {
	$wpcb_totals_class .= ' wpcb-border-' . wpcb_get_option( 'wpcb_border_style' );
}
if ($wpcb_step_count > 1) {
	$wpcb_totals_class .= ' wpcb-has-step-nav';
}
if ( 'sticky' === get_post_meta( $wpcb_configuration_id, '_totals_position', true ) ) {
	$wpcb_totals_class .= ' wpcb-sticky';
}

do_action( 'wpcb_before_configuration_form_totals' );

if ( wpcb_get_option( 'wpcb_enable_option_summary_inline' ) ) {
	include WPCB_BASE . 'public/blocks/form-summary.php';
}

include WPCB_BASE . 'public/blocks/form-price-table.php';
?>

<div class="wpcb-configurator-form-totals<?php echo esc_attr( $wpcb_totals_class ); ?>"<?php echo ' data-wpcb-id="' . esc_attr( $wpcb_configuration_id ) . '"'; ?>>

	<?php
	include WPCB_BASE . 'public/blocks/form-price.php';

	$button_action = get_post_meta( $wpcb_configuration_id, '_button_action', true );
	$button_alt_action = get_post_meta( $wpcb_configuration_id, '_button_alt_action', true );
	$has_review_page = 'yes' === get_post_meta( $wpcb_configuration_id, '_totals_review_page', true );
	$is_review_page = ( isset( $_GET['wpcb_result'] ) && $_GET['wpcb_result'] );

	if ( ! isset( $wpcb_step_count ) ) {
		$wpcb_step_count = 0;
	}

	if ( '' !== $button_action ) :
		echo '<div class="wpcb-configurator-form-totals-actions ' . esc_attr( $button_action ) . ' ' . esc_attr( $button_alt_action ) . '">';
	
		if ( $wpcb_step_count > 0 && function_exists( 'wpcb_configurator_form_step_buttons' ) ) :
			wpcb_configurator_form_step_buttons();
		endif;

		/**
		 * Show action.
		 */
		echo '<div class="wpcb-configurator-form-add-to-cart"';
		if ( function_exists('wpcb_display_total_price_attributes') ) {
			wpcb_display_total_price_attributes( $wpcb_configuration_id );
		}
		echo '>';
		
		include 'form-button.php';

		$wpcb_configuration_alt_action = get_post_meta( $wpcb_configuration_id, '_button_alt_action', true );
		if ( $wpcb_configuration_alt_action ) {
			include 'form-button-alt.php';
		}

		echo '</div>';
		echo '</div>';
	endif;
	?>

</div>

<?php
$panel_label = wpcb_get_option( 'wpcb_summary_panel_label', $suffix ) ?: __( 'Your configuration', 'wcb-configurator-builder' );
$panel_args = array(
	'description' => '<div class="wpcb-configurator-price-table" data-wpcb-id="' . $wpcb_configuration_id . '"></div>',
	'id' => 'wpcb-configurator-price-details-' . $wpcb_configuration_id,
);
wpcb_display_panel_html_safe( $panel_label, $panel_args );

do_action( 'wpcb_after_configuration_form_totals' );
