<?php

/**
 * The file that defines the core plugin configuration block
 *
 * @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;

Block::make( __( 'WCB Configuration', 'wcb-configurator-builder' ) )
	->add_fields( array(
		Field::make( 'select', 'configuration_id', __( 'Configuration', 'wcb-configurator-builder' ) )
			->set_width( 50 )
			->add_options( 'wpcb_get_configurations' )
	) )
	->set_description( __( 'Displays a WCB configuration form', 'wcb-configurator-builder' ) )
	->set_keywords(['wcb', 'configurator', 'configuration'])
	->set_category( 'widgets' )
	->set_mode( 'edit' )
	->set_icon( 'wcb' )
	->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {
		if ( isset( $fields['configuration_id'] ) && $fields['configuration_id'] ) {
			echo do_shortcode('[wpcb_configuration id="' . esc_attr( $fields['configuration_id'] ) . '"]');
		}
	});