<?php

global $intense_custom_post_types_list;

$intense_active_cpt_list = array();
$intense_cpt_fields = array();

foreach ($intense_custom_post_types_list as $class_name => $custom_post_type) {
	$lower_title = strtolower( $custom_post_type['name'] );
	$display_title = isset( $custom_post_type['title'] ) ? $custom_post_type['title'] : $custom_post_type['name'];

	if ( empty( $custom_post_type['hide_active'] ) ) {
		$intense_active_cpt_list[ $custom_post_type['option_name'] ] = __( $display_title, 'intense' );
	}

	if ( empty( $custom_post_type['hide_single'] ) ) {
		if ( $lower_title == 'post' ) {
			$cpt_lower_title = 'post';
		} elseif ( $lower_title == 'products' ) {
			$cpt_lower_title = 'product';
		} else {
			$cpt_lower_title = 'intense_' . $lower_title;
		}

		$intense_cpt_fields['single'][] = array(
			'id'=>'intense_cpt_' . strtolower( $custom_post_type['name'] ) . '_single',
			'type' => 'select',
			"title"   => __( $display_title, 'intense' ),
			'options' => array_merge( array( '' => '' ), intense_locate_available_plugin_templates('/custom-post/' . $cpt_lower_title . '/single/'), intense_locate_single_cpt_templates( $lower_title, true ) )
		);
	}

	if ( empty( $custom_post_type['hide_name'] ) ) {
		$intense_cpt_fields['names'][] = array(
			'id'=>'intense_cpt_' . strtolower( $custom_post_type['name'] ) . '_singular',
			'type' => 'text',
			'title'   => __( $display_title ) . " " . __( 'Singular', "intense" ),
			'default' => __( $custom_post_type['singular'], "intense" ),
		);

		$intense_cpt_fields['names'][] = array(
			'id'=>'intense_cpt_' . strtolower( $custom_post_type['name'] ) . '_plural',
			'type' => 'text',
			'title'   => __( $display_title ) . " " . __( 'Plural', "intense" ),
			'default' => __( $custom_post_type['plural'], "intense" ),
		);
	}
}

$this->sections['Custom_Post_Types'] = array(
	'title' => __( 'Custom Post Types', 'intense' ),
	'icon' => 'el-icon-pencil',
	'icon_class' => 'icon-large',
	'fields' => array(		
		array(
			'id'=>'intense_cpt_post_options',
			'type' => 'switch',
			"title"   => __( "Post Options", "intense" ),
			"desc"   => __( "Show Post Options metabox on Posts", "intense" ),
			'default' => 1,
		),
		array(
			'id'=>'intense_active_cpt',
			'type' => 'checkbox',
			'title' => __( 'Active Custom Post Types', 'intense' ),			
			"options"  => $intense_active_cpt_list,
			'default' => array(				
				'intense_cpt_snippets' => '1'
			)
		),
	)
);

$this->sections['Custom_Post_Types']['fields'][] = array(
	'id'=>'intense_cpt_single_post_templates',
	'type' => 'info',
	'class' => 'intense-header',
	'desc' => __( 'Single Post Templates', 'intense' ),
);

$this->sections['Custom_Post_Types']['fields'] = array_merge( 
	$this->sections['Custom_Post_Types']['fields'], 
	$intense_cpt_fields['single'] 
);

$this->sections['Custom_Post_Types']['fields'][] = array(
	'id'=>'intense_cpt_post_names',
	'type' => 'info',
	'class' => 'intense-header',
	'desc' => __( 'Custom Post Names', 'intense' ),
);

$this->sections['Custom_Post_Types']['fields'] = array_merge( 
	$this->sections['Custom_Post_Types']['fields'], 
	$intense_cpt_fields['names'] 
);

unset( $intense_active_cpt_list );
unset( $intense_cpt_fields );
