<?php

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

$wpcb_actions = carbon_get_post_meta( $wpcb_configuration_id, 'form_actions' );
$suffix = wpcb_get_i18n_suffix();
$inline_quote = false;
?>
<div class="wpcb-configurator-form-actions" data-wpcb-id="<?php echo esc_attr( $wpcb_configuration_id ); ?>">
	<?php
	if ( count( $wpcb_actions ) > 0 ) {
		?>
		<div class="wpcb-configurator-form-actions-list">
			<?php 
			if ( in_array( 'pdf', $wpcb_actions ) && function_exists('wpcb_configurator_form_pdf_button') ) :
				wpcb_configurator_form_pdf_button();
				
				if ( get_post_meta( $wpcb_configuration_id, '_pdf_collect_email', true ) ) {
					wpcb_configurator_form_pdf_popup( $wpcb_configuration_id, $suffix );
				}
			endif;

			if ( in_array( 'wishlist', $wpcb_actions ) && function_exists('wpcb_configurator_form_wishlist_button') ) :
				wpcb_configurator_form_wishlist_button();
			endif;
			?>
		</div>
		<?php
		if ( in_array( 'save', $wpcb_actions ) && function_exists('wpcb_configurator_form_save_popup') ) {
			wpcb_configurator_form_save_popup( $suffix );
		}

		if ( in_array( 'wishlist', $wpcb_actions ) && function_exists('wpcb_configurator_form_wishlist_popup') ) {
			wpcb_configurator_form_wishlist_popup( $suffix );
		}
	}

	/**
	* Display quote form in popup.
	*/

	$button_action = get_post_meta( $wpcb_configuration_id, '_button_action', true );
	$button_alt_action = get_post_meta( $wpcb_configuration_id, '_button_alt_action', true );

	if ( 'quote' === $button_action || 'quote' === $button_alt_action ) {
		$quote_form = get_post_meta( $wpcb_configuration_id, '_quote_shortcode', true );
		$quote_display = get_post_meta( $wpcb_configuration_id, '_quote_display', true );
		$quote_label = wpcb_get_option( 'wpcb_request_quote_panel_label', $suffix ) ?: __( 'Request a quote', 'wcb-configurator-builder' );

		if ( 'inline' === $quote_display ) {

			$inline_quote = true;

		} else {

			$quote_args = array(
				'id' => 'wpcb-single-request-quote-form-' . $wpcb_configuration_id,
				'shortcode' => $quote_form
			);

			wpcb_display_popup_html_safe( $quote_label, $quote_args );
		}
	}
	?>
</div>
<?php
if ( $inline_quote ) {
	echo '<div class="wpcb-configurator-inline-quote-form hidden">';
	echo do_shortcode( $quote_form );
	echo '</div>';
}

$wpcb_gallery_actions = carbon_get_post_meta( $wpcb_configuration_id, 'gallery_actions' ) ?: array();
if ( in_array( 'info', $wpcb_gallery_actions ) && function_exists( 'wpcb_configurator_gallery_info_popup' ) ) {
	wpcb_configurator_gallery_info_popup( $suffix );
}

if ( in_array( 'qr', $wpcb_gallery_actions ) && function_exists( 'wpcb_configurator_gallery_qr_popup' ) ) {
	wpcb_configurator_gallery_qr_popup( $suffix );
}
