<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Register Career CPT and Taxonomy with Dynamic Slug
 */
final class Sifency_CPT_Career {

	public function __construct() {
		if ( class_exists( 'Sifency_Addons_Theme_Builder_Master' ) 
			&& Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() 
		) {
			add_action( 'init', [ $this, 'register_career_cpt' ] );
		}
	}

	/**
	 * Register Career Custom Post Type
	 */
	public function register_career_cpt() {

		$options = get_option( 'sifency-options', [] );
		$slug    = ! empty( $options['career_slug'] ) ? sanitize_title( $options['career_slug'] ) : 'career';

		$labels = [
			'name'               => esc_html__( 'Careers', 'sifency-addons' ),
			'singular_name'      => esc_html__( 'Career', 'sifency-addons' ),
			'add_new'            => esc_html__( 'Add New', 'sifency-addons' ),
			'add_new_item'       => esc_html__( 'Add New Career', 'sifency-addons' ),
			'edit_item'          => esc_html__( 'Edit Career', 'sifency-addons' ),
			'new_item'           => esc_html__( 'New Career', 'sifency-addons' ),
			'view_item'          => esc_html__( 'View Career', 'sifency-addons' ),
			'search_items'       => esc_html__( 'Search Careers', 'sifency-addons' ),
			'not_found'          => esc_html__( 'No careers found', 'sifency-addons' ),
			'not_found_in_trash' => esc_html__( 'No careers found in trash', 'sifency-addons' ),
			'menu_name'          => esc_html__( 'Careers', 'sifency-addons' ),
		];

		$args = [
			'label'           => esc_html__( 'Careers', 'sifency-addons' ),
			'labels'          => $labels,
			'public'          => true,
			'has_archive'     => true,
			'rewrite'         => [ 'slug' => $slug, 'with_front' => false ],
			'menu_icon'       => 'dashicons-clipboard',
			'show_in_rest'    => true,
			'supports'        => [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions' ],
			'show_in_menu'    => true,
			'capability_type' => 'post',
		];

		register_post_type( 'career', $args );

		$this->register_career_taxonomy();
	}

	/**
	 * Register Career Taxonomy
	 */
	private function register_career_taxonomy() {

		$labels = [
			'name'          => esc_html__( 'Career Categories', 'sifency-addons' ),
			'singular_name' => esc_html__( 'Career Category', 'sifency-addons' ),
			'search_items'  => esc_html__( 'Search Categories', 'sifency-addons' ),
			'all_items'     => esc_html__( 'All Categories', 'sifency-addons' ),
			'edit_item'     => esc_html__( 'Edit Category', 'sifency-addons' ),
			'update_item'   => esc_html__( 'Update Category', 'sifency-addons' ),
			'add_new_item'  => esc_html__( 'Add New Category', 'sifency-addons' ),
			'new_item_name' => esc_html__( 'New Category Name', 'sifency-addons' ),
			'menu_name'     => esc_html__( 'Categories', 'sifency-addons' ),
		];

		$args = [
			'hierarchical'      => true,
			'labels'            => $labels,
			'show_ui'           => true,
			'show_admin_column' => true,
			'query_var'         => true,
			'rewrite'           => [ 'slug' => 'career-category', 'with_front' => false ],
			'show_in_rest'      => true,
		];

		register_taxonomy( 'career_category', [ 'career' ], $args );
	}
}

new Sifency_CPT_Career();