<?php
/**
 * Custom Post Types 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\Metabox;
use CodexShaper\Framework\Builder\Option;
use CodexShaper\Framework\Builder\Section;

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

$cpt_settings       = csmf_config( 'options.cpt' );
$cpt_option_name    = $cpt_settings['option_name'] ?? 'csmf_post_types_settings';
$menu_title         = $cpt_settings['menu_title'] ?? 'Custom Post Types';
$menu_slug          = $cpt_settings['menu_slug'] ?? 'csmf_post_types_settings';
$parent_slug        = $cpt_settings['parent_slug'] ?? 'codexshaper-framework';
$menu_type          = $cpt_settings['menu_type'] ?? 'submenu';
$menu_icon          = $cpt_settings['menu_icon'] ?? 'fa fa-filter';
$show_reset_all     = $cpt_settings['show_reset_all'] ?? true;
$show_reset_section = $cpt_settings['show_reset_section'] ?? true;
$show_tab           = $cpt_settings['show_tab'] ?? false;

// Create options.
Option::create(
	$cpt_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(
	$cpt_option_name,
	array(
		'title'  => esc_html__( 'Post Types', 'codexshaper-framework' ),
		'icon'   => 'fa fa-share-alt',
		'fields' => array(

			array(
				'id'     => 'csmf_cpt_options',
				'type'   => 'repeater',
				'title'  => '',
				'fields' => array(

					array(
						'id'          => 'post_type',
						'type'        => 'text',
						'title'       => esc_html__( 'Post Type (Unique)', 'codexshaper-framework' ),
						'placeholder' => esc_html__( 'post_type', 'codexshaper-framework' ),
					),

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

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

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

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

					array(
						'id'          => 'supports',
						'type'        => 'select',
						'title'       => esc_html__( 'Select Supports', 'codexshaper-framework' ),
						'chosen'    => true,
						'multiple'    => true,
						'placeholder' => esc_html__( 'Select an option', 'codexshaper-framework' ),
						'options'     => array(
							'title'     => 'Title',
							'editor'    => 'Editor',
							'author'    => 'Author',
							'thumbnail' => 'Thumbnail',
							'excerpt'   => 'Excerpt',
							'comments'  => 'Comments',
						),
						'default'     => 'title',
					),

					array(
						'id'       => 'exclude_from_search',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Exclude From Search?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => false,
					),

					array(
						'id'       => 'has_archive',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Has Archive?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => false,
					),

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

					array(
						'id'       => 'show_ui',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Show 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'      => 'icon',
						'type'    => 'media',
						'title'   => esc_html__( 'Nav Icon', 'codexshaper-framework' ),
						'library' => 'image',
						'preview' => 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'       => 'is_active',
						'type'     => 'switcher',
						'title'    => esc_html__( 'Is Active?', 'codexshaper-framework' ),
						'text_on'  => 'Yes',
						'text_off' => 'No',
						'default'  => true,
					),

				),
			),
		),

	)
);

// Create post type section.
$prefix = 'csmf_metabox';

// Service Meta Box
Metabox::create(
	$prefix . '_service_options',
	array(
		'title'     => esc_html__( 'Service Options', 'codexshaper-framework' ),
		'post_type' => 'service',
	)
);

Section::create(
	$prefix . '_service_options',
	array(
		'title'  => esc_html__( 'Service Info', 'codexshaper-framework' ),
		'fields' => array(
			array(
				'id'    => 'service_thumnail',
				'type'  => 'media',
				'title' => esc_html__( 'Service Thumnail', 'codexshaper-framework' ),
			),
			array(
				'id'    => 'service_logo',
				'type'  => 'media',
				'title' => esc_html__( 'Service Logo', 'codexshaper-framework' ),
			),
			array(
				'id'          => 'service_review',
				'title'       => esc_html__( 'Review', 'codexshaper-framework' ),
				'type'        => 'select',
				'placeholder' => 'Select Review',
				'options'     => array(
					'5' => ' 5 Star',
					'4' => ' 4 Star',
					'3' => ' 3 Star',
					'2' => ' 2 Star',
					'1' => ' 1 Star',
				),
				'default'     => '5 Star',
			),
			array(
				'id'      => 'service_total_review',
				'type'    => 'text',
				'title'   => esc_html__( 'Total Review', 'codexshaper-framework' ),
				'default' => '100k',
			),
		),
	)
);

// Portfolio Meta Box
Metabox::create(
	$prefix . '_portfolio_options',
	array(
		'title'     => esc_html__( 'Portfolio Options', 'codexshaper-framework' ),
		'post_type' => 'portfolio',
	)
);

Section::create(
	$prefix . '_portfolio_options',
	array(
		'title'  => esc_html__( 'Portfolio Info', 'codexshaper-framework' ),
		'fields' => array(
			array(
				'id'    => 'portfolio_thumnail',
				'type'  => 'media',
				'title' => esc_html__( 'Portfolio Thumnail', 'codexshaper-framework' ),
			),
			array(
				'id'    => 'portfolio_logo',
				'type'  => 'media',
				'title' => esc_html__( 'Portfolio Logo', 'codexshaper-framework' ),
			),
		),
	)
);

// Blog Meta Box
Metabox::create(
	$prefix . '_blog_options',
	array(
		'title'     => esc_html__( 'Blog Options', 'codexshaper-framework' ),
		'post_type' => 'post',
	)
);

Section::create(
	$prefix . '_blog_options',
	array(
		'title'  => esc_html__( 'Blog/News Info', 'codexshaper-framework' ),
		'fields' => array(
			array(
				'id'    => 'blog_thumbnail',
				'type'  => 'media',
				'title' => esc_html__( 'Blog Thumbnail', 'codexshaper-framework' ),
			),
		),
	)
);


// Team Meta Box
Metabox::create(
	$prefix . '_team_options',
	array(
		'title'     => esc_html__( 'Team Options', 'codexshaper-framework' ),
		'post_type' => 'team',
	)
);

Section::create(
	$prefix . '_team_options',
	array(
		'title'  => esc_html__( 'Team Info', 'codexshaper-framework' ),
		'fields' => array(
			array(
				'id'      => 'member_designation',
				'type'    => 'text',
				'title'   => esc_html__( 'Team Member Designation', 'codexshaper-framework' ),
				'default' => 'Leader',
			),
			array(
				'id'    => 'profile_picture',
				'type'  => 'media',
				'title' => esc_html__( 'Profile Picture', 'codexshaper-framework' ),
			),
			array(
                'id'      => 'social_links',
                'type'    => 'repeater',
                'title'   => esc_html__( 'Social Media Links', 'codexshaper-framework' ),
                'fields'  => array(
                    array(
                        'id'    => 'social_icon',
                        'type'  => 'icon',
                        'title' => esc_html__( 'Social Icon', 'codexshaper-framework' ),
                    ),
					array(
                        'id'    => 'social_image',
                        'type'  => 'media',
                        'title' => esc_html__( 'Social Image', 'codexshaper-framework' ),
                    ),
                    array(
                        'id'    => 'social_url',
                        'type'  => 'text',
                        'title' => esc_html__( 'Social URL', 'codexshaper-framework' ),
                    ),
                ),
            ),
		),
	)
);