<?php

if(!class_exists('Intense_Post_Type_Books')) {
  class Intense_Post_Type_Books extends Intense_Post_Type {  
    function __construct() {
      global $intense_visions_options;
      $name_singular = ( isset( $intense_visions_options['intense_cpt_books_singular'] ) ? $intense_visions_options['intense_cpt_books_singular'] : __( 'Book', 'intense' ) );    
      $name_plural = ( isset( $intense_visions_options['intense_cpt_books_plural'] ) ? $intense_visions_options['intense_cpt_books_plural'] : __( 'Books', 'intense' ) );
      
      $this->type = 'intense_books';
      $this->title = 'Enter ' . $name_singular . ' Title';
      $this->singular = $name_singular;
      $this->plural = $name_plural;    
      $this->icon = 'dashicons-book-alt';
      $this->category_taxonomy_key = 'intense_book_category';
      $this->hierarchical = true;
      $this->taxonomies = array(
        array(
          'key' => 'intense_book_author',
          'singular' => __( 'Author', "intense" ),
          'plural' => __( 'Authors', "intense" )
        ),
        array(
          'key' => 'intense_book_publisher',
          'singular' => __( 'Publisher', "intense" ),
          'plural' => __( 'Publishers', "intense" )
        )
      );
      $this->fields = array(
        array (
                'key' => 'field_52f6d5ae8n717',
                'label' => __( 'Subtitle', "intense" ),
                'name' => 'intense_book_subtitle',
                'type' => 'text',
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'formatting' => 'html',
                'maxlength' => '',
              ),
              array (
                'key' => 'field_52f6d77g8a712',
                'label' => __( 'Single Post Template', "intense" ),
                'name' => 'intense_books_single_template',
                'type' => 'select',
                'choices' => array_merge(
                  array( '' => '' ),
                  intense_locate_available_plugin_templates('/custom-post/intense_books/single/'),
                  intense_locate_single_cpt_templates( 'books', true )
                ),
                'default_value' => '',
                'allow_null' => 0,
                'multiple' => 0,
              ),
              array (
                'key' => 'field_52f6d9op8n538',
                'label' => __( 'Audio Clip', "intense" ),
                'name' => 'intense_book_audio_clip',
                'type' => 'intense_url',
                'instructions' => __( 'Audio file url. Supported formats: mp3, ogg.', "intense" ),
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'formatting' => 'html',
                'maxlength' => '',
              ),
              array (
                'key' => 'field_52e6y7b2wt32h',
                'label' => __( 'Cover Image', "intense" ),
                'name' => 'intense_book_image',
                'type' => 'image',
                'column_width' => 40,
                'save_format' => 'object',
                'preview_size' => 'thumbnail',
                'library' => 'all',
                'is_post_type_image' => 1
              ),
              array (
                'key' => 'field_52d60hhee7539',
                'label' => __( 'Website', 'intense' ),
                'name' => 'intense_book_website',
                'type' => 'intense_url',
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'formatting' => 'html',
                'maxlength' => ''
              ),
              array (
                'key' => 'field_52d60ffee7540',
                'label' => __( 'Purchase Link', 'intense' ),
                'name' => 'intense_book_purchase_link',
                'type' => 'intense_url',
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'formatting' => 'html',
                'maxlength' => '',
              ),
              array (
                'key' => 'field_52f6c581e5hy9',
                'label' => __( 'Languages', "intense" ),
                'name' => 'intense_book_languages',
                'type' => 'repeater',
                'instructions' => __( 'Enter languages that the book is released in (English, Spanish, etc...)', "intense" ),
                'sub_fields' => array (
                  array (
                    'key' => 'field_52f6c581e5hy0',
                    'label' => __( 'Language', "intense" ),
                    'name' => 'intense_book_language',
                    'type' => 'text',
                    'column_width' => 100,
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'formatting' => 'html',
                    'maxlength' => '',
                  ),
                ),
                'row_min' => '',
                'row_limit' => '',
                'layout' => 'table',
                'button_label' => __( 'Add Language', "intense" ),
              ),
              array (
                'key' => 'field_52f6d30d8a710',
                'label' => __( 'Excerpt', "intense" ),
                'name' => 'intense_book_excerpt',
                'type' => 'textarea',
                'default_value' => '',
                'placeholder' => '',
                'maxlength' => '',
                'formatting' => 'br',
              ),
              array (
                'key' => 'field_52f6d4448a712',
                'label' => __( 'Type(s)', "intense" ),
                'name' => 'intense_book_types',
                'type' => 'select',
                'choices' => array (
                  'Hardcover' => __( 'Hardcover', "intense" ),
                  'Paperback' => __( 'Paperback', "intense" ),
                  'Audiobook' => __( 'Audiobook', "intense" ),
                  'Audio CD' => __( 'Audio CD', "intense" ),
                  'Kindle' => __( 'Kindle', "intense" ),
                  'Audible Audio Edition' => __( 'Audible Audio Edition', "intense" ),
                  'Printed Access Code' => __( 'Printed Access Code', "intense" ),
                  'HTML' => __( 'HTML', "intense" ),
                  'PDF' => __( 'PDF', "intense" ),
                  'Board Book' => __( 'Board Book', "intense" ),
                  'Audio Cassette' => __( 'Audio Cassette', "intense" ),
                ),
                'default_value' => '',
                'allow_null' => 0,
                'multiple' => 1,
              ),
              array (
                'key' => 'field_52f6d4e08a713',
                'label' => __( 'Release Date', "intense" ),
                'name' => 'intense_book_release_date',
                'type' => 'date_picker',
                'date_format' => 'yymmdd',
                'display_format' => 'mm/dd/yy',
                'first_day' => 0,
              ),
              array (
                'key' => 'field_52f6d5ae8a717',
                'label' => __( 'Recommended Age', "intense" ),
                'name' => 'intense_book_recommended_age',
                'type' => 'text',
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'formatting' => 'html',
                'maxlength' => '',
              ),
              array (
                'key' => 'field_52f6d88o8a30c',
                'label' => __( 'Back Cover Text', "intense" ),
                'name' => 'intense_book_back_cover',
                'type' => 'textarea',
                'column_width' => 45,
                'default_value' => '',
                'placeholder' => '',
                'maxlength' => '',
                'formatting' => 'br',
              ),
              array (
                'key' => 'field_52f6d50b8a714',
                'label' => __( 'Awards', "intense" ),
                'name' => 'intense_book_awards',
                'type' => 'repeater',
                'sub_fields' => array (
                  array (
                    'key' => 'field_52f6d5228a715',
                    'label' => __( 'Name', "intense" ),
                    'name' => 'intense_book_award_name',
                    'type' => 'text',
                    'column_width' => 40,
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'formatting' => 'html',
                    'maxlength' => '',
                  ),
                  array (
                    'key' => 'field_52f6d5478a716',
                    'label' => __( 'Description', "intense" ),
                    'name' => 'intense_book_award_description',
                    'type' => 'textarea',
                    'column_width' => 60,
                    'default_value' => '',
                    'placeholder' => '',
                    'maxlength' => '',
                    'formatting' => 'br',
                  ),
                ),
                'row_min' => '',
                'row_limit' => '',
                'layout' => 'table',
                'button_label' => __( 'Add Award', "intense" ),
              ),
              array (
                'key' => 'field_52f6d6528a718',
                'label' => __( 'Reviews', "intense" ),
                'name' => 'intense_book_reviews',
                'type' => 'repeater',
                'sub_fields' => array (
                  array (
                    'key' => 'field_52f6d6728a719',
                    'label' => __( 'Reviewer', "intense" ),
                    'name' => 'intense_book_reviewer',
                    'type' => 'text',
                    'column_width' => 30,
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'formatting' => 'html',
                    'maxlength' => '',
                  ),
                  array (
                    'key' => 'field_52f6d6ba8a71a',
                    'label' => __( 'Review Date', "intense" ),
                    'name' => 'intense_book_review_date',
                    'type' => 'date_picker',
                    'column_width' => 15,
                    'date_format' => 'yymmdd',
                    'display_format' => 'mm/dd/yy',
                    'first_day' => 0,
                  ),
                  array (
                    'key' => 'field_52f6d7528a71b',
                    'label' => __( 'Rating', "intense" ),
                    'name' => 'intense_book_rating',
                    'type' => 'number',
                    'column_width' => 10,
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'min' => 0,
                    'max' => 5,
                    'step' => '.5',
                  ),
                  array (
                    'key' => 'field_52f6d79a8a71c',
                    'label' => __( 'Review', "intense" ),
                    'name' => 'intense_book_review',
                    'type' => 'textarea',
                    'column_width' => 45,
                    'default_value' => '',
                    'placeholder' => '',
                    'maxlength' => '',
                    'formatting' => 'br',
                  ),
                ),
                'row_min' => '',
                'row_limit' => '',
                'layout' => 'table',
                'button_label' => __( 'Add Review', "intense" ),
              ),
      );
    }

    public function get_subtitle() {
      return get_field('intense_book_subtitle');
    }
  }
}
