<?php
namespace OxygenApp\Hooks;

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

use OxygenApp\Models\BackgroundSound;
use OxygenApp\Models\AdminPlaylist;
use OxygenApp\Models\BackgroundCategory;
use OxygenApp\Views\Admin\Tax\AdminPlaylist as AdminPlaylistView;
use OxygenApp\Hooks\IHook;
use OxygenApp\Models\Background;
use OxygenApp\Views\Admin\Tax\BackgroundCategoryView;

class ActionTaxonomie implements IHook {

    static function register() {
        add_action('init', [self::class, 'registerAdminPlaylists']);
        add_action('init', [self::class, 'registerBackgroundCategories']);

        add_action(AdminPlaylist::TAX . '_add_form_fields', [AdminPlaylistView::class, 'renderOnCreateNew']);
        add_action(AdminPlaylist::TAX . '_edit_form_fields', [AdminPlaylistView::class, 'renderOnEdit'], 10, 2);
        add_action('created_' . AdminPlaylist::TAX, [AdminPlaylist::class, 'onSaveMeta']);
        add_action('edited_' . AdminPlaylist::TAX, [AdminPlaylist::class, 'onSaveMeta']);

        add_action(BackgroundCategory::TAX . '_add_form_fields', [BackgroundCategoryView::class, 'renderOnCreateNew']);
        add_action(BackgroundCategory::TAX . '_edit_form_fields', [BackgroundCategoryView::class, 'renderOnEdit'], 10, 2);
        add_action('created_' . BackgroundCategory::TAX, [BackgroundCategory::class, 'onSaveMeta']);
        add_action('edited_' . BackgroundCategory::TAX, [BackgroundCategory::class, 'onSaveMeta']);
    }

    static function registerAdminPlaylists() {
        register_taxonomy(AdminPlaylist::TAX, BackgroundSound::POST_TYPE, [
            'labels' => [
                'name'              => _x( 'Playlists', 'taxonomy general name', 'oxyleaf-app-working-and-relaxing-app' ),
                'singular_name'     => _x( 'Playlist', 'taxonomy singular name', 'oxyleaf-app-working-and-relaxing-app' ),
                'search_items'      => esc_html__( 'Search Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'all_items'         => esc_html__( 'All Playlists', 'oxyleaf-app-working-and-relaxing-app' ),
                'parent_item'       => esc_html__( 'Parent Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'parent_item_colon' => esc_html__( 'Parent Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'edit_item'         => esc_html__( 'Edit Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'update_item'       => esc_html__( 'Update Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'add_new_item'      => esc_html__( 'Add new Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'new_item_name'     => esc_html__( 'New Playlist', 'oxyleaf-app-working-and-relaxing-app' ),
                'menu_name'         => esc_html__( 'Playlists', 'oxyleaf-app-working-and-relaxing-app' ),
            ],
            'hierarchical'      => false,
            'show_ui'           => true,
            'meta_box_cb'       => false,
            'show_admin_column' => true,
            'query_var'         => true,
            'show_admin_column' => true,
        ]);
    }

    static function registerBackgroundCategories() {
        register_taxonomy(BackgroundCategory::TAX, Background::POST_TYPE, [
            'labels' => [
                'name'              => _x( 'Background categories', 'taxonomy general name', 'oxyleaf-app-working-and-relaxing-app' ),
                'singular_name'     => _x( 'Background category', 'taxonomy singular name', 'oxyleaf-app-working-and-relaxing-app' ),
                'search_items'      => esc_html__( 'Search category', 'oxyleaf-app-working-and-relaxing-app' ),
                'all_items'         => esc_html__( 'All categories', 'oxyleaf-app-working-and-relaxing-app' ),
                'parent_item'       => esc_html__( 'Parent category', 'oxyleaf-app-working-and-relaxing-app' ),
                'parent_item_colon' => esc_html__( 'Parent category', 'oxyleaf-app-working-and-relaxing-app' ),
                'edit_item'         => esc_html__( 'Edit category', 'oxyleaf-app-working-and-relaxing-app' ),
                'update_item'       => esc_html__( 'Update category', 'oxyleaf-app-working-and-relaxing-app' ),
                'add_new_item'      => esc_html__( 'Add new category', 'oxyleaf-app-working-and-relaxing-app' ),
                'new_item_name'     => esc_html__( 'New category', 'oxyleaf-app-working-and-relaxing-app' ),
                'menu_name'         => esc_html__( 'Categories', 'oxyleaf-app-working-and-relaxing-app' ),
            ],
            'hierarchical'      => false,
            'show_ui'           => true,
            'meta_box_cb'       => false,
            'show_admin_column' => true,
            'query_var'         => true,
            'show_admin_column' => true,
        ]);
    }
}