<?php

/**
 * The file that defines the core plugin configurator class
 *
 * @link       https://wpconfiguratorbuilder.com
 * @since      1.0.0
 *
 * @package    wcb-configurator-builder
 * @subpackage wcb-configurator-builder/includes
 */

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

use Carbon_Fields\Container;
use Carbon_Fields\Field;

/**
 * The core plugin configurator class.
 *
 * This is used to define core configurator post type and maintain its data.
 *
 * @since      1.0.0
 * @package    wcb-configurator-builder
 * @subpackage wcb-configurator-builder/includes
 * @author     WPCB <support@wpconfiguratorbuilder.com>
 */

class WPCB_Configuration
{
	/**
	 * The version of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $version    The current version of this plugin.
	 */
	private $version;

	/**
	 * Initialize the class and set its properties.
	 *
	 * @since    1.0.0
	 * @param    string $plugin_name       The name of this plugin.
	 * @param    string $version   		   The version of this plugin.
	 */
	public function __construct( $version )
	{
		$this->version = $version;

		add_action( 'init', array($this, 'register_configurator') );
		add_action( 'carbon_fields_register_fields', array( $this, 'register_configurator_fields' ) );
		add_action( 'carbon_fields_register_fields', array( $this, 'register_configurator_blocks' ) );

		add_action( 'save_post_wpcb_configuration', array( $this, 'clear_transients' ) );

		add_filter( 'manage_wpcb_configuration_posts_columns', array( $this, 'set_configurator_columns' ) );
		add_action( 'manage_wpcb_configuration_posts_custom_column', array( $this, 'fill_configurator_columns' ), 10, 2 );

		add_filter( 'allowed_block_types_all', array( $this, 'filter_configurator_blocks' ), 10, 2 );

		add_action( 'wp', array( $this, 'load_configurator_preview_template' ) );
		add_filter( 'post_row_actions', array( $this, 'register_preview_action_link' ), 10, 2 );
	}

	/**
	 * Clears saved inputs transients.
	 *
	 * @since    1.0.0.
	 */
	public function clear_transients( $post_id ) {
		$suffix = wpcb_get_i18n_suffix();

		delete_transient( 'wpcb_configurations' . $suffix );
	}

	/**
	 * Configurator preview template
	 */
	public function register_preview_action_link($actions, $post) {
		if ($post->post_type == 'wpcb_configuration') {
			$actions['present'] = '<a href="' . esc_url( get_site_url() ) . '?page=wpcb_configuration_preview&id=' . esc_attr( $post->ID ) . '" target="_blank">'
				. esc_attr__( 'Preview', 'wcb-configurator-builder' )
			. '</a>';
		}
		return $actions;
	}

	/**
	 * Configurator preview template
	 */
	public function load_configurator_preview_template() {
		if ( ! is_user_logged_in() ) {
			return;
		}

		if ( ! isset( $_GET['page'] ) || ! isset( $_GET['id'] ) ) {
			return;
		}
		
		$page = sanitize_text_field( $_GET['page'] );
		if ( 'wpcb_configuration_preview' !== $page ) {
			return;
		}

		global $wpcb_configuration_id;
		$wpcb_configuration_id = sanitize_key( $_GET['id'] );
		if ( 'wpcb_configuration' !== get_post_type( $wpcb_configuration_id ) ) {
			return;
		}

		do_action( 'wpcb_public_output_scripts' );

		include WPCB_BASE . 'admin/partials/configurator-preview.php';

		die();
	}

	/**
	 * Registers the configurator for the admin area.
	 *
	 * @since    1.0.0
	 */
	public function register_configurator()
	{
		$labels = array(
			'name'               => __('Configurators', 'wcb-configurator-builder'),
			'singular_name'      => __('Configurator', 'wcb-configurator-builder'),
			'menu_name'          => __('Configurators', 'wcb-configurator-builder'),
			'name_admin_bar'     => __('Configurator', 'wcb-configurator-builder'),
			'add_new'            => __('New configurator', 'wcb-configurator-builder'),
			'add_new_item'       => __('Add new configurator', 'wcb-configurator-builder'),
			'new_item'           => __('New configurator', 'wcb-configurator-builder'),
			'edit_item'          => __('Edit configurator', 'wcb-configurator-builder'),
			'view_item'          => __('View configurator', 'wcb-configurator-builder'),
			'all_items'          => __('Configurators', 'wcb-configurator-builder'),
			'search_items'       => __('Search configurators', 'wcb-configurator-builder'),
			'parent_item_colon'  => __('Parent configurators:', 'wcb-configurator-builder'),
			'not_found'          => __('No configurators found.', 'wcb-configurator-builder'),
			'not_found_in_trash' => __('No configurators found in bin.', 'wcb-configurator-builder'),
		);

		$args = array(
			'labels'             => $labels,
			'public'             => false,
			'publicly_queryable' => false,
			'show_ui'            => true,
			'show_in_menu'       => true,
			'menu_position'      => 55,
			'query_var'          => false,
			'rewrite'            => false,
			'with_front'         => false,
			'capability_type'    => 'post',
			'has_archive'        => false,
			'hierarchical'       => false,
			'menu_icon'          => 'dashicons-wcb',
			'supports'           => array('title', 'editor'),
			'show_in_rest'       => true,
		);

		register_post_type('wpcb_configuration', $args);
	}

	/**
	 * Set configurator columns in admin list view.
	 *
	 * @since    1.0.0
	 */
	public function set_configurator_columns($columns)
	{
		unset($columns['title']);
		unset($columns['date']);

		$new_columns = array(
			'title'    => __('Configuration', 'wcb-configurator-builder'),
			'template' => __('Template', 'wcb-configurator-builder'),
			'type'     => __('Template type', 'wcb-configurator-builder'),
			'display'  => __('Display', 'wcb-configurator-builder'),
			'date'     => __('Date', 'wcb-configurator-builder'),
		);

		$columns = array_merge($columns, $new_columns);

		return $columns;
	}

	/**
	 * Fills the configurator list view column values.
	 *
	 * @since    1.0.0
	 */
	public function fill_configurator_columns($column, $post_id)
	{
		if ('type' === $column) {
			$type = get_post_meta($post_id, '_template_display', true) ?: 'page';
			echo esc_attr( ucfirst( $type ) );
		} else if ('template' === $column) {
			$template = get_post_meta($post_id, '_template', true) ?: 'classic';
			echo '<img src="' . esc_url( WPCB_BASE_URL ) . 'admin/img/' . esc_attr( $template ) . '.png" height="80">';
		} else if ('display' === $column) {
			$display = get_post_meta($post_id, '_product_display', true) ?: __( 'Shortcode', 'wcb-configurator-builder' );

			if ( 'product' === $display ) {
				$products = carbon_get_post_meta($post_id, 'wpcb_products');
				$rule = get_post_meta($post_id, '_product_display_rule', true);

				if ( $rule === 'in' ) {
					echo esc_attr__( 'Products: ', 'wcb-configurator-builder' );
				} else {
					echo esc_attr__( 'All products except: ', 'wcb-configurator-builder' );
				}

				if ( is_array( $products ) ) {
					foreach ( $products as $key => $product_id ) {
						echo '<a href="' . esc_url( get_permalink( $product_id  ) ) . '" target="_blank">' . esc_attr( get_the_title( $product_id ) ) . '</a>';
						if ( $key + 1 !== sizeof( $products ) ) {
							echo ', ';
						}
					}
				}
			} else if ( 'product_cat' === $display ) {
				$terms = carbon_get_post_meta($post_id, 'wpcb_product_cats');
				$rule = get_post_meta($post_id, '_product_display_rule', true);

				if ( $rule === 'in' ) {
					echo esc_attr__( 'Product categories: ', 'wcb-configurator-builder' );
				} else {
					echo esc_attr__( 'All product categories except: ', 'wcb-configurator-builder' );
				}

				if ( is_array( $terms ) ) {
					foreach ( $terms as $key => $term_id ) {
						echo '<a href="' . esc_url( get_term_link( $term_id  ) ) . '" target="_blank">' . esc_attr( get_term( $term_id )->name ) . '</a>';
						if ( $key + 1 !== sizeof( $terms ) ) {
							echo ', ';
						}
					}
				}
			} else if ( 'product_tag' === $display ) {
				$terms = carbon_get_post_meta($post_id, 'wpcb_product_tags');
				$rule = get_post_meta($post_id, '_product_display_rule', true);

				if ( $rule === 'in' ) {
					echo esc_attr__( 'Product tags: ', 'wcb-configurator-builder' );
				} else {
					echo esc_attr__( 'All product tags except: ', 'wcb-configurator-builder' );
				}

				if ( is_array( $terms ) ) {
					foreach ( $terms as $key => $term_id ) {
						echo '<a href="' . esc_url( get_term_link( $term_id  ) ) . '" target="_blank">' . esc_attr( get_term( $term_id )->name ) . '</a>';
						if ( $key + 1 !== sizeof( $terms ) ) {
							echo ', ';
						}
					}
				}
			} else {
				echo esc_attr( ucfirst( $display ) ) . ':<br><code>[wpcb_configuration id="' . esc_attr( $post_id ) . '"]</code>';
			}
		}
	}

	/**
	 * Filter list of allowed block types
	 *
	 * @since    1.0.0
	 */
	public function filter_configurator_blocks( $block_types, $context ) {
		if ( ! $context || ! $context->post ) {
			return $block_types;
		}

		if ( 'wpcb_configuration' !== $context->post->post_type ) {
			return $block_types;
		}

		$allowed_blocks = [
			'carbon-fields/wcb-tab',
			'carbon-fields/wcb-group',
			'carbon-fields/wcb-choice',
			'carbon-fields/wcb-input',
			'carbon-fields/wcb-filter',
			'carbon-fields/wcb-html',
			'carbon-fields/wcb-shortcode',
			'carbon-fields/wcb-summary',
		];

		$allowed_blocks = apply_filters( 'wpcb_configuration_block_types', $allowed_blocks );

		return $allowed_blocks;
	}

	/**
	 * Registers the Carbon Fields Blocks for our configuration post type
	 *
	 * @since    1.0.0
	 */
	public function register_configurator_blocks() {

		include WPCB_BASE . '/includes/blocks/wpcb-configuration.php';

		if ( isset( $_GET['post'] ) ) {
			$id = sanitize_key( wp_unslash( $_GET['post'] ) );

			if ( 'wpcb_configuration' !== get_post_type( $id ) ) {
				return;
			}
		}

		wp_register_style( 'wpcb-blocks', WPCB_BASE_URL . 'admin/css/wpcb-blocks.css', array(), $this->version );

		include WPCB_BASE . '/includes/blocks/wpcb-choice.php';
		include WPCB_BASE . '/includes/blocks/wpcb-html.php';
		include WPCB_BASE . '/includes/blocks/wpcb-input.php';
		include WPCB_BASE . '/includes/blocks/wpcb-group.php';
		include WPCB_BASE . '/includes/blocks/wpcb-summary.php';
		include WPCB_BASE . '/includes/blocks/wpcb-shortcode.php';
		include WPCB_BASE . '/includes/blocks/wpcb-tab.php';

		do_action( 'wpcb_register_blocks' );

	}

	/**
	 * Registers the Carbon Fields for our configurator post type.
	 *
	 * @since    1.0.0
	 */
	public function register_configurator_fields() {

		$post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : false;
		if ( ! $post_id && isset( $_POST['post_ID'] ) ) {
			$post_id = absint( $_POST['post_ID'] );
		}
		if ( ! $post_id && isset( $_GET['id'] ) ) {
			$post_id = absint( $_GET['id'] );
		}

		$gallery_actions = array(
			'fullscreen' => __( 'Show fullscreen', 'wcb-configurator-builder' ),
			'capture' => __( 'Capture image', 'wcb-configurator-builder' ),
			'reset' => __( 'Reset camera view', 'wcb-configurator-builder' ),
			'info' => __( 'View instructions', 'wcb-configurator-builder' ),
			'dimensions' => __( 'Toggle dimensions', 'wcb-configurator-builder' ),
			'qr' => __( 'QR code for AR', 'wcb-configurator-builder' ),
		);

		$visual_tab_fields = array(
			Field::make( 'select', 'visual_type', __( 'Visual type', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'This change requires an update', 'wcb-configurator-builder' ) )
				->add_options( array(
					'inherit' => __( 'Inherit from settings' ),
					'image' => __( '2D image', 'wcb-configurator-builder' ),
					'model' => __( '3D model', 'wcb-configurator-builder' ),
				) ),
		);

		if ( 'model' === wpcb_get_option( 'wpcb_configuration_visual_type' ) || 'model' === get_post_meta( $post_id, '_visual_type', true ) ) {

			array_push( $visual_tab_fields, 
				Field::make( 'set', 'gallery_actions', __( 'Gallery actions', 'wcb-configurator-builder' ) )
					->add_options( $gallery_actions )
					->set_width( 50 ),

				Field::make( 'radio', 'gallery_sticky', __( 'Gallery position (mobile)', 'wcb-configurator-builder' ) )
					->add_options( array(
						'inline' => __( 'Keep gallery on top', 'wcb-configurator-builder' ),
						'sticky' => __( 'Keep gallery in view at all times (sticky)', 'wcb-configurator-builder' ),
					))
					->set_width( 50 ),

				Field::make( 'file', 'wpcb_model_file', __( '3D model file', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add your 3D configurator model here', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),
				Field::make( 'image', 'wpcb_model_poster', __( '3D model poster', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add your 3D configurator loader image here', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),
				Field::make( 'text', 'wpcb_model_file_url', __( '3D model file URL', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'If you have an external hosted 3D model file, you can enter the URL here', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),
				Field::make( 'text', 'wpcb_model_poster_url', __( '3D model poster URL', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'If you have an external hosted 3D poster, you can enter the URL here', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),

				Field::make( 'text', 'wpcb_model_base_nodes', __( '3D model nodes', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define nodes to show by default', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),
				Field::make( 'text', 'wpcb_model_base_hotspots', __( '3D model hotspots', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define hotspots to show by default. Use hotspot IDs', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),

				Field::make( 'file', 'wpcb_model_env_image', __( 'Environment Image', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Upload an HDR image to apply lightning to the model.', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
				Field::make( 'text', 'wpcb_model_env_image_url', __( 'Environment Image URL', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Or link to an external HDR image.', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
				Field::make( 'text', 'wpcb_model_env_image_exposure', __( 'Environment image exposure', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Lightning exposure (numeric value between 0 and 2)', 'wcb-configurator-builder' ) )
					->set_width( 25 ),
				Field::make( 'text', 'wpcb_model_env_image_height', __( 'Environment image height', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Real height of the environment, for example 20m', 'wcb-configurator-builder' ) )
					->set_width( 25 ),
				Field::make( 'checkbox', 'wpcb_model_show_env_image', __( 'Display environment background image', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Displays the selected HDR image as the background image.', 'wcb-configurator-builder' ) )
					->set_width( 50 ),

				Field::make( 'select', 'wpcb_model_controls', __( 'Visual controls', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->add_options( array(
						'labels' => __( 'Labels', 'wcb-configurator-builder' ),
						'icons' => __( 'Images', 'wcb-configurator-builder' ),
					)),
				Field::make( 'select', 'wpcb_model_control_position', __( 'Visual controls position', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->add_options( array(
						'underneath' => __( 'Underneath main product gallery', 'wcb-configurator-builder' ),
						'inside' => __( 'Inside main product gallery', 'wcb-configurator-builder' ),
					)),
				Field::make( 'text', 'wpcb_model_label_controls', __( 'Label controls', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add all your labels for each visual preview here (comma separated)', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_controls',
						'value' => 'labels',
					))),
				Field::make( 'media_gallery', 'wpcb_model_image_controls', __( 'Image controls', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add all your images for each visual preview here', 'wcb-configurator-builder' ) )
					->set_duplicates_allowed( false )
					->set_type( array( 'image' ) )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_controls',
						'value' => 'icons',
					))),

				Field::make( 'complex', 'wpcb_model_scenes', __( 'Scenes', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add camera views and scenes for the 3D model', 'wcb-configurator-builder' ) )
					->set_datastore( new WPCB_Datastore() )
					->add_fields( array(
						Field::make( 'text', 'scene_target', __( 'Scene target', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'text', 'scene_orbit', __( 'Scene orbit', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'text', 'scene_view', __( 'Scene view', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'file', 'scene_env_image', __( 'Environment image', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'text', 'scene_env_image_url', __( 'Environment image URL', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'text', 'scene_env_exposure', __( 'Environment exposure', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
					))
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),

			);

		} else {

			if ( $post_id ) {
				unset( $gallery_actions['qr'] );
			}

			array_push( $visual_tab_fields, 
				Field::make( 'media_gallery', 'image_views', __( 'Visuals', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add your base visual images here', 'wcb-configurator-builder' ) )
					->set_duplicates_allowed( false )
					->set_type( array( 'image' ) )
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),

				Field::make( 'checkbox', 'include_woo_gallery', __( 'Include WooCommerce product gallery images', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Check this box to include woocommerce product gallery image as a layer', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
				Field::make( 'text', 'woo_gallery_order', __( 'WooCommerce product gallery image layer order', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Higher numbers will be displayed on top. Base layer is 10.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'include_woo_gallery',
						'value' => true,
					))),

				Field::make( 'set', 'gallery_actions', __( 'Gallery actions', 'wcb-configurator-builder' ) )
					->add_options( $gallery_actions ),
				Field::make( 'radio', 'gallery_type', __( 'Image display', 'wcb-configurator-builder' ) )
					->add_options( array(
						'stacked' => __( 'Stacked image previews', 'wcb-configurator-builder' ),
						'single' => __( 'Single image preview', 'wcb-configurator-builder' ),
					))
					->set_width( 50 ),
				Field::make( 'radio', 'gallery_sticky', __( 'Image position (mobile)', 'wcb-configurator-builder' ) )
					->add_options( array(
						'inline' => __( 'Keep gallery on top', 'wcb-configurator-builder' ),
						'sticky' => __( 'Keep gallery in view at all times (sticky)', 'wcb-configurator-builder' ),
					))
					->set_width( 50 ),
				Field::make( 'image', 'background', __( 'Visual background', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally upload a background image here', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
				Field::make( 'radio', 'background_size', __( 'Background size', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->add_options( array(
						'contain' => __( 'Contain', 'wcb-configurator-builder' ),
						'cover' => __( 'Cover', 'wcb-configurator-builder' ),
					)),
				Field::make( 'select', 'gallery_controls', __( 'Visual controls', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->add_options( array(
						'bullets' => __( 'Bullet points', 'wcb-configurator-builder' ),
						'thumbnails' => __( 'Thumbnails', 'wcb-configurator-builder' ),
						'labels' => __( 'Labels', 'wcb-configurator-builder' ),
						'icons' => __( 'Icons', 'wcb-configurator-builder' ),
					)),
				Field::make( 'select', 'gallery_control_position', __( 'Visual controls position', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->add_options( array(
						'underneath' => __( 'Underneath main product gallery', 'wcb-configurator-builder' ),
						'inside' => __( 'Inside main product gallery', 'wcb-configurator-builder' ),
					)),
				Field::make( 'text', 'gallery_label_controls', __( 'Label controls', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add all your labels for each visual preview here (comma separated)', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'gallery_controls',
						'value' => 'labels',
					))),
				Field::make( 'media_gallery', 'gallery_icon_controls', __( 'Icon controls', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add all your icons for each visual preview here', 'wcb-configurator-builder' ) )
					->set_duplicates_allowed( false )
					->set_type( array( 'image' ) )
					->set_conditional_logic( array( array(
						'field' => 'gallery_controls',
						'value' => 'icons',
					))),
			);

		}

		$visual_tab_fields = apply_filters( 'wpcb_configuration_visual_tab_fields', $visual_tab_fields );

		$form_templates = array(
			'classic' => WPCB_BASE_URL . 'admin/img/classic.png',
			'floating' => WPCB_BASE_URL . 'admin/img/floating.png',
			'basic-summary' => WPCB_BASE_URL . 'admin/img/basic-summary.png',
			'basic' => WPCB_BASE_URL . 'admin/img/basic.png',
			// 'fullwidth' => WPCB_BASE_URL . 'admin/img/fullwidth.png',
			// 'stepper' => WPCB_BASE_URL . 'admin/img/stepper.png',
			// 'horizontal' => WPCB_BASE_URL . 'admin/img/horizontal.png',
			// 'vertical' => WPCB_BASE_URL . 'admin/img/vertical.png',
			'custom' => WPCB_BASE_URL . 'admin/img/custom.png',
		);

		$form_actions = array(
			'reset' => __( 'Show reset form button', 'wcb-configurator-builder' ),
		);
		$form_actions = apply_filters( 'wpcb_form_actions', $form_actions );
		
		$form_total_actions = array(
			'cart'     => __( 'Add to cart (WooCommerce)', 'wcb-configurator-builder' ),
			'quote'    => __( 'Request a quote', 'wcb-configurator-builder' ),
			'email'    => __( 'Send email', 'wcb-configurator-builder' ),
			'none'     => __( 'No action', 'wcb-configurator-builder' ),
		);
		$form_total_actions = apply_filters( 'wpcb_configuration_form_total_actions', $form_total_actions );

		$form_total_display = array(
			'always' => __( 'Show total buttons at all times', 'wcb-configurator-builder' ),
			'valid' => __( 'Only show total buttons when all required options are selected', 'wcb-configurator-builder' ),
		);
		$form_total_display = apply_filters( 'wpcb_configuration_form_total_display', $form_total_display );

		$form_quote_types = array(
			'image' => __( 'Include configuration image in form field', 'wcb-configurator-builder' ),
			'field' => __( 'Include configuration summary in form field', 'wcb-configurator-builder' ),
		);
		$form_quote_types = apply_filters( 'wpcb_configuration_form_quote_types', $form_quote_types );

		$template_fields = array(
			Field::make( 'select', 'product_display', __( 'Display configurator when', 'wcb-configurator-builder' ) )
				->set_width( 40 )
				->set_options( array(
					'shortcode' => __( 'Shortcode', 'wcb-configurator-builder' ),
					'product' => __( 'Product', 'wcb-configurator-builder' ),
					'product_cat' => __( 'Product category', 'wcb-configurator-builder' ),
					'product_tag' => __( 'Product tag', 'wcb-configurator-builder' ),
				)),
			Field::make( 'select', 'product_display_rule', __( 'Select comparison', 'wcb-configurator-builder' ) )
				->set_width( 20 )
				->set_options( array(
					'in' => __( 'Is in list', 'wcb-configurator-builder' ),
					'notin' => __( 'Not in list', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'product_display',
					'value' => 'shortcode',
					'compare' => '!=',
				))),
			Field::make( 'multiselect', 'wpcb_products', __( 'Products', 'wcb-configurator-builder' ) )
				->set_options( 'wpcb_get_product_list' )
				->set_width( 40 )
				->set_conditional_logic( array( array(
					'field' => 'product_display',
					'value' => 'product',
				))),
			Field::make( 'multiselect', 'wpcb_product_cats', __( 'Product categories', 'wcb-configurator-builder' ) )
				->set_options( 'wpcb_get_category_list' )
				->set_width( 40 )
				->set_conditional_logic( array( array(
					'field' => 'product_display',
					'value' => 'product_cat',
				))),
			Field::make( 'multiselect', 'wpcb_product_tags', __( 'Product tags', 'wcb-configurator-builder' ) )
				->set_options( 'wpcb_get_tag_list' )
				->set_width( 40 )
				->set_conditional_logic( array( array(
					'field' => 'product_display',
					'value' => 'product_tag',
				))),

			Field::make( 'radio_image', 'template', __( 'Configurator template', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose your configurator layout template. Select code icon to build your own template using blocks or shortcodes.', 'wcb-configurator-builder' ) )
				->add_options( $form_templates ),
			Field::make( 'select', 'template_display', __( 'Configurator template display', 'wcb-configurator-builder' ) )
				->add_options( array(
					'page' => __( 'Show on page', 'wcb-configurator-builder' ),
					'popup' => __( 'Show in popup', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'template',
					'compare' => '!=',
					'value' => 'custom',
				))),
			Field::make( 'select', 'page_display', __( 'Configurator page display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose where to display the configurator on the WooCommerce product page. Only applicable when linked to products.', 'wcb-configurator-builder' ) )
				->add_options( array(
					'replace' => __( 'Replace default WooCommerce product display', 'wcb-configurator-builder' ),
					'tabs' => __( 'Show in product tabs', 'wcb-configurator-builder' ),
					'shortcode' => __( 'Show at shortcode position', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'template',
					'compare' => '!=',
					'value' => 'custom',
				), array(
					'field' => 'template_display',
					'value' => 'page',
				))),
			Field::make( 'select', 'default_form_display', __( 'WooCommerce cart form display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose where to display the configurator on the WooCommerce product page. Only applicable when linked to products.', 'wcb-configurator-builder' ) )
				->add_options( array(
					'default' => __( 'Keep default add to cart form in place', 'wcb-configurator-builder' ),
					'replace' => __( 'Replace default WooCommerce cart form with configure button', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( 
					'relation' => 'OR', 
					array(
						'field' => 'template_display',
						'value' => 'popup',
					), array(
						'field' => 'page_display',
						'value' => 'tabs',
					), array(
						'field' => 'page_display',
						'value' => 'shortcode',
					)
				)),

			Field::make( 'select', 'template_height', __( 'Template height', 'wcb-configurator-builder' ) )
				->add_options( array(
					'auto' => __( 'Form height (auto size)', 'wcb-configurator-builder' ),
					'fixed' => __( 'Fixed height (screen size)', 'wcb-configurator-builder' ),
				))
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'compare' => '!=',
					'value' => 'custom',
				))),
			Field::make( 'select', 'template_width', __( 'Template width', 'wcb-configurator-builder' ) )
				->add_options( array(
					'contained' => __( 'In container', 'wcb-configurator-builder' ),
					'fullwidth' => __( 'Full page width', 'wcb-configurator-builder' ),
				))
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'compare' => '!=',
					'value' => 'custom',
				))),
		);

		if ( 'model' === wpcb_get_option( 'wpcb_configuration_visual_type' ) || 'model' === get_post_meta( $post_id, '_visual_type', true ) ) {

			array_push( $template_fields,
				Field::make( 'select', 'model_ratio', __( 'Gallery frame ratio', 'wcb-configurator-builder' ) )
					->add_options( array(
						'landscape' => __( '16:9 (default landscape)', 'wcb-configurator-builder' ),
						'wide' => __( '16:10 (landscape)', 'wcb-configurator-builder' ),
						'fourthree' => __( '4:3 (landscape)', 'wcb-configurator-builder' ),
						'threetwo' => __( '3:2 (landscape)', 'wcb-configurator-builder' ),
						'portrait' => __( '9:16 (default portrait)', 'wcb-configurator-builder' ),
						'high' => __( '10:16 (portrait)', 'wcb-configurator-builder' ),
						'threefour' => __( '3:4 (portrait)', 'wcb-configurator-builder' ),
						'twothree' => __( '2:3 (portrait)', 'wcb-configurator-builder' ),
						'squared' => __( '1:1 (square)', 'wcb-configurator-builder' ),
					))
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template_height',
						'value' => 'auto',
					))),
				Field::make( 'select', 'model_ratio_mobile', __( 'Gallery frame ratio', 'wcb-configurator-builder' ) )
					->add_options( array(
						'landscape' => __( '16:9 (default landscape)', 'wcb-configurator-builder' ),
						'wide' => __( '16:10 (landscape)', 'wcb-configurator-builder' ),
						'fourthree' => __( '4:3 (landscape)', 'wcb-configurator-builder' ),
						'threetwo' => __( '3:2 (landscape)', 'wcb-configurator-builder' ),
						'portrait' => __( '9:16 (default portrait)', 'wcb-configurator-builder' ),
						'high' => __( '10:16 (portrait)', 'wcb-configurator-builder' ),
						'threefour' => __( '3:4 (portrait)', 'wcb-configurator-builder' ),
						'twothree' => __( '2:3 (portrait)', 'wcb-configurator-builder' ),
						'squared' => __( '1:1 (square)', 'wcb-configurator-builder' ),
					))
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'template_height',
						'value' => 'auto',
					)))
			);
		}

		array_push( $template_fields,
			Field::make( 'select', 'gallery_position', __( 'Gallery position', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'left' => __( 'Left', 'wcb-configurator-builder' ),
					'right' => __( 'Right', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'template',
					'compare' => '!=',
					'value' => 'custom',
				))),
			Field::make( 'select', 'gallery_actions_position', __( 'Gallery actions position', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'left' => __( 'Left', 'wcb-configurator-builder' ),
					'right' => __( 'Right', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'template',
					'compare' => '!=',
					'value' => 'custom',
				))),
		);

		$totals_fields = array(
			Field::make( 'set', 'form_actions', __( 'Form buttons', 'wcb-configurator-builder' ) )
				->add_options( $form_actions ),

			Field::make( 'select', 'button_action', __( 'Configurator button action', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_default_value( 'cart' )
				->add_options( $form_total_actions ),

			Field::make( 'select', 'button_alt_action', __( 'Configurator second button action', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_default_value( 'none' )
				->add_options( array_reverse( $form_total_actions ) ),

			Field::make( 'select', 'woo_product_id', __( 'Product', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select your product to be added to cart when displayed by shortcode.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_options( 'wpcb_get_product_list' )
				->set_conditional_logic( array(
					'relation' => 'or',
					array(
						'field' => 'button_alt_action',
						'value' => 'cart',
					), array(
						'field' => 'button_action',
						'value' => 'cart',
					)
				)),
			Field::make( 'select', 'show_quantity', __( 'Configurator quantity input display', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'yes' => __( 'Show quantity input', 'wcb-configurator-builder' ),
					'no' => __( 'Hide quantity input', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'cart',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'cart',
					)
				)),
			Field::make( 'select', 'quantity_input', __( 'Configurator quantity input', 'wcb-configurator-builder' ) )
				->set_options( 'wpcb_get_configurator_fields' )
				->set_help_text( __( 'Optionally set custom input to override default WooCommerce product quantity input.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'show_quantity',
					'value' => 'yes',
				))),

			Field::make( 'set', 'quote_type', __( 'Configurator quote type', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose how to include configuration in form', 'wcb-configurator-builder' ) )
				->add_options( $form_quote_types )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'quote',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'quote',
					)
				)),
			Field::make( 'text', 'quote_shortcode', __( 'Request quote form shortcode', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'quote',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'quote',
					)
				)),
			Field::make( 'select', 'quote_display', __( 'Request quote form display', 'wcb-configurator-builder' ) )
				->set_options( array(
					'popup' => __( 'In popup', 'wcb-configurator-builder' ),
					'inline' => __( 'Inline', 'wcb-configurator-builder' ),
				))
				->set_width( 50 )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'quote',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'quote',
					)
				)),

			Field::make( 'text', 'email_prefix', __( 'Before email text', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally enter text to display before email configurator summary contents', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'email',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'email',
					)
				)),
			Field::make( 'text', 'email_postfix', __( 'After email text', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally enter text to display after email configurator summary contents', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'email',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'email',
					)
				)),

			Field::make( 'checkbox', 'pdf_collect_email', __( 'Show email field', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Show email field to collect email of customer for downloading the PDF', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'pdf',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'pdf',
					)
				)),
			Field::make( 'checkbox', 'pdf_force_email', __( 'Required email', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Block download PDF functionality when no email is provided.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'button_action',
						'value' => 'pdf',
					),
					array(
						'field' => 'button_alt_action',
						'value' => 'pdf',
					)
				)),

			Field::make( 'radio', 'totals_display', __( 'Configurator totals display', 'wcb-configurator-builder' ) )
				->add_options( $form_total_display )
				->set_width( 50 ),
			Field::make( 'radio', 'totals_position', __( 'Configurator totals position', 'wcb-configurator-builder' ) )
				->add_options( array(
					'inline' => __( 'Keep total buttons in place', 'wcb-configurator-builder' ),
					'sticky' => __( 'Keep total buttons in view at all times (sticky)', 'wcb-configurator-builder' ),
				))
				->set_width( 50 ),
		);

		$price_fields = array(
			Field::make( 'rich_text', 'short_description', __( 'Short description', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'This field will not be used when displayed on a product page.', 'wcb-configurator-builder' ) ),
			Field::make( 'text', 'price', __( 'Product price', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_help_text( __( 'This field will not be used when displayed on a product page. Enter numeric value (0.00)', 'wcb-configurator-builder' ) ),
			Field::make( 'text', 'sale_price', __( 'Product sale price', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_help_text( __( 'This field will not be used when displayed on a product page', 'wcb-configurator-builder' ) ),
			Field::make( 'select', 'show_price', __( 'Configurator price display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose whether configuration prices should be visible', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'yes' => __( 'Show product price', 'wcb-configurator-builder' ),
					'no' => __( 'Hide product price', 'wcb-configurator-builder' ),
				)),
			Field::make( 'select', 'show_price_totals', __( 'Configurator totals display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose whether configuration totals should be visible', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'yes' => __( 'Show product totals', 'wcb-configurator-builder' ),
					'no' => __( 'Hide product totals', 'wcb-configurator-builder' ),
				)),

			Field::make( 'checkbox', 'change_price_display', __( 'Change WooCommerce product price display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Check this box to override the WooCommerce default price display', 'wcb-configurator-builder' ) ),

			Field::make( 'text', 'max_price', __( 'Product maximum price', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_help_text( __( 'Enter numeric value (0.00)', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'change_price_display',
					'value' => true,
				))),
			Field::make( 'text', 'price_display', __( 'Product price display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Enter format in which price should be displayed. Available merge tags: ${price}, ${sale_price}, ${max_price}', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'change_price_display',
					'value' => true,
				))),

			Field::make( 'checkbox', 'change_dimensions', __( 'Change WooCommerce product dimensions', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Check this box to update the WooCommerce product dimensions', 'wcb-configurator-builder' ) ),

			Field::make( 'select', 'configurator_length', __( 'Configurator length input', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select configuration length input to link product length', 'wcb-configurator-builder' ) )
				->set_width( 33 )
				->set_options( 'wpcb_get_configurator_inputs' )
				->set_conditional_logic( array( array(
					'field' => 'change_dimensions',
					'value' => true,
				))),
			Field::make( 'select', 'configurator_width', __( 'Configurator width input', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select configuration width input to link product width', 'wcb-configurator-builder' ) )
				->set_width( 33 )
				->set_options( 'wpcb_get_configurator_inputs' )
				->set_conditional_logic( array( array(
					'field' => 'change_dimensions',
					'value' => true,
				))),
			Field::make( 'select', 'configurator_height', __( 'Configurator height input', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select configuration height input to link product height', 'wcb-configurator-builder' ) )
				->set_width( 33 )
				->set_options( 'wpcb_get_configurator_inputs' )
				->set_conditional_logic( array( array(
					'field' => 'change_dimensions',
					'value' => true,
				))),
		);
		
		$template_fields = apply_filters( 'wpcb_configuration_tab_template_fields', $template_fields );
		$price_fields = apply_filters( 'wpcb_configuration_tab_price_fields', $price_fields );
		$totals_fields = apply_filters( 'wpcb_configuration_tab_totals_fields', $totals_fields );

		$container = Container::make( 'post_meta', __( 'Configurator data', 'wcb-configurator-builder' ) )
			->where( 'post_type', '=', 'wpcb_configuration' )
			->set_layout( 'tabbed-vertical' )
			->add_tab( __( 'Template', 'wcb-configurator-builder' ), $template_fields )
			->add_tab( __( 'Visuals', 'wcb-configurator-builder' ), $visual_tab_fields );

		if ( 'model' === wpcb_get_option( 'wpcb_configuration_visual_type' ) || 'model' === get_post_meta( $post_id, '_visual_type', true ) ) {

			$viewer_fields = apply_filters( 'wpcb_configuration_tab_viewer_fields', array(

				Field::make( 'checkbox', 'wpcb_model_interaction_prompt', __( 'Show interaction prompt', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Shows indicator to rotate the model when idle.', 'wcb-configurator-builder' ) ),
				Field::make( 'checkbox', 'wpcb_model_custom_view', __( 'Customize initial viewpoint', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Modify the initial viewpoint of the 3D object.', 'wcb-configurator-builder' ) ),
				Field::make( 'text', 'wpcb_model_initial_view', __( 'Initial camera position', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Modify the position of the 3D object.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_view',
						'value' => true,
					))),
				Field::make( 'text', 'wpcb_model_initial_fov', __( 'Initial field of view', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_view',
						'value' => true,
					))),

				Field::make( 'checkbox', 'wpcb_model_custom_target', __( 'Customize initial target', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Modify the initial target of the 3D object.', 'wcb-configurator-builder' ) ),
				Field::make( 'text', 'wpcb_model_initial_target', __( 'Initial camera target position', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_target',
						'value' => true,
					))),

				Field::make( 'checkbox', 'wpcb_model_custom_shadow', __( 'Customize model shadow', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Modify the shadow view of the 3D object', 'wcb-configurator-builder' ) ),
				Field::make( 'text', 'wpcb_model_shadow_intensity', __( 'Shadow intensity', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Modify the shadow intensity of the 3D object. Enter decimal value between 0 and 2.00', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_shadow',
						'value' => true,
					))),
				Field::make( 'text', 'wpcb_model_shadow_softness', __( 'Shadow softness', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Modify the shadow softness of the 3D object. Enter decimal value between 0 and 1.00', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_shadow',
						'value' => true,
					))),

				Field::make( 'checkbox', 'wpcb_model_custom_view_limits', __( 'Customize model viewer limits', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Apply camera viewer limits for the 3D object viewer', 'wcb-configurator-builder' ) ),
				Field::make( 'text', 'wpcb_model_counter_clockwise_limit', __( 'Counter-clockwise limit', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Limit the camera rotation. Enter numeric value between -180 and 180', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_view_limits',
						'value' => true,
					))),
				Field::make( 'text', 'wpcb_model_clockwise_limit', __( 'Clockwise limit', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Limit the camera rotation. Enter numeric value between -180 and 180', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_view_limits',
						'value' => true,
					))),
				Field::make( 'text', 'wpcb_model_topdown_limit', __( 'Top-down limit', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Limit the camera rotation. Enter numeric value between 0 and 180', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_view_limits',
						'value' => true,
					))),
				Field::make( 'text', 'wpcb_model_bottomup_limit', __( 'Bottom-up limit', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Limit the camera rotation. Enter numeric value between 0 and 180', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_custom_view_limits',
						'value' => true,
					))),

				Field::make( 'checkbox', 'wpcb_model_auto_rotation', __( 'Auto-rotate model', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Automatically rotates the 3D model when idle.', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'wpcb_model_auto_rotation_delay', __( 'Auto rotation delay', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally enter delay for auto rotation (in milliseconds)', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_auto_rotation',
						'value' => true,
					))),
				Field::make( 'text', 'wpcb_model_auto_rotation_speed', __( 'Auto-rotate speed', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Use negative value to reverse auto rotate direction. Enter value including unit (degrees, radians and percentage)', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_auto_rotation',
						'value' => true,
					))),

				Field::make( 'checkbox', 'wpcb_model_show_dimensions', __( 'Show model dimensions', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Shows dimensons of the 3D model in the viewer.', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
				Field::make( 'select', 'wpcb_model_dimension_unit', __( 'Dimension unit', 'wcb-configurator-builder' ) )
					->set_options( array(
						'cm' => __( 'Centimeters', 'wp-configurator-builder' ),
						'mm' => __( 'Millimeters', 'wp-configurator-builder' ),
						'm' => __( 'Meters', 'wp-configurator-builder' ),
						'in' => __( 'Inches', 'wp-configurator-builder' ),
						'ft' => __( 'Feet', 'wp-configurator-builder' ),
						'yd' => __( 'Yards', 'wp-configurator-builder' ),
					))
					->set_width( 50 ),

				Field::make( 'checkbox', 'wpcb_model_disable_zoom', __( 'Disable model zoom', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Disables ability to zoom in on model.', 'wcb-configurator-builder' ) ),
				Field::make( 'text', 'wpcb_model_min_zoom', __( 'Minimum model zoom', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Limit the minimum zoom level on the model. Enter value including unit.', 'wcb-configurator-builder' ) )
					->set_width( 33 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_disable_zoom',
						'value' => false,
					))),
				Field::make( 'text', 'wpcb_model_camera_touch_action', __( 'Mobile touch action', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally change mobile touch action behaviour', 'wcb-configurator-builder' ) )
					->set_attribute( 'placeholder', __( 'pan-y', 'wcb-configurator-builder' ) )
					->set_width( 33 ),
				Field::make( 'text', 'wpcb_model_camera_speed', __( 'Camera rotation speed', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally change camera rotation speed behaviour', 'wcb-configurator-builder' ) )
					->set_attribute( 'placeholder', __( 'pan-y', 'wcb-configurator-builder' ) )
					->set_width( 33 ),

				Field::make( 'checkbox', 'wpcb_model_display_ar_button', __( 'Enable AR module', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Allows model to be displayed in the room using AR capabilities.', 'wcb-configurator-builder' ) ),
				Field::make( 'select', 'wpcb_model_ar_placement', __( 'AR placement', 'wcb-configurator-builder' ) )
					->set_options( array(
						'floor' => __( 'Place on the floor', 'wcb-configurator-builder' ),
						'wall' => __( 'Place on the wall', 'wcb-configurator-builder' ),
					))
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_display_ar_button',
						'value' => true,
					))),
				Field::make( 'checkbox', 'wpcb_model_fixed_ar', __( 'Disable AR zoom', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Disables option to scale model in AR.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'wpcb_model_display_ar_button',
						'value' => true,
					))),
				
				Field::make( 'complex', 'wpcb_model_hotspots', __( 'Hotspots', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Add default hotspots to display in the configurator template', 'wcb-configurator-builder' ) )
					->set_datastore( new WPCB_Datastore() )
					->add_fields( array(
						Field::make( 'text', 'hotspot_id', __( 'Hotspot ID', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'text', 'hotspot_target', __( 'Position target', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'text', 'hotspot_normal', __( 'Position normal', 'wcb-configurator-builder' ) )
							->set_width( 33 ),
						Field::make( 'rich_text', 'hotspot_text', __( 'Hotspot Content', 'wcb-configurator-builder' ) ),
					))
					->set_conditional_logic( array( array(
						'field' => 'template',
						'value' => 'basic',
						'compare' => '!=',
					))),
					
			) );

			$container->add_tab( __( 'Viewer', 'wcb-configurator-builder' ), $viewer_fields );
		}

		$container->add_tab( __( 'Product', 'wcb-configurator-builder' ), $price_fields );
		$container->add_tab( __( 'Actions', 'wcb-configurator-builder' ), $totals_fields );
	}
}
