<?php

/**
 * The main class for Settings configurations.
 *
 * @package greet-bubble
 * @subpackage greet-bubble/src/Admin/Views
 */

namespace ThemeAtelier\GreetBubble\Admin\Views;

use ThemeAtelier\GreetBubble\Admin\Framework\Classes\GREET_BUBBLE;
use ThemeAtelier\GreetBubble\Includes\Helpers;

if (! defined('ABSPATH')) {
	die;
} // Cannot access pages directly.

/**
 * Settings.
 */
class AssignBubble
{
	/**
	 * Returns all public taxonomy terms as term_id => "Taxonomy Label: Term Name".
	 *
	 * @return array
	 */
	public static function get_all_taxonomy_terms()
	{
		return greet_bubble_get_taxonomy_terms();
	}

	/**
	 * Create a settings page.
	 *
	 * @param string $prefix The settings.
	 * @return void
	 */
	public static function settings($prefix)
	{
		$capability = Helpers::greet_bubble_dashboard_capability();
		GREET_BUBBLE::createOptions(
			$prefix,
			array(
				'menu_title'       => esc_html__('Global Settings', 'greet-bubble'),
				'menu_type'        => 'submenu', // menu, submenu, options, theme, etc.
				'menu_slug'        => 'assign-bubble',
				'theme'            => 'light',
				'show_all_options' => false,
				'show_reset_all'   => false,
				'show_search'      => false,
				'show_footer'      => false,
				'show_bar_menu'    => false,
				'framework_title'  => esc_html__('Settings', 'greet-bubble'),
				'menu_capability'  => $capability,
			)
		);
		GREET_BUBBLE::createSection(
			$prefix,
			array(
				'name'   => 'assign_bubble',
				'title'  => __('Bubble', 'greet-bubble'),
				'fields' => array(
					array(
						'type'    => 'submessage',
						'content' => esc_html__('Assign bubble based on posts.', 'greet-bubble') . ' <a href="https://docs.themeatelier.net/docs/greet-bubble-pro/" target="_blank">' . esc_html__('See Docs', 'greet-bubble') . '</a>',
					),
					array(
						'id'                     => 'assign_bubble_data',
						'type'                   => 'group',
						'button_title'           => __('Add New', 'greet-bubble'),
						'accordion_title_prefix' => __('Assign Bubble:', 'greet-bubble'),
						'accordion_title_number' => true,
						'max' => 1,
						'fields'                 => array(
							array(
								'id'      => 'select_by',
								'type'    => 'button_set',
								'title'   => __('Select By', 'greet-bubble'),
								'options' => array(
									'posts'    => array('text' => __('Specific Post(s)', 'greet-bubble')),
									'taxonomy' => array('text' => __('Categories/Taxonomies', 'greet-bubble')),
								),
								'default' => 'posts',
							),
							array(
								'id'            => 'bubble_post_type',
								'type'          => 'select',
								'title'         => __('Post Type', 'greet-bubble'),
								'options'       => 'post_type',
								'class'         => 'ta_bubble_post_type',
								'multiple_type' => true,
								'attributes'    => array(
									'placeholder' => __('Select Post Type', 'greet-bubble'),
									'style'       => 'min-width: 150px;',
								),
								'default'       => 'post',
								'dependency'  => array('select_by', '!=', 'taxonomy'),
							),

							array(
								'id'         => 'bubble_taxonomy_terms',
								'type'       => 'select',
								'title'      => __('Select Taxonomy Terms', 'greet-bubble'),
								'options'    => 'greet_bubble_get_taxonomy_terms',
								'multiple'   => true,
								'chosen'     => true,
								'placeholder' => __('Choose Terms', 'greet-bubble'),
								'dependency' => array('select_by', '==', 'taxonomy'),
							),
							array(
								'id'          => 'bubble_specific_posts',
								'type'        => 'select',
								'title'       => __('Select Post(s)', 'greet-bubble'),
								'options'     => 'posts',
								'title_help'        => __('Choose the posts to display. Sort the posts position by drag & drop.', 'greet-bubble'),
								'chosen'      => true,
								'sortable'    => false,
								'ajax'        => true,
								'class'       => 'ta_bubble_specific_posts',
								'multiple'    => true,
								'placeholder' => __('Choose Posts', 'greet-bubble'),
								'query_args'  => array(
									'posts_per_page' => -1,
									'cache_results'  => false,
									'no_found_rows'  => true,
								),
								'dependency'  => array('select_by', '!=', 'taxonomy'),
							),
							array(
								'id'          => 'select_bubble',
								'class'          => 'select_bubble',
								'type'        => 'select',
								'title'       => __('Select Bubble', 'greet-bubble'),
								'options'     => 'posts',
								'title_help'  => __('Choose the posts to display.', 'greet-bubble'),
								'empty_message' => wp_kses_post(
									sprintf(
										__('No bubbles created. Please create a bubble first. <a href="%s">Create Bubble</a>', 'greet-bubble'),
										esc_url(admin_url('edit.php?post_type=manage_bubble'))
									)
								),
								'placeholder' => __('Choose Bubble', 'greet-bubble'),
								'query_args'  => array(
									'post_type'		 => 'manage_bubble',
									'posts_per_page' => -1,
									'cache_results'  => false,
									'no_found_rows'  => true,
								),
							),
						),
					),
				),
			)
		);
	}
}
