<?php

/**
 * The file that defines the core plugin input 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 input class.
 *
 * This is used to define core input 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_Input
{
	/**
	 * 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_input') );
		add_action( 'carbon_fields_register_fields', array( $this, 'register_inputs' ) );
		add_action( 'save_post_wpcb_input', array( $this, 'clear_transients' ) );

		add_filter( 'manage_wpcb_input_posts_columns', array( $this, 'set_input_columns' ) );
		add_action( 'manage_wpcb_input_posts_custom_column', array( $this, 'fill_input_columns' ), 10, 2 );
	}

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

		delete_transient( 'wpcb_configuration_inputs' . $suffix );
	}

	/**
	 * Registers the input for the admin area.
	 *
	 * @since    1.0.0
	 */
	public function register_input()
	{
		$labels = array(
			'name'               => __('Input fields', 'wcb-configurator-builder'),
			'singular_name'      => __('Input field', 'wcb-configurator-builder'),
			'menu_name'          => __('Input fields', 'wcb-configurator-builder'),
			'name_admin_bar'     => __('Input field', 'wcb-configurator-builder'),
			'add_new'            => __('New input field', 'wcb-configurator-builder'),
			'add_new_item'       => __('Add new input field', 'wcb-configurator-builder'),
			'new_item'           => __('New input field', 'wcb-configurator-builder'),
			'edit_item'          => __('Edit input field', 'wcb-configurator-builder'),
			'view_item'          => __('View input field', 'wcb-configurator-builder'),
			'all_items'          => __('Input fields', 'wcb-configurator-builder'),
			'search_items'       => __('Search input fields', 'wcb-configurator-builder'),
			'parent_item_colon'  => __('Parent input field:', 'wcb-configurator-builder'),
			'not_found'          => __('No input fields found.', 'wcb-configurator-builder'),
			'not_found_in_trash' => __('No input fields 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_input', $args);
	}

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

		$new_columns = array(
			'title'    => __('Input', 'wcb-configurator-builder'),
			'label'    => __('Label', 'wcb-configurator-builder'),
			'type'     => __('Type', 'wcb-configurator-builder'),
			'price'    => __('Price type', '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 input list view column values.
	 *
	 * @since    1.0.0
	 */
	public function fill_input_columns($column, $post_id)
	{
		if ('post_id' === $column) {
			echo esc_attr( $post_id );
		} else if ('type' === $column) {
			echo esc_attr( ucfirst( get_post_meta($post_id, '_type', 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 ('price' === $column) {
			$price = get_post_meta($post_id, '_price_type', true) ?: __( 'None', 'wcb-configurator-builder' );
			echo esc_attr( ucfirst( $price ) );
		}
	}

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

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

		$input_types = apply_filters( 'wpcb_input_types', array(
			'text-input'  => __( 'Text', 'wcb-configurator-builder' ),
			'textarea'    => __( 'Textarea', 'wcb-configurator-builder' ),
			'email-input' => __( 'Email', 'wcb-configurator-builder' ),
			'phone-input' => __( 'Phone', 'wcb-configurator-builder' ),
			'true-false'  => __( 'True/False', 'wcb-configurator-builder' ),
			'number-input' => __( 'Number', 'wcb-configurator-builder' )
		) );

		$input_price_types = apply_filters( 'wpcb_input_price_types', array(
			'none' => __( 'No price calculation', 'wcb-configurator-builder' ),
			'fixed' => __( 'Fixed price', 'wcb-configurator-builder' ),
			'unit' => __( 'Unit price', 'wcb-configurator-builder' ),
		));

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

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

			Field::make( 'text', 'placeholder', __( 'Placeholder', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally set a placeholder for the input.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'range-slider', 'file-upload' ),
					'compare' => 'NOT IN',
				))),

			Field::make( 'text', 'default_value', __( 'Default value', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally set a default value for the input.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN'
				))),

			Field::make( 'checkbox', 'default_checked', __( 'Default selected', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally set option checked by default.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => 'true-false',
				))),

			Field::make( 'text', 'step_increments', __( 'Step increments', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Amount of increments per step. Defaults to 1.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'number-input', 'range-slider' ),
					'compare' => 'IN',
				))),

			Field::make( 'text', 'unit', __( 'Field unit', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally display unit for given field (e.g. cm, inch, gallon, liters)', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'number-input', 'range-slider' ),
					'compare' => 'IN',
				))),

			Field::make( 'text', 'rows', __( 'Textarea rows', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally change amount of columns for textarea field', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => 'textarea',
				))),
		);

		$input_general_fields = apply_filters( 'wpcb_input_general_fields', $input_general_fields );

		array_push( $input_general_fields,
			Field::make( 'select', 'price_type', __( 'Price type', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Choose table to add your prices in a separate table', 'wcb-configurator-builder' ) )
				->add_options( $input_price_types ),

			Field::make( 'text', 'price', __( 'Price', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Additional cost when input has value. Leave empty for free of charge', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'price_type',
					'value' => 'fixed',
				))),
			Field::make( 'text', 'sale_price', __( 'Sale Price', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Discounted additional cost for this input', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'price_type',
					'value' => 'fixed',
				))),
			Field::make( 'text', 'unit_price', __( 'Unit price', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Define fixed price per unit value. Important! Units should match.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'price_type',
					'value' => 'unit',
				), array(
					'field' => 'type',
					'value' => array( 'text-input', 'textarea', 'number-input', 'range-slider' ),
					'compare' => 'IN',
				))),
			Field::make( 'text', 'unit_sale_price', __( 'Unit Sale Price', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Discounted fixed price per unit for this input', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'price_type',
					'value' => 'unit',
				), array(
					'field' => 'type',
					'value' => array( 'text-input', 'textarea', 'number-input', 'range-slider' ),
					'compare' => 'IN',
				))),
		);

		// if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
		// 	array_push( $input_general_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_conditional_logic( array( array(
		// 				'field' => 'price_type',
		// 				'compare' => '!=',
		// 				'value' => 'none',
		// 			))),
		// 	);
		// }

		$input_general_fields = apply_filters( 'wpcb_after_input_general_fields', $input_general_fields );

		$input_detail_fields = array(
			Field::make( 'checkbox', 'label_hidden', __( 'Hide label', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_help_text( __( 'Hide complete label (including price and 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( 'rich_text', 'note', __( 'Note', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Small description for input shown in the configurator.', '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', __( 'Input class', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally enter custom HTML class(es) for the input', 'wcb-configurator-builder' ) ),
		);

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

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

			// Field::make( 'text', 'regex', __( 'Field regex', 'wcb-configurator-builder' ) )
			// 	->set_help_text( __( 'Optionally set custom regex validation.', 'wcb-configurator-builder' ) )
			// 	->set_conditional_logic( array( array(
			// 		'field' => 'type',
			// 		'value' => array( 'text-input', 'phone-input', 'email-input' ),
			// 		'compare' => 'IN',
			// 	))),

			Field::make( 'text', 'min', __( 'Field min', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Minimum text length, date or numeric value for given field.', 'wcb-configurator-builder' ) )
				->set_width( 50 ),
			Field::make( 'text', 'max', __( 'Field max', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Maximum text length, date or numeric value for given field.', 'wcb-configurator-builder' ) )
				->set_width( 50 ),

		);

		$input_detail_fields = apply_filters( 'wpcb_input_detail_fields', $input_detail_fields );

		$input_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' ),
				) ),

			Field::make( 'checkbox', 'preview', __( 'Disable preview', 'wcb-configurator-builder' ) ),

			Field::make( 'radio', 'preview_type', __( 'Select preview type', 'wcb-configurator-builder' ) )
				->add_options(array(
					'input_value' => __( 'Display input value', 'wcb-configurator-builder' ),
					'reference' => __( 'Update value by reference', 'wcb-configurator-builder' ),
				)),

			Field::make( 'multiselect', 'reference', __( 'Visual reference', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Select inputs you wish to update the visual value for.', 'wcb-configurator-builder' ) )
				->set_options( 'wpcb_get_configurator_fields' )
				->set_datastore( new WPCB_Datastore() )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'reference',
				))),

			Field::make( 'text', 'property', __( 'Visual property', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Enter property you want to update (e.g. color, fontSize, fontFamily, etc)', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'reference',
				))),
		);

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

			array_push( $input_visual_fields,
				Field::make( 'text', 'multiplier', __( 'Visual multiplier', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Optionally enter multiplier if you want to change object dimensions in different unit. Defaults to millimeters', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'preview_type',
						'value' => 'reference',
					))),

				Field::make( 'text', 'model_node', __( 'Visual nodes', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Enter node name(s) you wish to update the visual property for.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'preview_type',
						'value' => 'reference',
					))),

				Field::make( 'text', 'material_name', __( 'Preview material name', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define the name of the material the visual preview should be applied to.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'type',
						'value' => 'true-false',
						'compare' => '!=',
					),  array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),

				Field::make( 'select', 'material_type', __( '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_width( 50 )
					->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' => 'type',
						'value' => 'true-false',
						'compare' => '!=',
					),  array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),
				Field::make( 'text', 'canvas_width', __( 'Preview width', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define the preview width. Should match the material width. Use numeric values.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'type',
						'value' => 'true-false',
						'compare' => '!=',
					),  array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),
				Field::make( 'text', 'canvas_height', __( 'Preview height', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define the preview height. Should match the material height. Use numeric values.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'type',
						'value' => 'true-false',
						'compare' => '!=',
					),  array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),
			);

		} else {

			array_push( $input_visual_fields,
				Field::make( 'text', 'order', __( 'Input layer order', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Higher numbers will be displayed on top. Base layer is 10.', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),

				Field::make( 'text', 'index', __( 'Display input values on slides', 'wcb-configurator-builder' ) )
					->set_attribute( 'placeholder', 'e.g. 1, 2, 5' )
					->set_help_text( __( 'Slides the main image will appear on. Defaults to first slide (1).', 'wcb-configurator-builder' ) )
					->set_conditional_logic( array( array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),

				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' ) )
					->set_conditional_logic( array( array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),
			);

		}

		array_push( $input_visual_fields,

			Field::make( 'text', '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 )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'text', 'left', __( 'Preview left position', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Set default preview position from left. Use numeric values. Defaults to 0', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'text', 'width', __( 'Preview object width', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Optionally set a fixed width. Use numeric values.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'file-upload', 'true-false' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'select', 'overflow', __( 'Preview overflow', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Set preview overflow behaviour.', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->add_options( array(
					'hidden' => __( 'Hide text', 'wcb-configurator-builder' ),
					'fittext' => __( 'Fit text within container', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'file-upload', 'true-false' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'text', 'font_family', __( 'Default font', 'wcb-configurator-builder' ) )
				->set_width( 25 )
				->set_help_text( __( 'Set default font family.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'text', 'font_size', __( 'Default font size', 'wcb-configurator-builder' ) )
				->set_width( 25 )
				->set_help_text( __( 'Set default font size.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'text', 'font_weight', __( 'Default font weight', 'wcb-configurator-builder' ) )
				->set_width( 25 )
				->set_help_text( __( 'Set default font weight.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'select', 'font_style', __( 'Default font style', 'wcb-configurator-builder' ) )
				->set_width( 25 )
				->set_options( array(
					'normal' => __( 'Normal', 'wcb-configurator-builder' ),
					'italic' => __( 'Italic', 'wcb-configurator-builder' ),
				))
				->set_help_text( __( 'Set default font style.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'select', 'text_align', __( 'Default text align', 'wcb-configurator-builder' ) )
				->set_width( 50 )
				->set_options( array(
					'left' => __( 'Left', 'wcb-configurator-builder' ),
					'center' => __( 'Center', 'wcb-configurator-builder' ),
					'right' => __( 'Right', 'wcb-configurator-builder' ),
				))
				->set_help_text( __( 'Set default font style.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'text', 'text_rotation', __( 'Default text rotation', 'wcb-configurator-builder' ) )
				->set_width( 25 )
				->set_help_text( __( 'Set default text rotation (0 - 360 degrees).', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),
			Field::make( 'color', 'font_color', __( 'Default font color', 'wcb-configurator-builder' ) )
				->set_width( 25 )
				->set_help_text( __( 'Set default font color.', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => array( 'true-false', 'file-upload' ),
					'compare' => 'NOT IN',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

			Field::make( 'select', 'image_fill', __( 'Preview image fill', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Enter the desired preview image fill.', 'wcb-configurator-builder' ) )
				->set_options( array(
					'contain' => __( 'Contain', 'wcb-configurator-builder' ),
					'cover' => __( 'Cover', 'wcb-configurator-builder' ),
				))
				->set_conditional_logic( array( array(
					'field' => 'type',
					'value' => 'file-upload',
				),  array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),

		);

		if ( 'model' === wpcb_get_option( 'wpcb_configuration_visual_type' ) || 'model' === get_post_meta( $post_id, '_visual_type', true ) ) {
			array_push( $input_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' ) ),
			);
		} else {
			array_push( $input_visual_fields,
				Field::make( 'text', 'canvas_width', __( 'Preview width', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define the preview width. Use numeric values.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'type',
						'value' => 'file-upload',
					),  array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),
				Field::make( 'text', 'canvas_height', __( 'Preview height', 'wcb-configurator-builder' ) )
					->set_help_text( __( 'Define the preview height. Use numeric values.', 'wcb-configurator-builder' ) )
					->set_width( 50 )
					->set_conditional_logic( array( array(
						'field' => 'type',
						'value' => 'file-upload',
					),  array(
						'field' => 'preview_type',
						'value' => 'input_value',
					))),
			);
		}

		array_push( $input_visual_fields,
			Field::make( 'checkbox', 'allow_customize', __( 'Allow visual object customization', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'Allows user to modify image position inside image area', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),
			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' ) )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),
			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' ) )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),
			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' ) )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),
			Field::make( 'checkbox', 'mark_dimension', __( 'Mark the input as dimension', 'wcb-configurator-builder' ) )
				->set_help_text( __( 'When checked it allows your customers to toggle the visibility of the value using the dimensions toggle', 'wcb-configurator-builder' ) )
				->set_conditional_logic( array( array(
					'field' => 'preview_type',
					'value' => 'input_value',
				))),
		);

		$input_visual_fields = apply_filters( 'wpcb_input_visual_fields', $input_visual_fields );

		Container::make( 'post_meta', __( 'Input details', 'wcb-configurator-builder' ) )
			->where( 'post_type', '=', 'wpcb_input' )
			->add_tab( __( 'General', 'wcb-configurator-builder' ), $input_general_fields )
			->add_tab( __( 'Details', 'wcb-configurator-builder' ), $input_detail_fields )
			->add_tab( __( 'Visuals', 'wcb-configurator-builder' ), $input_visual_fields );

	}
}
