<?php

/**
 * The file that defines the core plugin choice 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 choice class.
 *
 * This is used to define core choice 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_Choice
{
	/**
	 * 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()
	{
		add_action( 'init', array($this, 'register_choice') );
		add_action( 'carbon_fields_register_fields', array( $this, 'register_choice_fields' ) );
		add_action( 'save_post_wpcb_choice', array( $this, 'clear_transients' ) );
		add_action( 'save_draft_wpcb_choice', array( $this, 'clear_transients' ) );

		add_filter( 'manage_wpcb_choice_posts_columns', array( $this, 'set_choice_columns' ) );
		add_action( 'manage_wpcb_choice_posts_custom_column', array( $this, 'fill_choice_columns' ), 10, 2 );
	}

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

		delete_transient( 'wpcb_configuration_choices' . $suffix );
		delete_transient( 'wpcb_configuration_choices_' . $post_id . $suffix );
	}

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

		$args = array(
			'labels'             => $labels,
			'public'             => false,
			'publicly_queryable' => false,
			'show_ui'            => true,
			'show_in_menu'       => 'edit.php?post_type=wpcb_configuration',
			'query_var'          => false,
			'rewrite'            => false,
			'with_front'         => false,
			'capability_type'    => 'post',
			'has_archive'        => false,
			'hierarchical'       => false,
			'supports'           => array('title'),
		);

		register_post_type('wpcb_choice', $args);
	}

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

		$new_columns = array(
			'title'    => __('Choice', 'wcb-configurator-builder'),
			'label'    => __('Label', 'wcb-configurator-builder'),
			'template' => __('Template', 'wcb-configurator-builder'),
			'options'  => __('Options', 'wcb-configurator-builder'),
			'required' => __('Required', 'wcb-configurator-builder'),
			'post_id'  => __('ID', 'wcb-configurator-builder'),
			'date'     => __('Date', 'wcb-configurator-builder'),
		);

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

		return $columns;
	}

	/**
	 * Fills the choice list view column values.
	 *
	 * @since    1.0.0
	 */
	public function fill_choice_columns($column, $post_id)
	{
		if ('post_id' === $column) {
			echo esc_attr( $post_id );
		} else if ('template' === $column) {
			echo esc_attr( ucfirst( get_post_meta($post_id, '_template', true) ) );
		} else if ('label' === $column) {
			echo esc_attr( get_post_meta($post_id, '_label', true) );
		} else if ('required' === $column) {
			$required = get_post_meta($post_id, '_required', true) ?: __( 'No', 'wcb-configurator-builder' );
			echo esc_attr( ucfirst( $required ) );
		} else if ('options' === $column) {
			if ( get_post_meta($post_id, '_options', true) ) {
				$options = get_post_meta($post_id, '_options', true);
				echo esc_attr( count( $options ) );
			} else {
				echo '0';
			}
		}
	}

	/**
	 * Registers the Carbon Fields for our choice post type.
	 *
	 * @since    1.0.0
	 */
	public function register_choice_fields() {
		$item_labels = array(
			'plural_name' => 'options',
			'singular_name' => 'option',
		);

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

		$type = 'label';
		$price_type = 'none';
		$info_type = 'none';
		if ( $post_id ) {
			$type = get_post_meta( $post_id, '_type', true ) ?: 'label';
			$price_type = get_post_meta( $post_id, '_price_type', true ) ?: 'none';
			$info_type = get_post_meta( $post_id, '_description_type', true ) ?: 'none';
		}

		$choice_option_fields = array(
			Field::make( 'text', 'label', __( 'Label', 'wcb-configurator-builder' ) )
				->set_width(33)
				->set_required( true ),
			Field::make( 'text', 'label_value', __( 'Value', 'wcb-configurator-builder' ) )
				->set_width(33)
				->set_help_text( __( 'Optionally set custom value like font value or URL. Defaults to label.', 'wcb-configurator-builder' ) ),
			Field::make( 'color', 'color', __( 'Color', 'wcb-configurator-builder' ) )
				->set_width(33)
				->set_conditional_logic( array( array(
					'field' => 'parent.type',
					'value' => 'color',
				))),
			Field::make( 'select', 'product_id', __( 'Product', 'wcb-configurator-builder' ) )
				->add_options( 'wpcb_get_product_list' )
				->set_help_text( __( 'Only non-configurable products appear in this list.', 'wcb-configurator-builder' ) )
				->set_width(33)
				->set_conditional_logic( array( array(
					'field' => 'parent.type',
					'value' => 'product',
				))),
			Field::make( 'image', 'thumbnail', __( 'Thumbnail', 'wcb-configurator-builder' ) )
				->set_width(33)
				->set_help_text( __( 'Optionally attach thumbnail image for the option.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'parent.show_thumbnail',
					'value' => 'yes',
				))),
		);

		if ( in_array( $info_type, array( 'notes', 'notes_descriptions', 'notes_gallery_descriptions' ) )
			|| ! get_option( 'wpcb_new_install' ) ) {
			array_push( $choice_option_fields,
				Field::make( 'textarea', 'note', __( 'Note', 'wcb-configurator-builder' ) )
					->set_width(33)
					->set_help_text( __( 'Note is displayed underneath the label', 'wcb-configurator-builder' ) ),
			);
		}
		if ( in_array( $info_type, array( 'descriptions', 'gallery_descriptions', 'notes_descriptions', 'notes_gallery_descriptions' ) )
			|| ! get_option( 'wpcb_new_install' ) ) {
			array_push( $choice_option_fields,
				Field::make( 'rich_text', 'description', __( 'Description', 'wcb-configurator-builder' ) )
					->set_width(33)
					->set_help_text( __( 'Description is displayed in a popup or popout panel', 'wcb-configurator-builder' ) ),
			);
		}
		if ( in_array( $info_type, array( 'gallery_descriptions', 'notes_gallery_descriptions' ) )
			|| ! get_option( 'wpcb_new_install' ) ) {
			array_push( $choice_option_fields,
				Field::make( 'media_gallery', 'gallery', __( 'Description gallery', 'wcb-configurator-builder' ) )
					->set_width(33)
					->set_help_text( __( 'Optionally display gallery of images above description', 'wcb-configurator-builder' ) ),
			);
		}

		if ( 'template' != $type && 'product' != $type ) {
			if ( 'yes' == wpcb_get_option( 'wpcb_enable_option_sku' ) ) {
				array_push( $choice_option_fields,
					Field::make( 'text', 'sku', __( 'SKU', 'wcb-configurator-builder' ) )
						->set_help_text( __( 'Optionally set an option SKU.', 'wcb-configurator-builder' ) )
						->set_width(33),
				);
			}
			
			if ( 'fixed' == $price_type ) {
				array_push( $choice_option_fields,
					Field::make( 'text', 'price', __( 'Price', 'wcb-configurator-builder' ) )
						->set_help_text( __( 'Additional cost for this item. Leave empty for free option.', 'wcb-configurator-builder' ) )
						->set_width(33),
					Field::make( 'text', 'sale_price', __( 'Sale Price', 'wcb-configurator-builder' ) )
						->set_help_text( __( 'Discounted additional cost for this item', 'wcb-configurator-builder' ) )
						->set_width(33),
				);
			}

			if ( function_exists('wpcb_get_formulas') ) {
				if ( 'percentage' == $price_type ) {
					array_push( $choice_option_fields,
						Field::make( 'text', 'percentage_price', __( 'Percentage price', 'wcb-configurator-builder' ) )
							->set_help_text( __( 'Enter numeric percentage value.', 'wcb-configurator-builder' ) )
							->set_width(33)
							->set_conditional_logic( array( array(
								'field' => 'parent.price_type',
								'value' => 'percentage',
							))),
						Field::make( 'select', 'percentage_field', __( 'Percentage field', 'wcb-configurator-builder' ) )
							->set_help_text( __( 'Enter field label to base price percentage on. Leave empty for configuration total price.', 'wcb-configurator-builder' ) )
							->set_options( 'wpcb_get_configurator_percentage_fields' )
							->set_width(33)
							->set_conditional_logic( array( array(
								'field' => 'parent.price_type',
								'value' => 'percentage',
							))),
					);
				}
				else if ( 'formula' == $price_type ) {
					array_push( $choice_option_fields,
						Field::make( 'select', 'formula', __( 'Price formula', 'wcb-configurator-builder' ) )
							->set_options( 'wpcb_get_formulas' )
							->set_help_text( __( 'Additional cost for this item. Select formula.', 'wcb-configurator-builder' ) )
							->set_width(33)
					);
				}
				else if ( 'table' == $price_type ) {
					array_push( $choice_option_fields,
						Field::make( 'select', 'price_table', __( 'Price table', 'wcb-configurator-builder' ) )
							->set_options( 'wpcb_get_tablepress_tables' )
							->set_help_text( __( 'Additional cost for this item. Select price table.', 'wcb-configurator-builder' ) )
							->set_width(33),
						Field::make( 'select', 'price_table_field', __( 'Price table field', 'wcb-configurator-builder' ) )
							->set_options( 'wpcb_get_configurator_fields' )
							->set_help_text( __( 'Optionally select field to base value on. Defaults to product quantity.', 'wcb-configurator-builder' ) )
							->set_width(33),
					);
				}
			}

			if ( 'yes' == wpcb_get_option( 'wpcb_manage_stock' ) ) {
				array_push( $choice_option_fields,
					Field::make( 'text', 'stock_qty', __( 'Stock quantity', 'wcb-configurator-builder' ) )
						->set_help_text( __( 'Current stock position.', 'wcb-configurator-builder' ) )
						->set_width(33),
				);
			}

			if ( 'yes' == wpcb_get_option( 'wpcb_manage_weight' ) ) {
				if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
					$weight_unit = get_option('woocommerce_weight_unit');

					array_push( $choice_option_fields,
						// translators: %s: woocommerce weight unit
						Field::make( 'text', 'weight', sprintf( __( 'Weight (%s)', 'wcb-configurator-builder' ), $weight_unit ) )
							->set_help_text( __( 'Additional option weight.', 'wcb-configurator-builder' ) )
							->set_width(33),
					);
				}
			}
		}

		$choice_visual_fields = array(
			Field::make( 'select', 'visual_type', __( 'Visual type', 'wcb-configurator-builder' ) )
				->set_width( 20 )
				->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( $choice_visual_fields,
				Field::make( 'text', 'model_target', __( '3D model camera target', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Change 3D model camera target when option is selected.', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'model_orbit', __( '3D model camera orbit', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Change 3D model camera orbit when option is selected.', 'wcb-configurator-builder' ) ),
					
				Field::make( 'text', 'model_view', __( '3D model camera field of view', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Change 3D model camera field of view when option is selected.', 'wcb-configurator-builder' ) ),

				Field::make( 'checkbox', 'use_thumbnail', __( 'Visual thumbnail', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Use thumbnail image as visual material texture.', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'model_group', __( 'Material name', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'use_thumbnail',
						'value' => true,
					))),
				Field::make( 'select', 'model_material', __( 'Preview material type', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define the type of the material the visual preview should be applied to.', 'wcb-configurator-builder' ) )
					->set_options( array(
						'color' => __( 'Base Color', 'wcb-configurator-builder' ),
						'base' => __( 'Base Texture', 'wcb-configurator-builder' ),
						'metallic' => __( 'Metallic Texture', 'wcb-configurator-builder' ),
						'normal' => __( 'Normal Texture', 'wcb-configurator-builder' ),
						'occlusion' => __( 'Occlusion Texture', 'wcb-configurator-builder' ),
						'emissive' => __( 'Emissive Texture', 'wcb-configurator-builder' ),
					) )
					->set_conditional_logic( array( array(
						'field' => 'use_thumbnail',
						'value' => true,
					))),
				Field::make( 'multiselect', 'reference', __( 'Visual reference', 'wcb-configurator-builder' ) )
					->set_options( 'wpcb_get_configurator_inputs' )
					->set_help_text( __( 'Select inputs you wish to update the visual value for.', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'use_thumbnail',
						'value' => false,
					))),
				Field::make( 'text', 'property', __( 'Visual property', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Enter property you want to update (e.g. fill, fontSize, fontFamily, etc)', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'use_thumbnail',
						'value' => false,
					))),
			);

		} else {

			array_push( $choice_visual_fields,
				Field::make( 'text', 'slide', __( 'Make Slide Active:', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Index of product image slide to show when viewing this step.', 'wcb-configurator-builder' ) ),
	
				Field::make( 'multiselect', 'reference', __( 'Visual reference', 'wcb-configurator-builder' ) )
					->set_options( 'wpcb_get_configurator_fields' )
					->set_datastore( new WPCB_Datastore() )
					->set_help_text( __( 'Select inputs you wish to update the visual value for.', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'property', __( 'Visual property', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_help_text( __( 'Enter property you want to update (e.g. color, fontSize, fontFamily, etc)', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'index', __( 'Indexes', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Index the visual appears on. Enter multiple values comma separated.', 'wcb-configurator-builder' ) )
					->set_width( 50 ),

				Field::make( 'checkbox', 'use_thumbnail', __( 'Visual thumbnail', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Use thumbnail image as visual preview image.', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'order', __( 'Layers', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Higher numbers will show on top. Enter multiple values comma separated.', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'use_thumbnail',
						'value' => true,
					))),

				Field::make( 'checkbox', 'allow_drag', __( 'Allow visual object drag', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Allows user to drag the object on the canvas in desired position', 'wcb-configurator-builder' ) ),
				Field::make( 'checkbox', 'allow_resize', __( 'Allow visual object resize', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Allows user to resize the object on the canvas', 'wcb-configurator-builder' ) ),
				Field::make( 'checkbox', 'allow_rotate', __( 'Allow visual object rotation', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Allows user to rotate the object on the canvas', 'wcb-configurator-builder' ) ),

				Field::make( 'text', 'drag_top', __( 'Preview top position', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Set default preview position from top. Use numeric values. Defaults to 0', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
				Field::make( 'text', 'drag_left', __( 'Preview left position', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Set default preview position from top. Use numeric values. Defaults to 0', 'wcb-configurator-builder' ) )
					->set_width( 50 ),
			);
		}

		$choice_base_types = array(
			'label' => __( 'Label', 'wcb-configurator-builder' ),
			'color' => __( 'Color', 'wcb-configurator-builder' ),
			'font'  => __( 'Font', 'wcb-configurator-builder' ),
			'url'   => __( 'URL', 'wcb-configurator-builder' ),
		);
		$choice_base_types = apply_filters( 'wpcb_choice_base_types', $choice_base_types );

		$choice_base_templates = array(
			'dropdown' => __( 'Dropdown', 'wcb-configurator-builder' ),
			'list' => __( 'List', 'wcb-configurator-builder' ),
			'cards' => __( 'Cards', 'wcb-configurator-builder' ),
			'swatches' => __( 'Swatches', 'wcb-configurator-builder' ),
			'button-group' => __( 'Button group', 'wcb-configurator-builder' ),
		);
		$choice_base_templates = apply_filters( 'wpcb_choice_base_templates', $choice_base_templates );

		$choice_price_types = array(
			'none'  => __( 'No price', 'wcb-configurator-builder' ),
			'fixed' => __( 'Fixed price', 'wcb-configurator-builder' ),
		);
		$choice_price_types = apply_filters( 'wpcb_choice_price_types', $choice_price_types );

		$choice_base_fields = array(
			Field::make( 'text', 'label', __( 'Label', 'wcb-configurator-builder' ) )
				->set_required( true )
				->set_help_text( __( 'Label shown in the configurator.', 'wcb-configurator-builder' ) )
				->set_width( 50 ),

			Field::make( 'select', 'type', __( 'Type', 'wcb-configurator-builder' ) )
				->add_options( $choice_base_types )
				->set_width( 25 ),

			Field::make( 'select', 'template', __( 'Template', 'wcb-configurator-builder' ) )
				->add_options( $choice_base_templates )
				->set_width( 25 ),

			Field::make( 'select', 'show_thumbnail', __( 'Display option thumbnails', 'wcb-configurator-builder' ) )
				->add_options( array(
					'yes' => __( 'Yes', 'wcb-configurator-builder' ),
					'no' => __( 'No', 'wcb-configurator-builder' ),
				) )
				->set_width( 25 ),

			Field::make( 'select', 'description_type', __( 'Option descriptions', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'This change requires an update.', 'wcb-configurator-builder' ) )
				->add_options( array(
					'none' => __( 'No descriptions' ),
					'notes' => __( 'Short notes' ),
					'descriptions' => __( 'Full descriptions' ),
					'gallery_descriptions' => __( 'Full descriptions and gallery' ),
					'notes_descriptions' => __( 'Short notes and descriptions' ),
					'notes_gallery_descriptions' => __( 'Short notes, descriptions and gallery' ),
				) )
				->set_width( 25 ),

			Field::make( 'select', 'price_type', __( 'Option price type', 'wcb-configurator-builder' ) )
				->add_options( $choice_price_types )
				->set_help_text( __( 'This change requires an update.', 'wcb-configurator-builder' ) )
				->set_width( 25 ),
		);

		if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
			array_push( $choice_base_fields,
				Field::make( 'select', 'tax_class', __( 'Tax class', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally set different tax class.', 'wcb-configurator-builder' ) )
					->set_options( 'wpcb_get_woocommerce_tax_classes' )
					->set_width( 25 )
					->set_conditional_logic( array( array(
						'field' => 'price_type',
						'compare' => '!=',
						'value' => 'none',
					))),
			);
		}

		$choice_option_fields = apply_filters( 'wpcb_choice_option_fields', $choice_option_fields );

		if ( ! $post_id ) {
			array_push( $choice_base_fields,
				Field::make( 'html', 'info_warning' )
					->set_html( sprintf( '<p><strong>%s</strong></p>', __( 'Important! Please configure and save the choice settings above before creating your options', 'wcb-configurator-builder' ) ) )
			);
		}

		array_push( $choice_base_fields,
			Field::make( 'complex', 'options', __( 'Options', 'wcb-configurator-builder' ) )
				->set_datastore( new WPCB_Datastore() )
				->setup_labels( $item_labels )
				->add_fields( $choice_option_fields )
				->set_header_template( '
					<% if (label) { %>
						<%- label %>
					<% } %>
				' )
		);

		$choice_details_fields = array(
			Field::make( 'rich_text', 'note', __( 'Short description', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Short description that will be displayed alongside the available options.', 'wcb-configurator-builder' ) ),

			Field::make( 'select', 'note_position', __( 'Short description position', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select if the short description should appear above or below options.', 'wcb-configurator-builder' ) )
				->add_options( array(
					'inherit' => __( 'Inherit from settings page', 'wcb-configurator-builder' ),
					'below' => __( 'Show below options', 'wcb-configurator-builder' ),
					'above' => __( 'Show above options', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'note',
					'value' => '',
					'compare' => '!=',
				))),

			Field::make( 'rich_text', 'description', __( 'Detailed description', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Extensive description that will be displayed in popup or slide out panel.', 'wcb-configurator-builder' ) ),

			Field::make( 'media_gallery', 'gallery', __( 'Detailed description gallery', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally display gallery of images above description', 'wcb-configurator-builder' ) ),

			Field::make( 'text', 'class', __( 'Custom class', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally enter custom HTML class(es) for the choice', 'wcb-configurator-builder' ) ),
		);

		if ( 'yes' == wpcb_get_option( 'wpcb_enable_option_sku' ) ) {
			array_push( $choice_details_fields,
				Field::make( 'text', 'sku', __( 'Choice SKU', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally enter an SKU for the choice attribute', 'wcb-configurator-builder' ) ),
			);
		}

		array_push( $choice_details_fields,
			Field::make( 'checkbox', 'label_hidden', __( 'Hide label', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_help_text( __( 'Hide complete label (including info icon) in the configurator.', 'wcb-configurator-builder' ) ),

			Field::make( 'checkbox', 'price_hidden', __( 'Hide price', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_help_text( __( 'Hide price display in the configurator.', 'wcb-configurator-builder' ) ),

			Field::make( 'text', 'placeholder', __( 'Placeholder', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Placeholder option for the Dropdown field.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => 'dropdown',
				))),

			Field::make( 'select', 'summary', __( 'Show summary of selected option', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Only applicable for Dropdown, Swatches and Button group templates.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'no' => __( 'Hide option summary', 'wcb-configurator-builder' ),
					'yes' => __( 'Show option summary', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => array( 'dropdown', 'button-group', 'swatches' ),
					'compare' => 'IN'
				))),

			Field::make( 'select', 'summary_position', __( 'Display summary position', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select if the summary should appear above or below options.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'inherit' => __( 'Inherit from settings page', 'wcb-configurator-builder' ),
					'below' => __( 'Show below options', 'wcb-configurator-builder' ),
					'above' => __( 'Show above options', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'summary',
					'value' => 'yes',
				), array(
					'field' => 'template',
					'value' => array( 'dropdown', 'button-group', 'swatches' ),
					'compare' => 'IN'
				))),

			Field::make( 'set', 'swatch_inline_display', __( 'Choose swatch inline display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally choose to show inline swatch label, note and price', 'wcb-configurator-builder' ) )
				->set_datastore(new WPCB_Datastore())
				->set_options( array(
					'label' => __( 'Show label', 'wcb-configurator-builder' ),
					'note' => __( 'Show note', 'wcb-configurator-builder' ),
					'price' => __( 'Show price', 'wcb-configurator-builder' ),
				) )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => 'swatches',
				))),

			// Field::make( 'select', 'wpcb_swatch_tooltip', __( 'Choose swatch size', 'wcb-configurator-builder' ) )
			// 	->set_help_text( __( 'Choose the size of your swatches', 'wcb-configurator-builder' ) )
			// 	->add_options( array(
			// 		'show' => __( 'Show label', 'wcb-configurator-builder' ),
			// 		'hide' => __( 'Hide label', 'wcb-configurator-builder' ),
			// 	) )
			// 	->set_conditional_logic( array( array(
			// 		'field' => 'template',
			// 		'value' => 'swatches',
			// 	))),

			Field::make( 'select', 'product_template', __( 'Product display', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose how to display the product. Only applicable for Product template.', 'wcb-configurator-builder' ) )
				->add_options( array(
					'list' => __( 'Horizontal display (list style)', 'wcb-configurator-builder' ),
					'cards' => __( 'Vertical display (card style)', 'wcb-configurator-builder' ),
				) )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => 'products'
				))),

			Field::make( 'select', 'thumbnail_position', __( 'Thumbnail position', 'wcb-configurator-builder' ) )
				->add_options( array(
					'start' => __( 'Start', 'wcb-configurator-builder' ),
					'end' => __( 'End', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array(
					'relation' => 'OR', 
					array(
						'field' => 'template',
						'value' => 'list'
					),
					array(
						'field' => 'template',
						'value' => 'cards'
					)
				)),

			Field::make( 'select', 'image_zoom', __( 'Enable option image zoom', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose the size of your swatches', 'wcb-configurator-builder' ) )
				->add_options( array(
					'no' => __( 'No zoom', 'wcb-configurator-builder' ),
					'yes' => __( 'Enable zoom', 'wcb-configurator-builder' ),
				) )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => array( 'swatches', 'list', 'cards', 'products' ),
					'compare' => 'IN',
				), array(
					'field' => 'show_thumbnail',
					'value' => 'yes',
				))),

			Field::make( 'select', 'items_per_row', __( 'Options per row', 'wcb-configurator-builder' ) )
				->add_options( array(
					'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'
				) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => array( 'swatches', 'list', 'cards', 'products' ),
					'compare' => 'IN'
				))),
			Field::make( 'select', 'items_per_row_tablet', __( 'Options per row (tablet)', 'wcb-configurator-builder' ) )
				->add_options( array(
					'1', '2', '3', '4', '5', '6', '7', '8', '9'
				) )
				->set_width( 25 )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => array( 'swatches', 'list', 'cards', 'products' ),
					'compare' => 'IN'
				))),
			Field::make( 'select', 'items_per_row_mobile', __( 'Options per row (mobile)', 'wcb-configurator-builder' ) )
				->add_options( array(
					'1', '2', '3', '4', '5', '6'
				) )
				->set_width( 25 )
				->set_conditional_logic( array( array(
					'field' => 'template',
					'value' => array( 'swatches', 'list', 'cards', 'products' ),
					'compare' => 'IN'
				))),

		);

		$choice_details_fields = apply_filters( 'wpcb_choice_details_fields', $choice_details_fields );

		array_push( $choice_details_fields,
			Field::make( 'separator', 'validation', __( 'Validation', 'wcb-configurator-builder' ) ),

			Field::make( 'select', 'required', __( 'Required choice', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select if the choice is required or optional.', 'wcb-configurator-builder' ) )
				->add_options( array(
					'no' => __( 'Optional', 'wcb-configurator-builder' ),
					'yes' => __( 'Required', 'wcb-configurator-builder' ),
				)),
		);

		$choice_validation_fields = apply_filters( 'wpcb_choice_validation_fields', $choice_details_fields );

		$choice_visual_fields = apply_filters( 'wpcb_choice_visual_fields', $choice_visual_fields );

		Container::make( 'post_meta', __( 'Choice details', 'wcb-configurator-builder' ) )
			->where( 'post_type', '=', 'wpcb_choice' )
			->add_tab( __( 'General', 'wcb-configurator-builder' ), $choice_base_fields )
			->add_tab( __( 'Details', 'wcb-configurator-builder' ), $choice_validation_fields )
			->add_tab( __( 'Visuals', 'wcb-configurator-builder' ), $choice_visual_fields );

	}
}
