<?php
/**
 * WPFAQBlock Taxonomy
 *
 * Registers the 'faq_group' (hierarchical) and 'faq_tag' (flat) taxonomies
 * for grouping and tagging FAQ items.
 *
 * @package WPFAQBlock
 * @since   2.0.0
 */

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

/**
 * Class WPFAQBlock_Taxonomy
 *
 * Handles registration of both FAQ taxonomies attached to the wpfaqblock CPT.
 */
class WPFAQBlock_Taxonomy
{

	/**
	 * FAQ Categories taxonomy slug (hierarchical).
	 *
	 * @since 2.0.0
	 * @var   string
	 */
	const SLUG = 'faq_group';

	/**
	 * FAQ Tags taxonomy slug (flat).
	 *
	 * @since 2.0.0
	 * @var   string
	 */
	const TAG_SLUG = 'faq_tag';

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

	/**
	 * Register both the faq_group and faq_tag taxonomies.
	 *
	 * Hooked into: init (priority 11 — after CPT is registered at 10).
	 *
	 * @since 2.0.0
	 * @return void
	 */
	public function register(): void
	{
		$this->register_groups();
		$this->register_tags();
	}

	// ──────────────────────────────────────────────
	// Private helpers
	// ──────────────────────────────────────────────

	/**
	 * Register the hierarchical 'faq_group' taxonomy (category-like).
	 *
	 * @since 2.0.0
	 * @return void
	 */
	private function register_groups(): void
	{
		$labels = array(
			'name'                       => _x( 'FAQ Categories', 'Taxonomy general name', 'wpfaqblock' ),
			'singular_name'              => _x( 'FAQ Category', 'Taxonomy singular name', 'wpfaqblock' ),
			'search_items'               => __( 'Search FAQ Categories', 'wpfaqblock' ),
			'popular_items'              => __( 'Popular FAQ Categories', 'wpfaqblock' ),
			'all_items'                  => __( 'All FAQ Categories', 'wpfaqblock' ),
			'parent_item'                => __( 'Parent FAQ Category', 'wpfaqblock' ),
			'parent_item_colon'          => __( 'Parent FAQ Category:', 'wpfaqblock' ),
			'edit_item'                  => __( 'Edit FAQ Category', 'wpfaqblock' ),
			'update_item'                => __( 'Update FAQ Category', 'wpfaqblock' ),
			'add_new_item'               => __( 'Add New FAQ Category', 'wpfaqblock' ),
			'new_item_name'              => __( 'New FAQ Category Name', 'wpfaqblock' ),
			'separate_items_with_commas' => __( 'Separate categories with commas', 'wpfaqblock' ),
			'add_or_remove_items'        => __( 'Add or remove FAQ Categories', 'wpfaqblock' ),
			'choose_from_most_used'      => __( 'Choose from most used FAQ Categories', 'wpfaqblock' ),
			'not_found'                  => __( 'No FAQ Categories found.', 'wpfaqblock' ),
			'menu_name'                  => __( 'FAQ Categories', 'wpfaqblock' ),
			'back_to_items'              => __( '← Go to FAQ Categories', 'wpfaqblock' ),
		);

		$args = array(
			'labels' => $labels,
			'hierarchical' => true,    // Category-like — groups can have parents.
			'public' => true,
			'show_ui' => true,
			'show_admin_column' => true,    // Adds Group column to FAQ list table.
			'show_in_nav_menus' => false,
			'show_in_rest' => true,
			'query_var' => true,
			'rewrite' => array('slug' => 'faq-group'),
		);

		register_taxonomy(self::SLUG, array(WPFAQBlock_CPT::SLUG), $args);
	}

	/**
	 * Register the flat 'faq_tag' taxonomy (tag-like, non-hierarchical).
	 *
	 * @since 2.0.0
	 * @return void
	 */
	private function register_tags(): void
	{
		$labels = array(
			'name' => _x('FAQ Tags', 'Taxonomy general name', 'wpfaqblock'),
			'singular_name' => _x('FAQ Tag', 'Taxonomy singular name', 'wpfaqblock'),
			'search_items' => __('Search FAQ Tags', 'wpfaqblock'),
			'popular_items' => __('Popular FAQ Tags', 'wpfaqblock'),
			'all_items' => __('All FAQ Tags', 'wpfaqblock'),
			'edit_item' => __('Edit FAQ Tag', 'wpfaqblock'),
			'update_item' => __('Update FAQ Tag', 'wpfaqblock'),
			'add_new_item' => __('Add New FAQ Tag', 'wpfaqblock'),
			'new_item_name' => __('New FAQ Tag Name', 'wpfaqblock'),
			'separate_items_with_commas' => __('Separate tags with commas', 'wpfaqblock'),
			'add_or_remove_items' => __('Add or remove FAQ Tags', 'wpfaqblock'),
			'choose_from_most_used' => __('Choose from most used FAQ Tags', 'wpfaqblock'),
			'not_found' => __('No FAQ Tags found.', 'wpfaqblock'),
			'menu_name' => __('FAQ Tags', 'wpfaqblock'),
			'back_to_items' => __('← Go to FAQ Tags', 'wpfaqblock'),
		);

		$args = array(
			'labels' => $labels,
			'hierarchical' => false,   // Tag-like — no parent/child structure.
			'public' => true,
			'show_ui' => true,
			'show_admin_column' => false,
			'show_in_nav_menus' => false,
			'show_in_rest' => true,
			'query_var' => true,
			'rewrite' => array('slug' => 'faq-tag'),
		);

		register_taxonomy(self::TAG_SLUG, array(WPFAQBlock_CPT::SLUG), $args);
	}
}
