<?php

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

if ( 'model' === wpcb_get_option( 'wpcb_configuration_visual_type' ) || 'model' === get_post_meta( $wpcb_configuration_id, '_visual_type', true ) ) :

	if ( $scenes = get_post_meta( $wpcb_configuration_id, '_wpcb_model_scenes', true ) ) :
		if ( function_exists( 'wpcb_display_modelviewer_scenes' ) ) {
			wpcb_display_modelviewer_scenes( $scenes, $wpcb_configuration_id );
		}
	endif;

else :

	global $wpcb_gallery_slots;

	// Check if multiple preview images set.
	if ( isset( $wpcb_gallery_slots ) && is_array( $wpcb_gallery_slots ) && count( $wpcb_gallery_slots ) > 1 ) :

		$nav_labels = explode( ',', get_post_meta( $wpcb_configuration_id, '_gallery_label_controls', true ) );
		$nav_icons  = carbon_get_post_meta( $wpcb_configuration_id, 'gallery_icon_controls' );

		$nav_type = get_post_meta( $wpcb_configuration_id, '_gallery_controls', true);
		$nav_class = $nav_type;

		if ( wpcb_get_option( 'wpcb_border_style' ) ) {
			$nav_class .= ' wpcb-border-' . wpcb_get_option( 'wpcb_border_style' );
		}

		$position = get_post_meta( $wpcb_configuration_id, '_gallery_control_position', true );
		$nav_class .= ' wpcb-configurator-gallery-nav--' . $position;

		$nav_icon_size = apply_filters( 'wpcb_gallery_nav_icon_size', 'thumbnail' );
		?>
		<div class="wpcb-configurator-gallery-nav wpcb-configurator-gallery-nav--<?php echo esc_attr( $nav_class ); ?>">
			<?php
			foreach ( $wpcb_gallery_slots as $wpcb_slot => $wpcb_image_id ) : 
				$active = '';
				if ( 0 == $wpcb_slot ) {
					$active = ' active';
				}
				?>
				<button class="wpcb-configurator-gallery-nav__item<?php echo esc_attr( $active ); ?>" data-slot="<?php echo esc_attr( $wpcb_slot + 1 ); ?>">
					<?php
					if ( 'bullets' === $nav_type ) {

						echo '<div class="wpcb-configurator-gallery-nav-bullet"></div>';

					} else if ( 'thumbnails' === $nav_type ) {

						echo '<div class="wpcb-configurator-gallery-nav-thumbnail"><img src=""></div>';

					} else if ('labels' === $nav_type) {

						echo '<div class="wpcb-configurator-gallery-nav-label">' . esc_attr( $nav_labels[$wpcb_slot] ) . '</div>';

					} else if ('icons' === $nav_type) {

						echo '<div class="wpcb-configurator-gallery-nav-icon">' . wp_get_attachment_image( $nav_icons[$wpcb_slot], $nav_icon_size ) . '</div>';

					}
					?>
				</button>
				<?php
			endforeach;
			?>
		</div>
		<?php
	endif;
endif;
