<?php
/**
 * AdminCptHook class.
 *
 * Registers the custom post type used to store PromoTimeWidget instances.
 *
 * @package Ilabs\Firevert\Modules\PromoTimeWidget\Hooks\Admin
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Modules\PromoTimeWidget\Hooks\Admin;

use Ilabs\Firevert\Modules\PromoTimeWidget\Services\Type\ModuleType;

/**
 * Registers the 'promo_time_widget' custom post type.
 */
class AdminCptHook {

	/**
	 * Registers the hook that sets up the CPT.
	 *
	 * @return void
	 */
	public function register(): void {
		if ( did_action( 'init' ) ) {
			$this->register_cpt();

			return;
		}

		add_action( 'init', array( $this, 'register_cpt' ), 0 );
	}

	/**
	 * Registers the 'promo_time_widget' CPT.
	 *
	 * @return void
	 */
	public function register_cpt(): void {
		register_post_type(
			ModuleType::MODULE_CPT,
			array(
				'label'               => __( 'Promo Time Widget', 'firevert' ),
				'labels'              => array(
					'name'               => __( 'Promo Time Widgets', 'firevert' ),
					'singular_name'      => __( 'Promo Time Widget', 'firevert' ),
					'add_new_item'       => __( 'Add New Promo Time Widget', 'firevert' ),
					'edit_item'          => __( 'Edit Promo Time Widget', 'firevert' ),
					'not_found'          => __( 'No widgets found.', 'firevert' ),
					'not_found_in_trash' => __( 'No widgets found in Trash.', 'firevert' ),
				),
				'public'              => false,
				'show_ui'             => true,
				'show_in_menu'        => false,
				'show_in_rest'        => false,
				'supports'            => array( 'title', 'editor', 'author', 'thumbnail' ),
				'capability_type'     => 'post',
				'exclude_from_search' => true,
				'has_archive'         => false,
				'rewrite'             => false,
			)
		);
	}
}
