<?php

namespace SmartSlotAppointmentScheduler;

use SmartSlotAppointmentScheduler\Schedule_Posttype;

if (! defined('ABSPATH')) {
	exit;
}

if (! class_exists('\SmartSlotAppointmentScheduler\Posttype_Taxonomy')) {

	class Posttype_Taxonomy {

		/**
		 * Register taxonomies for the schedule CPT.
		 *
		 * @return void
		 */
		public static function register() {

			register_taxonomy(
				'ssas_categories',
				Schedule_Posttype::SLUG,
				[
					'hierarchical'      => true,
					'public'            => true,
					'show_ui'           => true,
					'show_admin_column' => true,
					'show_in_rest'      => true,

					'labels' => [
						'name'                       => __('Categories', 'smartslot-appointment-scheduler'),
						'singular_name'              => __('Category', 'smartslot-appointment-scheduler'),
						'menu_name'                  => __('Categories', 'smartslot-appointment-scheduler'),
						'all_items'                  => __('All Categories', 'smartslot-appointment-scheduler'),
						'parent_item'                => __('Parent Category', 'smartslot-appointment-scheduler'),
						'parent_item_colon'          => __('Parent Category:', 'smartslot-appointment-scheduler'),
						'new_item_name'              => __('New Category Name', 'smartslot-appointment-scheduler'),
						'add_new_item'               => __('Add New Category', 'smartslot-appointment-scheduler'),
						'edit_item'                  => __('Edit Category', 'smartslot-appointment-scheduler'),
						'update_item'                => __('Update Category', 'smartslot-appointment-scheduler'),
						'view_item'                  => __('View Category', 'smartslot-appointment-scheduler'),
						'separate_items_with_commas' => __('Separate categories with commas', 'smartslot-appointment-scheduler'),
						'add_or_remove_items'        => __('Add or remove category', 'smartslot-appointment-scheduler'),
						'popular_items'              => __('Popular Categories', 'smartslot-appointment-scheduler'),
						'search_items'               => __('Search Categories', 'smartslot-appointment-scheduler'),
						'items_list'                 => __('Categories list', 'smartslot-appointment-scheduler'),
						'items_list_navigation'      => __('Categories list navigation', 'smartslot-appointment-scheduler'),
					],
				]
			);

			register_taxonomy(
				'ssas_services',
				Schedule_Posttype::SLUG,
				[
					'hierarchical'      => true,
					'public'            => true,
					'show_ui'           => true,
					'show_admin_column' => true,
					'show_in_rest'      => true,

					'labels' => [
						'name'                       => __('Services', 'smartslot-appointment-scheduler'),
						'singular_name'              => __('Service', 'smartslot-appointment-scheduler'),
						'menu_name'                  => __('Services', 'smartslot-appointment-scheduler'),
						'all_items'                  => __('All Services', 'smartslot-appointment-scheduler'),
						'parent_item'                => __('Parent Service', 'smartslot-appointment-scheduler'),
						'parent_item_colon'          => __('Parent Service:', 'smartslot-appointment-scheduler'),
						'new_item_name'              => __('New Service Name', 'smartslot-appointment-scheduler'),
						'add_new_item'               => __('Add New Service', 'smartslot-appointment-scheduler'),
						'edit_item'                  => __('Edit Service', 'smartslot-appointment-scheduler'),
						'update_item'                => __('Update Service', 'smartslot-appointment-scheduler'),
						'view_item'                  => __('View Service', 'smartslot-appointment-scheduler'),
						'separate_items_with_commas' => __('Separate services with commas', 'smartslot-appointment-scheduler'),
						'add_or_remove_items'        => __('Add or remove service', 'smartslot-appointment-scheduler'),
						'popular_items'              => __('Popular Services', 'smartslot-appointment-scheduler'),
						'search_items'               => __('Search Services', 'smartslot-appointment-scheduler'),
						'items_list'                 => __('Services list', 'smartslot-appointment-scheduler'),
						'items_list_navigation'      => __('Services list navigation', 'smartslot-appointment-scheduler'),
					],
				]
			);
		}

		/**
		 * Display an admin help notice on taxonomy screens.
		 *
		 * @return void
		 */
		public static function admin_help_notice() {

			$screen = get_current_screen();

			if (! $screen || $screen->base !== 'edit-tags') {
				return;
			}

			if ($screen->taxonomy === 'ssas_categories') {
				echo '<div class="notice notice-info inline"><p>';

				esc_html_e(
					'Categories help organize related services, appointments, or offerings into logical groups for easier management.',
					'smartslot-appointment-scheduler'
				);

				echo '</p></div>';
			}

			if ($screen->taxonomy === 'ssas_services') {
				echo '<div class="notice notice-info inline"><p>';

				esc_html_e(
					'Services represent the individual appointments, bookings, or offerings that users can select or schedule.',
					'smartslot-appointment-scheduler'
				);

				echo '</p></div>';
			}
		}
	}

	add_action(
		'init',
		['\SmartSlotAppointmentScheduler\Posttype_Taxonomy', 'register'],
		11
	);

	add_action(
		'admin_notices',
		['\SmartSlotAppointmentScheduler\Posttype_Taxonomy', 'admin_help_notice']
	);
}
