<?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\Block;
use Carbon_Fields\Field;

$builder_choice_fields = array(
	Field::make( 'separator', 'wpcb_choice_toggler', __( 'Choice', 'wcb-configurator-builder' ) )
		->set_classes('accordeon'),
	Field::make( 'select', 'wpcb_field', __( 'Field', 'wcb-configurator-builder' ) )
		->set_help_text( __( 'Select choice field', 'wcb-configurator-builder' ) )
		->set_classes( 'cf-select-choice' )
		->add_options( 'wpcb_get_configurator_choices' ),
	Field::make( 'checkbox', 'wpcb_field_hidden', __( 'Make field hidden', 'wcb-configurator-builder' ) )
		->set_default_value(false),
	Field::make( 'checkbox', 'wpcb_field_collapsible', __( 'Make field collapsible', 'wcb-configurator-builder' ) )
		->set_default_value(false),
	Field::make( 'select', 'wpcb_field_collapsible_state', __( 'Collapsible state', 'wcb-configurator-builder' ) )
		->set_options( array(
			'yes' => __( 'Collapsed', 'wcb-configurator-builder' ),
			'no' => __( 'Open', 'wcb-configurator-builder' ),
		))
		->set_conditional_logic( array( array(
			'field' => 'wpcb_field_collapsible',
			'value' => true,
		))),
	Field::make( 'checkbox', 'wpcb_field_set_default_option', __( 'Set default option', 'wcb-configurator-builder' ) )
		->set_classes( 'cf-checkbox-default-option' )
		->set_default_value(false),
	Field::make( 'select', 'wpcb_field_default_option', __( 'Default option', 'wcb-configurator-builder' ) )
		->add_options( 'wpcb_get_configurator_choice_options' )
		->set_classes( 'cf-select-default-option' )
		->set_conditional_logic( array( array(
			'field' => 'wpcb_field_set_default_option',
			'value' => true,
		))),
);

$builder_choice_fields = apply_filters( 'wpcb_builder_choice_fields', $builder_choice_fields );

Block::make( __( 'WCB Choice', 'wcb-configurator-builder' ) )
	->add_fields( $builder_choice_fields )
	->set_description( __( 'Displays a choice in the configuration form', 'wcb-configurator-builder' ) )
	->set_keywords(['wcb', 'choice'])
	->set_editor_style('wpcb-blocks')
	->set_category( 'wpcb-general', __( 'General', 'wcb-configurator-builder' ) )
	->set_icon( 'yes-alt' )
	->set_mode( 'edit' )
	->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {

		// include block partial

	});