<?php
/**
 * Custom Taxonomies Options
 *
 * @category   Builder
 * @package    CodexShaper_Framework
 * @author     CodexShaper <info@codexshaper.com>
 * @license    https://www.gnu.org/licenses/gpl-2.0.html
 * @link       https://codexshaper.com
 * @since      1.0.0
 */

use CodexShaper\Framework\Builder\Option;
use CodexShaper\Framework\Builder\Section;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

$post_types           = function_exists( 'csmf_get_cache_post_types' ) ? csmf_get_cache_post_types() : array();
$taxonomy_settings    = csmf_config( 'options.taxonomy' );
$taxonomy_option_name = $taxonomy_settings['option_name'] ?? 'csmf_taxonomy_settings';
$menu_title           = $taxonomy_settings['menu_title'] ?? 'Custom Taxonomies';
$menu_slug            = $taxonomy_settings['menu_slug'] ?? 'csmf_taxonomy_settings';
$parent_slug          = $taxonomy_settings['parent_slug'] ?? 'codexshaper-framework';
$menu_type            = $taxonomy_settings['menu_type'] ?? 'submenu';
$menu_icon            = $taxonomy_settings['menu_icon'] ?? 'fa fa-filter';
$show_reset_all       = $taxonomy_settings['show_reset_all'] ?? true;
$show_reset_section   = $taxonomy_settings['show_reset_section'] ?? true;
$show_tab             = $taxonomy_settings['show_tab'] ?? false;

// Create options.
Option::create(
	$taxonomy_option_name,
	array(
		'menu_title'         => $menu_title,
		'menu_slug'          => $menu_slug,
		'parent_slug'        => $parent_slug,
		'menu_type'          => $menu_type,
		'menu_icon'          => $menu_icon,
		'show_reset_all'     => $show_reset_all,
		'show_reset_section' => $show_reset_section,
		'show_tab'           => $show_tab,
	)
);

Section::create(
	$taxonomy_option_name,
	array(
		'title'  => esc_html__( 'Custom Taxonomies', 'codexshaper-framework' ),
		'icon'   => 'fa fa-share-alt',
		'fields' => array(
			array(
				'id'     => 'csmf_taxonomy_options',
				'type'   => 'repeater',
				'title'  => '',
				'fields' => array(

					array(
						'id'          => 'taxonomy',
						'type'        => 'text',
						'title'       => esc_html__( 'Taxonomy ID (Unique)', 'codexshaper-framework' ),
						'placeholder' => esc_html__( 'custom_taxonomy', 'codexshaper-framework' ),
					),

					array(
						'id'    => 'taxonomy_label',
						'type'  => 'text',
						'title' => esc_html__( 'Singular Name', 'codexshaper-framework' ),
					),

					array(
						'id'    => 'taxonomy_plural_label',
						'type'  => 'text',
						'title' => esc_html__( 'Plural Name', 'codexshaper-framework' ),
					),

					array(
						'id'    => 'slug',
						'type'  => 'text',
						'title' => esc_html__( 'Front Slug', 'codexshaper-framework' ),
					),

					array(
						'id'          => 'object_type',
						'type'        => 'select',
						'title'       => esc_html__( 'Select Object / Post types', 'codexshaper-framework' ),
						'multiple'    => true,
						'placeholder' => esc_html__( 'Select an object / post type', 'codexshaper-framework' ),
						'options'     => $post_types,
						'default'     => '',
					),

					array(
						'id'       => 'public',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Is public?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => true,
					),

					array(
						'id'       => 'publicly_queryable',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Publicly Queryable?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => true,
					),

					array(
						'id'       => 'show_ui',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Show in ui?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => true,
					),

					array(
						'id'       => 'show_in_menu',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Show in admin menu?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => true,
					),


					array(
						'id'       => 'show_in_nav_menus',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Show in nav menus?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => false,
					),
					array(
						'id'       => 'show_in_rest',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Show in Rest?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => false,
					),

					array(
						'id'       => 'is_active',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Is Active?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => true,
					),

				),
			),
		),
	)
);
