<?php
namespace ShopyPress\Hooks;
if ( ! defined( 'ABSPATH' ) ) exit;

use ShopyPress\Hooks\IHook;
use ShopyPress\Models\ShopyPressProduct;
use ShopyPress\Utils\OptionUtils;

class ActionCpt implements IHook {

    static function register() {
        add_action('init', [self::class, 'registerCpt']);
        add_action('init', [self::class, 'registerTaxonomy']);
    }

    static function registerCpt() {
        $labels = [
            'name'                  => _x('Shopify Products', 'Post type general name', 'synckube-products-sync-for-shopify'),
            'singular_name'         => _x('Shopify Product', 'Post type singular name', 'synckube-products-sync-for-shopify'),
            'menu_name'             => _x('Shopify Products', 'Admin Menu text', 'synckube-products-sync-for-shopify'),
            'name_admin_bar'        => _x('Shopify Product', 'Add New on Toolbar', 'synckube-products-sync-for-shopify'),
            'add_new'               => __('Add New', 'synckube-products-sync-for-shopify'),
            'add_new_item'          => __('Add New Shopify Product', 'synckube-products-sync-for-shopify'),
            'new_item'              => __('New Shopify Product', 'synckube-products-sync-for-shopify'),
            'edit_item'             => __('Edit Shopify Product', 'synckube-products-sync-for-shopify'),
            'view_item'             => __('View Shopify Product', 'synckube-products-sync-for-shopify'),
            'all_items'             => __('All Shopify Products', 'synckube-products-sync-for-shopify'),
            'search_items'          => __('Search Shopify Products', 'synckube-products-sync-for-shopify'),
            'parent_item_colon'     => __('Parent Shopify Products:', 'synckube-products-sync-for-shopify'),
            'not_found'             => __('No Shopify products found.', 'synckube-products-sync-for-shopify'),
            'not_found_in_trash'    => __('No Shopify products found in Trash.', 'synckube-products-sync-for-shopify'),
            'archives'              => _x('Shopify Product archives', 'The post type archive label used in nav menus.', 'synckube-products-sync-for-shopify'),
            'insert_into_item'      => _x('Insert into Shopify product', 'Overrides the "Insert into post" phrase.', 'synckube-products-sync-for-shopify'),
            'uploaded_to_this_item' => _x('Uploaded to this Shopify product', 'Overrides the "Uploaded to this post" phrase.', 'synckube-products-sync-for-shopify'),
            'filter_items_list'     => _x('Filter Shopify products list', 'Screen reader text for the filter links.', 'synckube-products-sync-for-shopify'),
            'items_list_navigation' => _x('Shopify products list navigation', 'Screen reader text for the pagination.', 'synckube-products-sync-for-shopify'),
            'items_list'            => _x('Shopify products list', 'Screen reader text for the items list.', 'synckube-products-sync-for-shopify'),
        ];

        $args = [
            'labels'             => $labels,
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'query_var'          => true,
            'rewrite'            => ['slug' => OptionUtils::getInstance()->getOption('shopypress_product_rewrite', ShopyPressProduct::DEFAULT_REWRITE)],
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'menu_icon'          => 'dashicons-cart',
            'supports'           => ['title', 'thumbnail', 'custom-fields'],
            'show_in_rest'       => true,
        ];

        register_post_type(ShopyPressProduct::PRODUCT_SLUG, $args);
    }

    static function registerTaxonomy() {
        $labels = [
            'name'              => _x('Product Collections', 'taxonomy general name', 'synckube-products-sync-for-shopify'),
            'singular_name'     => _x('Product Collection', 'taxonomy singular name', 'synckube-products-sync-for-shopify'),
            'search_items'      => __('Search Product Collections', 'synckube-products-sync-for-shopify'),
            'all_items'         => __('All Product Collections', 'synckube-products-sync-for-shopify'),
            'parent_item'       => __('Parent Product Collection', 'synckube-products-sync-for-shopify'),
            'parent_item_colon' => __('Parent Product Collection:', 'synckube-products-sync-for-shopify'),
            'edit_item'         => __('Edit Product Collection', 'synckube-products-sync-for-shopify'),
            'update_item'       => __('Update Product Collection', 'synckube-products-sync-for-shopify'),
            'add_new_item'      => __('Add New Product Collection', 'synckube-products-sync-for-shopify'),
            'new_item_name'     => __('New Product Collection Name', 'synckube-products-sync-for-shopify'),
            'menu_name'         => __('Product Collections', 'synckube-products-sync-for-shopify'),
        ];

        $args = [
            'hierarchical'      => true,
            'labels'            => $labels,
            'show_ui'           => true,
            'show_admin_column' => true,
            'query_var'         => true,
            'rewrite'           => ['slug' => OptionUtils::getInstance()->getOption('shopypress_collection_rewrite', ShopyPressProduct::DEFAULT_COLLECTION_REWRITE)],
            'show_in_rest'      => true,
        ];

        register_taxonomy(ShopyPressProduct::COLLECTION_TAXONOMY, [ShopyPressProduct::PRODUCT_SLUG], $args);
    }
}