<?php
/**
 * Quote Tool Settings
 *
 * @package mof
 */

namespace MOF\Core;

defined( 'ABSPATH' ) || die();

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

/**
 * Quote_Tool_Settings Class
 */
class Quote_Tool_Settings {

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

		\add_action( 'carbon_fields_register_fields', [ $this, 'register_fields' ] );

	}

	/**
	 * Register custom fields
	 */
	public function register_fields() {

		Container::make( 'theme_options', __( 'Quote Tool', 'mof-core' ) )
			->set_page_file( 'quote-tool-settings' )
			->set_page_parent( 'options-general.php' )
			->add_fields(
				[
					Field::make( 'separator', 'mof_quote_resorts_separator', __( 'Resort Factors and Dues', 'mof-core' ) )
						->set_help_text( __( 'The resorts entered below populate the Resort selection box of the Quote Tool.', 'mof-core' ) ),
					Field::make( 'complex', 'mof_quote_resorts', __( 'Resorts', 'mof-core' ) )
						->set_collapsed( true )
						->setup_labels(
							[
								'plural_name'   => 'Resorts',
								'singular_name' => 'Resort',
							]
						)
						->add_fields(
							[
								Field::make( 'text', 'resort_name', __( 'Resort Name', 'mof-core' ) )
									->set_help_text( __( 'Resort Name must be entered exactly as in Knack.', 'mof-core' ) )
									->set_width( 60 ),
								Field::make( 'text', 'resort_factor', __( 'Factor', 'mof-core' ) )
									->set_help_text( __( 'Must be a number.', 'mof-core' ) )
									->set_attribute( 'type', 'number' )
									->set_attribute( 'min', '1' )
									->set_width( 20 ),
								Field::make( 'text', 'resort_dues_per_point', __( 'Dues Per Point', 'mof-core' ) )
									->set_help_text( __( 'Must be a number.', 'mof-core' ) )
									->set_width( 20 ),
							]
						)
						->set_header_template(
							'
							<% if (resort_name) { %>
									Resort: <%- resort_name %> (<%- resort_factor%>)
							<% } %>
							'
						),
					Field::make( 'separator', 'mof_quote_points_separator', __( 'Point Factors', 'mof-core' ) ),
					Field::make( 'complex', 'mof_quote_points', __( 'Points', 'mof-core' ) )
						->set_collapsed( true )
						->setup_labels(
							[
								'plural_name'   => 'Points',
								'singular_name' => 'Point Factor',
							]
						)
						->add_fields(
							[
								Field::make( 'text', 'points_from', __( 'From', 'mof-core' ) )
									->set_help_text( __( 'Must be a number.', 'mof-core' ) )
									->set_width( 25 ),
								Field::make( 'text', 'points_to', __( 'To', 'mof-core' ) )
									->set_help_text( __( 'Must be a number. Leave empty or use \'0\' for no upper range.', 'mof-core' ) )
									->set_width( 25 ),
								Field::make( 'text', 'points_value', __( 'Factor', 'mof-core' ) )
									->set_help_text( __( 'Number or calculation. If a calculation, be sure to use the variable \'points\'.', 'mof-core' ) )
									->set_width( 50 ),
							]
						)
						->set_header_template(
							'
							<% if (points_from) { %>
								From: <%- points_from %>
							<% } %>
							<% if (points_from && points_to) { %>

							<% } %>
							<% if (points_to) { %>
								To: <%- points_to %>
							<% } %>
							'
						),
					Field::make( 'separator', 'mof_quote_terms_separator', __( 'Term Rates', 'mof-core' ) ),
					Field::make( 'complex', 'mof_quote_terms', __( 'Terms', 'mof-core' ) )
						->set_collapsed( true )
						->setup_labels(
							[
								'plural_name'   => 'Terms',
								'singular_name' => 'Term',
							]
						)
						->add_fields(
							[
								Field::make( 'text', 'term', __( 'Term', 'mof-core' ) )
									->set_help_text( __( 'Length of loan.', 'mof-core' ) ),
								Field::make( 'text', 'ncc_option1', __( 'No Credit Check Down Payment Option 1', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 13.9).', 'mof-core' ) )
									->set_width( 33 ),
								Field::make( 'text', 'ncc_option2', __( 'No Credit Check Down Payment Option 2', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 11.9).', 'mof-core' ) )
									->set_width( 34 ),
								Field::make( 'text', 'ncc_option3', __( 'No Credit Check Down Payment Option 3', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 9.9).', 'mof-core' ) )
									->set_width( 33 ),
								Field::make( 'text', 'cc_excellent', __( 'Excellent Credit (800+)', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 14.9)', 'mof-core' ) )
									->set_width( 25 ),
								Field::make( 'text', 'cc_verygood', __( 'Very Good Credit (700+)', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 13.9)', 'mof-core' ) )
									->set_width( 25 ),
								Field::make( 'text', 'cc_good', __( 'Good Credit (650+)', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 11.9)', 'mof-core' ) )
									->set_width( 25 ),
								Field::make( 'text', 'cc_fair', __( 'Fair Credit (600+)', 'mof-core' ) )
									->set_help_text( __( 'Must be a number (ex: 8.9)', 'mof-core' ) )
									->set_width( 25 ),
							]
						)
						->set_header_template(
							'
							<% if (term) { %>
								<%- term %> Year Loan
							<% } %>
							'
						),
				]
			);

	}

}

new Quote_Tool_Settings();
