<?php
/**
 * Fired during plugin activation
 *
 * @link        https://wpsmartpost.com/
 * @since      2.0.0
 *
 * @package    Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/includes
 */

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

/**
 * Custom post class to register the carousel.
 */
class Smart_Post_Show_Pro_Builder_Post_Type {

	/**
	 * The single instance of the class.
	 *
	 * @var self
	 * @since 2.0.0
	 */
	private static $instance;

	/**
	 * Allows for accessing single instance of class. Class should only be constructed once per call.
	 *
	 * @since 1.0.0
	 * @static
	 * @return self Main instance.
	 */
	public static function instance() {
		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * Post carousel builder post type
	 */
	public function smart_post_builder_post_type() {
		if ( post_type_exists( 'sp_smart_builder' ) ) {
			return;
		}
		$capability = apply_filters( 'pcp_user_role_permission', 'manage_options' );
		$show_ui    = current_user_can( $capability ) ? true : false;
		// Set the Post carousel builder post type labels.
		$labels =
			array(
				'name'               => __( 'Builder', 'smart-post-show-pro' ),
				'singular_name'      => __( 'Builder', 'smart-post-show-pro' ),
				'menu_name'          => __( 'Builder', 'smart-post-show-pro' ),
				'all_items'          => __( 'Builder', 'smart-post-show-pro' ),
				'add_new'            => __( 'Add New', 'smart-post-show-pro' ),
				'add_new_item'       => __( 'Add New', 'smart-post-show-pro' ),
				'edit'               => __( 'Edit', 'smart-post-show-pro' ),
				'edit_item'          => __( 'Edit Builder', 'smart-post-show-pro' ),
				'new_item'           => __( 'New Builder', 'smart-post-show-pro' ),
				'search_items'       => __( 'Search Builder', 'smart-post-show-pro' ),
				'not_found'          => __( 'No Builder found', 'smart-post-show-pro' ),
				'not_found_in_trash' => __( 'No Builder found in Trash', 'smart-post-show-pro' ),
			);
		// Set the Post carousel post type arguments.
		$args =
			array(
				'labels'              => $labels,
				'public'              => false,
				'supports'            => array( 'title', 'editor', 'revisions' ),
				'show_in_rest'        => true,
				'hierarchical'        => false,
				'rewrite'             => false,
				'show_ui'             => $show_ui,
				// 'show_in_menu'        => '/edit.php?post_type=sp_post_carousel',
				'show_in_menu'        => false,
				'show_in_nav_menu'    => false,
				'menu_position'       => 6,
				'exclude_from_search' => true,
				'capability_type'     => 'page',
			);

		register_post_type( 'sp_smart_builder', $args );
	}
}
