<?php
/**
 * Class to handle custom post types creation.
 *
 * @package HBFWC
 */

namespace HBFWC\Utils;

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

/**
 * Class HBFWC\Utils\Custom_Post_Types.
 */
class Custom_Post_Types {
	/**
	 * Class init.
	 */
	public static function init() {
		add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 );
	}

	/**
	 * Register post types.
	 */
	public static function register_post_types() {
		$post_types = apply_filters(
			'hbfwc_custom_post_types',
			array(
				'booking_addon' => array(
					'label'               => __( 'Booking Add-ons', 'hotel-booking-for-woocommerce' ),
					'labels'              => [
						'name'          => __( 'Booking Add-ons', 'hotel-booking-for-woocommerce' ),
						'singular_name' => __( 'Booking Add-on', 'hotel-booking-for-woocommerce' ),
						'menu_name'     => _x( 'Booking Add-ons', 'Admin menu name', 'hotel-booking-for-woocommerce' ),
						'search_items'  => __( 'Search booking add-ons', 'hotel-booking-for-woocommerce' ),
						'all_items'     => __( 'Booking Add-ons', 'hotel-booking-for-woocommerce' ),
						'edit_item'     => __( 'Edit booking add-on', 'hotel-booking-for-woocommerce' ),
						'update_item'   => __( 'Update booking add-on', 'hotel-booking-for-woocommerce' ),
						'add_new_item'  => __( 'Add new booking add-on', 'hotel-booking-for-woocommerce' ),
					],
					'public'              => false,
					'hierarchical'        => false,
					'show_in_rest'        => false,
					'show_ui'             => true,
					'show_in_menu'        => 'edit.php?post_type=product',
					'show_in_nav_menus'   => false,
					'show_in_admin_bar'   => false,
					'supports'            => [ 'title' ],
					'has_archive'         => false,
					'rewrite'             => false,
					'query_var'           => false,
					'can_export'          => true,
					'register_meta_box_cb'=> apply_filters( 'hbfwc_booking_addon_meta', [ \HBFWC\Admin\Booking_Addon_Metabox::class, 'register_metaboxes' ] ),
				),
			)
		);

		// Register each post type.
		foreach ( $post_types as $post_type => $args ) {
			if ( post_type_exists( $post_type ) ) {
				continue;
			}
			register_post_type( $post_type, $args );
		}
	}
}

// Initialize the custom post types.
if ( ! defined( 'HBFWC_CUSTOM_POST_TYPES_INIT' ) ) {
	Custom_Post_Types::init();
	define( 'HBFWC_CUSTOM_POST_TYPES_INIT', true );
}
