<?php
/**
 * WPFAQBlock Custom Post Type
 *
 * Registers the 'wpfaqblock' CPT used to store individual FAQ items.
 *
 * @package WPFAQBlock
 * @since   2.0.0
 */

// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class WPFAQBlock_CPT
 *
 * Handles registration of the wpfaqblock Custom Post Type.
 */
class WPFAQBlock_CPT {

	/**
	 * The CPT slug.
	 *
	 * @since 2.0.0
	 * @var   string
	 */
	const SLUG = 'wpfaqblock';

	// ──────────────────────────────────────────────
	// Hook Callbacks
	// ──────────────────────────────────────────────

	/**
	 * Register the wpfaqblock Custom Post Type.
	 *
	 * Hooked into: init
	 *
	 * @since 2.0.0
	 * @return void
	 */
	public function register(): void {
		$labels = array(
			'name'                  => _x( 'FAQs', 'Post type general name', 'wpfaqblock' ),
			'singular_name'         => _x( 'FAQ', 'Post type singular name', 'wpfaqblock' ),
			'menu_name'             => _x( 'FAQs', 'Admin Menu text', 'wpfaqblock' ),
			'name_admin_bar'        => _x( 'FAQ', 'Add New on Toolbar', 'wpfaqblock' ),
			'add_new'               => __( 'Add New', 'wpfaqblock' ),
			'add_new_item'          => __( 'Add New FAQ', 'wpfaqblock' ),
			'new_item'              => __( 'New FAQ', 'wpfaqblock' ),
			'edit_item'             => __( 'Edit FAQ', 'wpfaqblock' ),
			'view_item'             => __( 'View FAQ', 'wpfaqblock' ),
			'all_items'             => __( 'All FAQs', 'wpfaqblock' ),
			'search_items'          => __( 'Search FAQs', 'wpfaqblock' ),
			'parent_item_colon'     => __( 'Parent FAQs:', 'wpfaqblock' ),
			'not_found'             => __( 'No FAQs found.', 'wpfaqblock' ),
			'not_found_in_trash'    => __( 'No FAQs found in Trash.', 'wpfaqblock' ),
			'featured_image'        => __( 'FAQ Featured Image', 'wpfaqblock' ),
			'set_featured_image'    => __( 'Set FAQ featured image', 'wpfaqblock' ),
			'remove_featured_image' => __( 'Remove FAQ featured image', 'wpfaqblock' ),
			'use_featured_image'    => __( 'Use as featured image', 'wpfaqblock' ),
			'archives'              => __( 'FAQ Archives', 'wpfaqblock' ),
			'insert_into_item'      => __( 'Insert into FAQ', 'wpfaqblock' ),
			'uploaded_to_this_item' => __( 'Uploaded to this FAQ', 'wpfaqblock' ),
			'filter_items_list'     => __( 'Filter FAQs list', 'wpfaqblock' ),
			'items_list_navigation' => __( 'FAQs list navigation', 'wpfaqblock' ),
			'items_list'            => __( 'FAQs list', 'wpfaqblock' ),
		);

		$args = array(
			'labels'             => $labels,
			'description'        => __( 'Frequently Asked Questions managed by WPFAQBlock.', 'wpfaqblock' ),
			'public'             => true,
			'publicly_queryable' => false,  // Disables standalone single pages & hides the Slug panel in block editor.
			'exclude_from_search'=> true,   // Keeps FAQs out of general site search (they have their own search).
			'show_ui'            => true,
			'show_in_menu'       => false,
			'show_in_nav_menus'  => false,
			'show_in_rest'       => true,   // Enables Gutenberg editor support.
			'query_var'          => true,
			'rewrite'            => false,  // No need for rewrite rules since there's no frontend single page.
			'capability_type'    => 'post',
			'has_archive'        => false,
			'hierarchical'       => false,
			'menu_position'      => null,
			'menu_icon'          => 'dashicons-editor-ul',
			'supports'           => array(
				'title',       // FAQ question stored as post title.
				'editor',      // FAQ answer stored in post content.
				'custom-fields',
				'page-attributes', // Enables menu_order for drag-and-drop reordering.
			),
			'taxonomies'         => array( 'faq_group' ),
		);

		register_post_type( self::SLUG, $args );
	}
}
