<?php
/**
 * Class Custom_Fields
 *
 * @package dvcrs-core
 */

namespace DVCRS\Core;

use \Carbon_Fields\Carbon_Fields;
use \Carbon_Fields\Container;
use \Carbon_Fields\Field;

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

/**
 * Custom_Fields Class
 */
class Custom_Fields {

	/**
	 * Custom_Fields constructor
	 */
	public function __construct() {

		\add_action( 'after_setup_theme', [ $this, 'load_carbon_fields' ] );
	}

	/**
	 * Load Carbon Fields
	 */
	public function load_carbon_fields() {

		require_once dirname( __FILE__ ) . '/../../vendor/autoload.php';
		Carbon_Fields::boot();

		Container::make( 'theme_options', 'Referral Code Dropdown Options' )
			->add_fields( array(
				Field::make( 'complex', 'referral_codes' )
					->set_layout( 'grid' )
					->add_fields( [
						Field::make( 'text', 'display', 'Displayed Text' )
							->set_width( 50 ),
						Field::make( 'text', 'code', 'Code' )
							->set_width( 50 )
					] )
					->set_header_template( '
						Option: <% if (display) { %>
							<%- display %> <%- code ? "(" + code + ")" : "" %>
						<% } %>
					' ),
			) );

	}
}

new Custom_Fields();
