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

/**
 * Team CPT with Dynamic Slug
 */
if ( Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) {

final class Sifency_CPT_Team {

    private $option_key = 'sifency-options';
    private $post_type  = 'team';
    private $taxonomy   = 'team_category';

    public function __construct() {
        add_action( 'init', [ $this, 'register_all' ] );
    }

    /**
     * Register CPT and taxonomy
     */
    public function register_all() {
        $this->register_post_type();
        $this->register_taxonomy();
    }

    /**
     * Register Team Post Type
     */
    private function register_post_type() {

        $options = get_option( $this->option_key, [] );
        $slug    = ! empty( $options['team_slug'] )
            ? sanitize_title( $options['team_slug'] )
            : 'team';

        $labels = [
            'name'               => __( 'Team Members', 'sifency-addons' ),
            'singular_name'      => __( 'Team Member', 'sifency-addons' ),
            'menu_name'          => __( 'Team', 'sifency-addons' ),
            'add_new'            => __( 'Add New Member', 'sifency-addons' ),
            'add_new_item'       => __( 'Add New Team Member', 'sifency-addons' ),
            'edit_item'          => __( 'Edit Team Member', 'sifency-addons' ),
            'new_item'           => __( 'New Team Member', 'sifency-addons' ),
            'view_item'          => __( 'View Team Member', 'sifency-addons' ),
            'search_items'       => __( 'Search Team Members', 'sifency-addons' ),
            'not_found'          => __( 'No team members found.', 'sifency-addons' ),
            'not_found_in_trash' => __( 'No team members found in Trash.', 'sifency-addons' ),
        ];

        $args = [
            'labels'        => $labels,
            'public'        => true,
            'has_archive'   => true,
            'menu_icon'     => 'dashicons-groups',
            'show_in_rest'  => true,
            'supports'      => [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions' ],
            'rewrite'       => [
                'slug'       => $slug,
                'with_front' => false,
            ],
        ];

        register_post_type( $this->post_type, $args );
    }

    /**
     * Register Team Taxonomy
     */
    private function register_taxonomy() {

        $labels = [
            'name'          => __( 'Team Categories', 'sifency-addons' ),
            'singular_name' => __( 'Team Category', 'sifency-addons' ),
            'menu_name'     => __( 'Categories', 'sifency-addons' ),
            'search_items'  => __( 'Search Categories', 'sifency-addons' ),
            'all_items'     => __( 'All Categories', 'sifency-addons' ),
            'edit_item'     => __( 'Edit Category', 'sifency-addons' ),
            'add_new_item'  => __( 'Add New Category', 'sifency-addons' ),
        ];

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

        register_taxonomy( $this->taxonomy, [ $this->post_type ], $args );
    }
}
new Sifency_CPT_Team();
}
