<?php

namespace Dispatch\Config;

// use Dispatch\PostTypes\Blog as Blog;
use Dispatch\PostTypes\News as News;
use Dispatch\PostTypes\Updates as Updates;
use Dispatch\PostTypes\Maps as Maps;
use Dispatch\PostTypes\Community as Community;
use Dispatch\PostTypes\Media as Media;
use Dispatch\PostTypes\FAQ as FAQ;
use Dispatch\PostTypes\Gallery as Gallery;

class CustomPostTypes {

    public function __construct() {
    }

    /**
     * Use this as a guide when creating new post types
     * each custom post type should have it's own 'register' function
     */
    public static function register_blog() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('Blog', 'blog'),
                'singular_name' => _x('Post', 'blog'),
                'add_new' => _x('Add New', 'blog'),
                'add_new_item' => _x('Add New Post', 'blog'),
                'edit_item' => _x('Edit Post', 'blog'),
                'new_item' => _x('New Post', 'blog'),
                'view_item' => _x('View Post', 'blog'),
                'search_items' => _x('Search Blog', 'blog'),
                'not_found' => _x('No posts found', 'blog'),
                'not_found_in_trash' => _x('No posts found in Trash', 'blog'),
                'parent_item_colon' => _x('Parent Post:', 'blog'),
                'menu_name' => _x('Blog', 'blog'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Blog Posts',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'),
                'public' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => true,
                'publicly_queryable' => true,
                'exclude_from_search' => false,
                'has_archive' => true,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-welcome-write-blog'
            );
            register_post_type( Blog::this_post_type(), $args );
            // add_post_type_support( 'blog', 'post-formats' );
            // register_taxonomy_for_object_type( 'category', 'blog' );
        });

    }

    public static function register_news() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('News', 'news'),
                'singular_name' => _x('Article', 'news'),
                'add_new' => _x('Add New', 'news'),
                'add_new_item' => _x('Add New Article', 'news'),
                'edit_item' => _x('Edit Article', 'news'),
                'new_item' => _x('New Article', 'news'),
                'view_item' => _x('View Article', 'news'),
                'search_items' => _x('Search News', 'news'),
                'not_found' => _x('No article found', 'news'),
                'not_found_in_trash' => _x('No article found in Trash', 'news'),
                'parent_item_colon' => _x('Parent Article:', 'news'),
                'menu_name' => _x('News', 'news'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Article',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'),
                'public' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => true,
                'publicly_queryable' => true,
                'exclude_from_search' => false,
                'has_archive' => true,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-layout'
            );
            register_post_type( News::this_post_type(), $args );
        });

    }

    public static function register_updates() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('Construction Updates', 'updates'),
                'singular_name' => _x('Update', 'updates'),
                'add_new' => _x('Add New', 'updates'),
                'add_new_item' => _x('Add New Update', 'updates'),
                'edit_item' => _x('Edit Update', 'updates'),
                'new_item' => _x('New Update', 'updates'),
                'view_item' => _x('View Update', 'updates'),
                'search_items' => _x('Search Construction Updates', 'updates'),
                'not_found' => _x('No Update found', 'updates'),
                'not_found_in_trash' => _x('No Update found in Trash', 'updates'),
                'parent_item_colon' => _x('Parent Update:', 'updates'),
                'menu_name' => _x('Construction Updates', 'updates'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Article',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'),
                'public' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => true,
                'publicly_queryable' => true,
                'exclude_from_search' => false,
                'has_archive' => false,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-admin-tools'
            );
            register_post_type( Updates::this_post_type(), $args );
        });

    }

    public static function register_maps() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('Maps', 'maps'),
                'singular_name' => _x('Map', 'maps'),
                'add_new' => _x('Add New', 'maps'),
                'add_new_item' => _x('Add New Map', 'maps'),
                'edit_item' => _x('Edit Map', 'maps'),
                'new_item' => _x('New Map', 'maps'),
                'view_item' => _x('View Map', 'maps'),
                'search_items' => _x('Search Maps', 'maps'),
                'not_found' => _x('No Map found', 'maps'),
                'not_found_in_trash' => _x('No Map found in Trash', 'maps'),
                'parent_item_colon' => _x('Parent Map:', 'maps'),
                'menu_name' => _x('Maps', 'maps'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Article',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'),
                'public' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => false,
                'publicly_queryable' => true,
                'exclude_from_search' => false,
                'has_archive' => false,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-location-alt'
            );
            register_post_type( Maps::this_post_type(), $args );
        });

    }

    public static function register_community() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('Community Profiles', 'profile'),
                'singular_name' => _x('Profile', 'profile'),
                'add_new' => _x('Add New', 'profile'),
                'add_new_item' => _x('Add New Profile', 'profile'),
                'edit_item' => _x('Edit Profile', 'profile'),
                'new_item' => _x('New Profile', 'profile'),
                'view_item' => _x('View Profile', 'profile'),
                'search_items' => _x('Search Community Profiles', 'profile'),
                'not_found' => _x('No Profile found', 'profile'),
                'not_found_in_trash' => _x('No Profiles found in Trash', 'profile'),
                'parent_item_colon' => _x('Parent Profile:', 'profile'),
                'menu_name' => _x('Community Profiles', 'profile'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Article',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'),
                'public' => false,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => false,
                'publicly_queryable' => false,
                'exclude_from_search' => true,
                'has_archive' => false,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-star-filled'
            );
            register_post_type( Community::this_post_type(), $args );
        });

    }

    public static function register_media() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('Media & Publications', 'media'),
                'singular_name' => _x('Article', 'media'),
                'add_new' => _x('Add New', 'media'),
                'add_new_item' => _x('Add New Article', 'media'),
                'edit_item' => _x('Edit Article', 'media'),
                'new_item' => _x('New Article', 'media'),
                'view_item' => _x('View Article', 'media'),
                'search_items' => _x('Search Articles', 'media'),
                'not_found' => _x('No Articles found', 'media'),
                'not_found_in_trash' => _x('No Articles found in Trash', 'media'),
                'parent_item_colon' => _x('Parent Article:', 'media'),
                'menu_name' => _x('Media & Publications', 'media'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Article',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions', 'post-formats'),
                'public' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => true,
                'publicly_queryable' => true,
                'exclude_from_search' => false,
                'has_archive' => true,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-layout'
            );
            register_post_type( Media::this_post_type(), $args );
            register_taxonomy_for_object_type( Media::this_post_type(), 'post-formats' );
        });

    }

    public static function register_faq() {

        add_action( 'init', function() {
            $labels = array(
                'name' => _x('Frequently Asked Questions', 'media'),
                'singular_name' => _x('FAQ', 'media'),
                'add_new' => _x('Add New', 'media'),
                'add_new_item' => _x('Add New FAQ', 'media'),
                'edit_item' => _x('Edit FAQ', 'media'),
                'new_item' => _x('New FAQ', 'media'),
                'view_item' => _x('View FAQ', 'media'),
                'search_items' => _x('Search Frequently Asked Questions', 'media'),
                'not_found' => _x('No Frequently Asked Questions found', 'media'),
                'not_found_in_trash' => _x('No Frequently Asked Questions found in Trash', 'media'),
                'parent_item_colon' => _x('Parent FAQ:', 'media'),
                'menu_name' => _x('Frequently Asked Questions', 'media'),
            );
            $args = array(
                'labels' => $labels,
                'hierarchical' => false,
                'description' => 'Create, edit or remove Article',
                'supports' => array('title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'),
                'public' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'show_in_nav_menus' => true,
                'publicly_queryable' => true,
                'exclude_from_search' => false,
                'has_archive' => true,
                'query_var' => true,
                'can_export' => true,
                'rewrite' => true,
                'capability_type' => 'post',
                'menu_icon' => 'dashicons-sos'
            );
            register_post_type( FAQ::this_post_type(), $args );
        });

    }

    public static function register_gallery() {

        add_action( 'init', function() {
           $labels = array(
               'name' => _x('Gallery', 'gallery'),
               'singular_name' => _x('Post', 'gallery'),
               'add_new' => _x('Add New', 'gallery'),
               'add_new_item' => _x('Add New Post', 'gallery'),
               'edit_item' => _x('Edit Post', 'gallery'),
               'new_item' => _x('New Post', 'gallery'),
               'view_item' => _x('View Post', 'gallery'),
               'search_items' => _x('Search Gallery', 'gallery'),
               'not_found' => _x('No posts found', 'gallery'),
               'not_found_in_trash' => _x('No posts found in Trash', 'gallery'),
               'parent_item_colon' => _x('Parent Post:', 'gallery'),
               'menu_name' => _x('Gallery', 'gallery'),
           );
           $args = array(
               'labels' => $labels,
               'hierarchical' => false,
               'description' => 'Create, edit or remove Gallery Posts',
               'supports' => array('title', 'author', 'excerpt', 'thumbnail', 'revisions'),
               'public' => true,
               'show_ui' => true, 
               'show_in_menu' => true,
               'show_in_nav_menus' => true,
               'publicly_queryable' => true,
               'exclude_from_search' => false,
               'has_archive' => true,
               'query_var' => false,
               'can_export' => true,
               'rewrite' => true,
               'capability_type' => 'post',
               'menu_icon' => 'dashicons-format-gallery'
           );
           register_post_type( Gallery::this_post_type(), $args );
           // add_post_type_support( 'gallery', 'post-formats' );
           // register_taxonomy_for_object_type( 'category', 'gallery' );
        });

        add_action( 'pre_get_posts', function( $query ) {
            if ( !is_admin() && $query->is_main_query() && ( is_post_type_archive( Gallery::this_post_type() ) || is_tax( 'gallery-types' ) ) ) {
                // $query->set( 'posts_per_page', -1 );
                $query->set( 'posts_per_page', 48 );
            }
        } );

    }

}
