<?php

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

class Kavehboardticketsystem {

    public function __construct() {
        add_action('init', array($this, 'register_ticket_cpt'));
        add_action('init', array($this, 'register_department_taxonomy'));
        add_action('init', array($this, 'register_ticket_message_cpt'));
    }

    public function register_ticket_cpt() {
        $labels = array(
            'name'                  => _x('Tickets', 'Post Type General Name', 'kavehTheme'),
            'singular_name'         => _x('Ticket', 'Post Type Singular Name', 'kavehTheme'),
            'menu_name'             => __('Tickets', 'kavehTheme'),
            'name_admin_bar'        => __('Ticket', 'kavehTheme'),
            'archives'              => __('Ticket Archives', 'kavehTheme'),
            'attributes'            => __('Ticket Attributes', 'kavehTheme'),
            'parent_item_colon'     => __('Parent Ticket:', 'kavehTheme'),
            'all_items'             => __('All Tickets', 'kavehTheme'),
            'add_new_item'          => __('Add New Ticket', 'kavehTheme'),
            'add_new'               => __('Add New', 'kavehTheme'),
            'new_item'              => __('New Ticket', 'kavehTheme'),
            'edit_item'             => __('Edit Ticket', 'kavehTheme'),
            'update_item'           => __('Update Ticket', 'kavehTheme'),
            'view_item'             => __('View Ticket', 'kavehTheme'),
            'view_items'            => __('View Tickets', 'kavehTheme'),
            'search_items'          => __('Search Ticket', 'kavehTheme'),
            'not_found'             => __('Not found', 'kavehTheme'),
            'not_found_in_trash'    => __('Not found in Trash', 'kavehTheme'),
            'featured_image'        => __('Featured Image', 'kavehTheme'),
            'set_featured_image'    => __('Set featured image', 'kavehTheme'),
            'remove_featured_image' => __('Remove featured image', 'kavehTheme'),
            'use_featured_image'    => __('Use as featured image', 'kavehTheme'),
            'insert_into_item'      => __('Insert into ticket', 'kavehTheme'),
            'uploaded_to_this_item' => __('Uploaded to this ticket', 'kavehTheme'),
            'items_list'            => __('Tickets list', 'kavehTheme'),
            'items_list_navigation' => __('Tickets list navigation', 'kavehTheme'),
            'filter_items_list'     => __('Filter tickets list', 'kavehTheme'),
        );
        $args = array(
            'label'                 => __('Ticket', 'kavehTheme'),
            'description'           => __('Support Tickets', 'kavehTheme'),
            'labels'                => $labels,
            'supports'              => array('title', 'editor', 'author', 'custom-fields'),
            'hierarchical'          => false,
            'public'                => false, // Should not be publicly accessible via URL
            'show_ui'               => true,
            'show_in_menu'          => true,
            'menu_position'         => 5,
            'menu_icon'             => 'dashicons-tickets',
            'show_in_admin_bar'     => true,
            'show_in_nav_menus'     => true,
            'can_export'            => true,
            'has_archive'           => false,
            'exclude_from_search'   => true,
            'publicly_queryable'    => false,
            'capability_type'       => 'post',
            'rewrite'               => false,
        );
        register_post_type('kaveh_ticket', $args);
    }

    public function register_department_taxonomy() {
        $labels = array(
            'name'                       => _x('Departments', 'Taxonomy General Name', 'kavehTheme'),
            'singular_name'              => _x('Department', 'Taxonomy Singular Name', 'kavehTheme'),
            'menu_name'                  => __('Departments', 'kavehTheme'),
            'all_items'                  => __('All Departments', 'kavehTheme'),
            'parent_item'                => __('Parent Department', 'kavehTheme'),
            'parent_item_colon'          => __('Parent Department:', 'kavehTheme'),
            'new_item_name'              => __('New Department Name', 'kavehTheme'),
            'add_new_item'               => __('Add New Department', 'kavehTheme'),
            'edit_item'                  => __('Edit Department', 'kavehTheme'),
            'update_item'                => __('Update Department', 'kavehTheme'),
            'view_item'                  => __('View Department', 'kavehTheme'),
            'separate_items_with_commas' => __('Separate departments with commas', 'kavehTheme'),
            'add_or_remove_items'        => __('Add or remove departments', 'kavehTheme'),
            'choose_from_most_used'      => __('Choose from the most used departments', 'kavehTheme'),
            'popular_items'              => __('Popular Departments', 'kavehTheme'),
            'search_items'               => __('Search Departments', 'kavehTheme'),
            'not_found'                  => __('Not Found', 'kavehTheme'),
            'no_terms'                   => __('No departments', 'kavehTheme'),
            'items_list'                 => __('Departments list', 'kavehTheme'),
            'items_list_navigation'      => __('Departments list navigation', 'kavehTheme'),
        );
        $args = array(
            'labels'                     => $labels,
            'hierarchical'               => true,
            'public'                     => true,
            'show_ui'                    => true,
            'show_admin_column'          => true,
            'show_in_nav_menus'          => true,
            'show_tagcloud'              => true,
            'rewrite'                    => false,
        );
        register_taxonomy('kaveh_department', array('kaveh_ticket'), $args);
    }

    public function register_ticket_message_cpt() {
        $labels = array(
            'name'                  => _x('Ticket Messages', 'Post Type General Name', 'kavehTheme'),
            'singular_name'         => _x('Ticket Message', 'Post Type Singular Name', 'kavehTheme'),
            'menu_name'             => __('Ticket Messages', 'kavehTheme'),
            'name_admin_bar'        => __('Ticket Message', 'kavehTheme'),
            'archives'              => __('Ticket Message Archives', 'kavehTheme'),
            'attributes'            => __('Ticket Message Attributes', 'kavehTheme'),
            'parent_item_colon'     => __('Parent Ticket Message:', 'kavehTheme'),
            'all_items'             => __('All Ticket Messages', 'kavehTheme'),
            'add_new_item'          => __('Add New Ticket Message', 'kavehTheme'),
            'add_new'               => __('Add New', 'kavehTheme'),
            'new_item'              => __('New Ticket Message', 'kavehTheme'),
            'edit_item'             => __('Edit Ticket Message', 'kavehTheme'),
            'update_item'           => __('Update Ticket Message', 'kavehTheme'),
            'view_item'             => __('View Ticket Message', 'kavehTheme'),
            'view_items'            => __('View Ticket Messages', 'kavehTheme'),
            'search_items'          => __('Search Ticket Message', 'kavehTheme'),
            'not_found'             => __('Not found', 'kavehTheme'),
            'not_found_in_trash'    => __('Not found in Trash', 'kavehTheme'),
            'featured_image'        => __('Featured Image', 'kavehTheme'),
            'set_featured_image'    => __('Set featured image', 'kavehTheme'),
            'remove_featured_image' => __('Remove featured image', 'kavehTheme'),
            'use_featured_image'    => __('Use as featured image', 'kavehTheme'),
            'insert_into_item'      => __('Insert into ticket message', 'kavehTheme'),
            'uploaded_to_this_item' => __('Uploaded to this ticket message', 'kavehTheme'),
            'items_list'            => __('Ticket Messages list', 'kavehTheme'),
            'items_list_navigation' => __('Ticket Messages list navigation', 'kavehTheme'),
            'filter_items_list'     => __('Filter ticket messages list', 'kavehTheme'),
        );
        $args = array(
            'label'                 => __('Ticket Message', 'kavehTheme'),
            'description'           => __('Messages for Support Tickets', 'kavehTheme'),
            'labels'                => $labels,
            'supports'              => array('editor', 'author', 'custom-fields'),
            'hierarchical'          => false,
            'public'                => false,
            'show_ui'               => true,
            'show_in_menu'          => false, // Do not show in admin menu directly
            'show_in_admin_bar'     => false,
            'show_in_nav_menus'     => false,
            'can_export'            => true,
            'has_archive'           => false,
            'exclude_from_search'   => true,
            'publicly_queryable'    => false,
            'capability_type'       => 'post',
            'rewrite'               => false,
        );
        register_post_type('kaveh_ticket_message', $args);
    }

}

// Only instantiate if not already done in kavehboard.php
if (!isset($kavehboardticketsystem)) {
    new Kavehboardticketsystem();
}

?>