<?php
if (!defined('ABSPATH')) {
    exit;
}
/**
 * Define the internationalization functionality.
 *
 * Loads and defines the internationalization files for this plugin
 * so that it is ready for translation.
 *
 * @since      1.0.0
 * @package    Media_Blaster
 * @subpackage Media_Blaster/includes
 * @author     Your Name <email@example.com>
 */
class Wp_Smart_Tv_series_meta
{

    public function __construct()
    {
        $this->get_metabox();
    }

    private function get_metabox()
    {
        global $wpstv_tools;

        $tv_settings = get_option('rovidx_smart_tv_options');

        $prefix = 'rovidx_smarttv_';
        /**
         * Metabox to add fields to categories and tags
         */
        $cmb = new_cmb2_box(array(
            'id' => $prefix . 'edit',
            'title' => esc_html__('WP Smart TV Info', 'wp-smart-tv'), // Doesn't output for term boxes
            'object_types' => array('series'), // Tells CMB2 to use term_meta vs post_meta
            //'taxonomies'       => array( 'series' ), // Tells CMB2 which taxonomies should have these fields
            // 'new_term_section' => true, // Will display in the "Add New Category" section
        ));


        $cmb->add_field(array(
            'id' => $prefix . 'series_type',
            'name' => esc_html__('Type of Series', 'wp-smart-tv'),
            'desc' => esc_html__('Multiple seasons or mini-series', 'wp-smart-tv'),
            'type' => 'select',
            'options' => array(
                'miniseries' => esc_html__('Mini-Series', 'wp-smart-tv'),
                'seasons' => esc_html__('Multiple Seasons', 'wp-smart-tv')
            ),
            'sanitization_cb' => 'sanitize_text_field',
        ));

        $cmb->add_field(array(
            'name' => esc_html__('Release Date', 'wp-smart-tv'),
            'id' => $prefix . 'series_release_date',
            'type' => 'text_date',
            'desc' => esc_html__('YYYY-mm-dd', 'wp-smart-tv'),
            // 'timezone_meta_key' => 'wiki_test_timezone',
            'date_format' => 'Y-m-d',
            'attributes' => array(
                'data-datepicker' => json_encode(array(
                    'yearRange' => '1900:' . (date('Y'))
                )),
                'data-validation' => 'required',
            ),
            'sanitization_cb' => 'sanitize_text_field',
        ));

        $cmb->add_field(array(
            'name' => esc_html__('Choose Content', 'wp-smart-tv'),
            'desc' => esc_html__('Drag posts from the left column to the right column to attach them to this Playlist.', 'wp-smart-tv'),
            'id' => $prefix . 'playlist',
            'type' => 'custom_attached_posts',
            'options' => array(
                'show_thumbnails' => true, // Show thumbnails on the left
                'filter_boxes' => true, // Show a text box for filtering the results
                'query_args' => array(
                    'posts_per_page' => 200,
                    'post_type' => array('episodes'),
                ), // override the get_posts args
            ),
            'attributes' => array(
                'data-validation' => 'required',
            ),
        ));

        $cmb->add_field(array(
            'name' => esc_html__('Series Thumbnail', 'wp-smart-tv'),
            'desc' => esc_html__('Minimum of 800px by 450px', 'wp-smart-tv'),
            'id' => $prefix . 'series_thumb',
            'type' => 'file',
            'preview_size' => array(225, 400),
            'options' => array(
                'url' => false, // Hide the text input for the url
            ),
            'attributes' => array(
                'data-validation' => 'required',
            ),
            'sanitization_cb' => 'esc_url_raw',
        ));

        $cmb->add_field(array(
            'name' => esc_html__('Genres', 'wp-smart-tv'),
            //'desc'    => '',
            'id' => $prefix . 'series_genres',
            'type' => 'multicheck_inline',
            'select_all_button' => false,
            'options' => $wpstv_tools->get_genre_list(),
            'attributes' => array(
                'data-validation' => 'required',
            ),
            'sanitization_cb' => 'wpstv_sanitize_string_array',

        ));

        // Episode Meta's
        $box = new_cmb2_box(array(
            'id' => $prefix . 'episode_metabox',
            'title' => '<i class="fas fa-television" aria-hidden="true"></i> ' . esc_html__('Series Information', 'wp-smart-tv'),
            'object_types' => array('episodes'), // Post type
            // 'show_on_cb' => 'rovidx_smart_tv_show_if_front_page', // function should return a bool value
            'context' => 'side',
            //'priority'   => 'high',
            // 'show_names' => true, // Show field names on the left
            'cmb_styles' => true, // false to disable the CMB stylesheet
            // 'closed'     => true, // true to keep the groups closed by default
            //'classes'    => 'rovidx-admin-meta', // Extra cmb2-wrap classes
            //'classes_cb' => 'rovidx-smarttv-videodata', // Add classes through a callback.
        ));

        $box->add_field(array(
            'name' => esc_html__('Season', 'wp-smart-tv'),
            'desc' => esc_html__('Leave blank for Mini Series', 'wp-smart-tv'),
            'id' => $prefix . 'se_no',
            'type' => 'text',
            'column' => array(
                'position' => 2,
            ),
            'attributes' => array(
                'type' => 'number',
                'pattern' => '\d*',
            ),
            'sanitization_cb' => 'absint',
        ));

        $box->add_field(array(
            'name' => esc_html__('Episode Number', 'wp-smart-tv'),
            //'desc'       => esc_html__( 'URL of the Media.  Tested with Vimeo Pro (HLS), Amazon S3 with CloudFront and Self-Hosted video files', 'wp-smart-tv' ),
            'id' => $prefix . 'ep_no',
            'type' => 'text',
            'column' => array(
                'position' => 3,
            ),
            'attributes' => array(
                'type' => 'number',
                'pattern' => '\d*',
            ),
            'sanitization_cb' => 'absint',
        ));
    }

    public function get_genre_list()
    {
        return array(
            'action' => 'Action',
            'adventure' => 'Adventure',
            'animals' => 'Animals',
            'animated' => 'Animated',
            'anime' => 'Anime',
            'children' => 'Children',
            'comedy' => 'Comedy',
            'crime' => 'Crime',
            'documentary' => 'Documentary',
            'drama' => 'Drama',
            'educational' => 'Educational',
            'fantasy' => 'Fantasy',
            'faith' => 'Faith',
            'food' => 'Food',
            'fashion' => 'Fashion',
            'gaming' => 'Gaming',
            'health' => 'Health',
            'history' => 'History',
            'horror' => 'Horror',
            'miniseries' => 'Mini Series',
            'mystery' => 'Mystery',
            'nature' => 'Nature',
            'news' => 'News',
            'reality' => 'Reality',
            'romance' => 'Romance',
            'science' => 'Science',
            'science fiction' => 'Science Fiction',
            'sitcom' => 'Sitcom',
            'special' => 'Special',
            'sports' => 'Sports',
            'thriller' => 'Thriller',
            'technology' => 'Technology',
        );
    }
}
