<?php
namespace SabaiApps\Directories\Component\Display\Helper;

use SabaiApps\Directories\Application;
use SabaiApps\Directories\Exception;
use SabaiApps\Directories\Component\Form\Form;
use SabaiApps\Directories\Component\Display\Model\Display;
use SabaiApps\Directories\Component\Display\Model\Element;
use SabaiApps\Directories\Component\Entity\Model\Bundle;

class ElementFormHelper {

	public function help( Application $application, Display $display, $element, $action, ?array $submittedValues = null, ?Display $altDisplay = null ) {
		$_display = isset( $altDisplay ) ? $altDisplay : $display;

		if ( $element instanceof Element ) {
			$element_name = $element->name;
			$element_id   = $element->id;
			$element_data = (array) $element->data;
			$is_edit      = true;
			unset( $element );
		} else {
			$element_name = $element;
			$element_data = array();
			$is_edit      = false;
		}

		// Get bundle and element
		if ( ! $bundle = $application->Entity_Bundle( $_display->bundle_name ) ) {
			throw new Exception\RuntimeException( 'Invalid bundle: ' . $_display->bundle_name );
		}
		if ( ! $element = $application->Display_Elements_impl( $bundle, $element_name, true, false ) ) {
			throw new Exception\RuntimeException( 'Invalid display element: ' . $element_name );
		}

		if ( ! $element->displayElementSupports( $bundle, $_display ) ) {
			throw new Exception\RuntimeException( 'The element is not supported: ' . $element_name );
		}

		// Define form
		$form = array(
			'#header'           => array(),
			'#action'           => $application->Url( $action ),
			'#token_reuseable'  => true,
			'#enable_storage'   => true,
			'#bundle'           => $bundle,
			'#element_name'     => $element_name,
			'#inherits'         => array(
				'display_admin_add_element_' . strtolower( $element_name ),
			),
			'#element_validate' => array(
				array( __CLASS__, '_filterSettings' ),
			),
			'#tab_style'        => 'pill',
			'#tabs'             => array(
				'general' => array(
					'#active' => true,
					'#title'  => _x( 'General', 'settings tab', 'directories-pro' ),
					'#weight' => 1,
				),
			),
			'general'           => array(
				'#tree'   => true,
				'#tab'    => 'general',
				'#weight' => 1,
			),
			'display_id'        => array(
				'#type'  => 'hidden',
				'#value' => $display->id,
			),
		);
		if ( isset( $element_id ) ) {
			$form['element_id'] = array(
				'#type'  => 'hidden',
				'#value' => $element_id,
			);
		} else {
			$form['element']   = array(
				'#type'  => 'hidden',
				'#value' => $element_name,
			);
			$form['parent_id'] = array(
				'#type'  => 'hidden',
				'#id'    => 'drts-display-add-element-parent',
				'#value' => null,
			);
		}
		if ( isset( $altDisplay ) ) {
			$form['alt_display_id'] = array(
				'#type'  => 'hidden',
				'#value' => $altDisplay->id,
			);
		}

		$tab_weight    = 5;
		$info          = $element->displayElementInfo( $bundle );
		$settings      = isset( $element_data['settings'] ) ? $element_data['settings'] : array();
		$settings     += (array) $info['default_settings'];
		$settings_form = (array) @$element->displayElementSettingsForm(
			$bundle,
			$settings,
			$_display,
			array( 'general', 'settings' ),
			null,
			$is_edit,
			isset( $submittedValues['settings'] ) ? $submittedValues['settings'] : array()
		);
		// Labels
		$labellable = $_display->type === 'entity'
			&& strpos( $_display->name, 'summary' ) === 0 // only for Summary displays
			&& ! empty( $info['labellable'] );
		if ( $labellable ) {
			$labels_states                    = array(
				'visible' => array(
					'input[name="general[settings][_labels][enable]"]' => array(
						'type'  => 'checked',
						'value' => true,
					),
				),
			);
			$settings_form['#tabs']['labels'] = array(
				'#title'  => _x( 'Labels', 'settings tab', 'directories-pro' ),
				'#states' => $labels_states,
			);
			$settings_form['_labels']         = array(
				'enable'      => array(
					'#type'          => 'checkbox',
					'#title'         => __( 'Show overlay labels', 'directories-pro' ),
					'#horizontal'    => true,
					'#default_value' => ! empty( $settings['_labels']['enable'] ),
				),
				'arrangement' => array(
					'#type'          => 'sortablecheckboxes',
					'#horizontal'    => true,
					'#options'       => $options = $application->Display_Labels_options( $bundle ),
					'#default_value' => isset( $settings['_labels']['arrangement'] ) ? $settings['_labels']['arrangement'] : array_keys( $options ),
					'#states'        => $labels_states,
				),
				'style'       => array(
					'#title'         => __( 'Label style', 'directories-pro' ),
					'#type'          => 'select',
					'#horizontal'    => true,
					'#options'       => array(
						''     => __( 'Default', 'directories-pro' ),
						'pill' => __( 'Oval', 'directories-pro' ),
					),
					'#default_value' => isset( $settings['_labels']['style'] ) ? $settings['_labels']['style'] : '',
					'#states'        => $labels_states,
				),
				'position'    => array(
					'#title'         => __( 'Label position', 'directories-pro' ),
					'#type'          => 'select',
					'#horizontal'    => true,
					'#options'       => array(
						'tl' => __( 'Top left', 'directories-pro' ),
						'tr' => __( 'Top right', 'directories-pro' ),
						'bl' => __( 'Bottom left', 'directories-pro' ),
						'br' => __( 'Bottom right', 'directories-pro' ),
					),
					'#default_value' => isset( $settings['_labels']['position'] ) ? $settings['_labels']['position'] : 'tl',
					'#states'        => $labels_states,
				),
			);
		}
		// Buttons
		$buttonable = $_display->type === 'entity'
			&& strpos( $_display->name, 'summary' ) === 0 // only for Summary displays
			&& ! empty( $info['buttonable'] );
		if ( $buttonable ) {
			$buttons_states                           = array(
				'visible' => array(
					'input[name="general[settings][_buttons][enable]"]' => array(
						'type'  => 'checked',
						'value' => true,
					),
				),
			);
			list($buttons_options, $buttons_defaults) = $application->Display_Buttons_options( $bundle, true );
			$settings_form['#tabs']['buttons']        = array(
				'#title'  => _x( 'Buttons', 'settings tab', 'directories-pro' ),
				'#states' => $buttons_states,
			);
			$settings_form['_buttons']                = array(
				'enable'      => array(
					'#type'          => 'checkbox',
					'#title'         => __( 'Show overlay buttons', 'directories-pro' ),
					'#horizontal'    => true,
					'#default_value' => ! empty( $settings['_buttons']['enable'] ),
				),
				'arrangement' => array(
					'#type'          => 'sortablecheckboxes',
					'#horizontal'    => true,
					'#options'       => $buttons_options,
					'#default_value' => isset( $settings['_buttons']['arrangement'] ) ? $settings['_buttons']['arrangement'] : $buttons_defaults,
					'#states'        => $buttons_states,
				),
				'position'    => array(
					'#title'         => __( 'Button position', 'directories-pro' ),
					'#type'          => 'select',
					'#horizontal'    => true,
					'#options'       => array(
						'tl' => __( 'Top left', 'directories-pro' ),
						'tr' => __( 'Top right', 'directories-pro' ),
						'bl' => __( 'Bottom left', 'directories-pro' ),
						'br' => __( 'Bottom right', 'directories-pro' ),
					),
					'#default_value' => isset( $settings['_buttons']['position'] ) ? $settings['_buttons']['position'] : 'tl',
					'#states'        => $buttons_states,
				),
				'hover'       => array(
					'#type'          => 'checkbox',
					'#title'         => __( 'Show buttons on hover only', 'directories-pro' ),
					'#horizontal'    => true,
					'#default_value' => ! empty( $settings['_buttons']['hover'] ),
					// '#switch' => false,
					'#states'        => $buttons_states,
				),
			);
		}
		// Icons
		$iconable = $_display->type === 'entity'
			&& strpos( $_display->name, 'summary' ) === 0 // only for Summary displays
			&& ! empty( $info['iconable'] );
		if ( $iconable ) {
			list($icons_options, $icons_defaults) = $application->Display_Icons_options( $bundle, $display );
			$icons_states                         = array(
				'visible' => array(
					'input[name="general[settings][_icons][enable]"]' => array(
						'type'  => 'checked',
						'value' => true,
					),
				),
			);
			$settings_form['#tabs']['icons']      = array(
				'#title'  => _x( 'Icons', 'settings tab', 'directories-pro' ),
				'#states' => $icons_states,
			);
			$settings_form['_icons']              = array(
				'enable'      => array(
					'#type'          => 'checkbox',
					'#title'         => __( 'Show overlay icons', 'directories-pro' ),
					'#horizontal'    => true,
					'#default_value' => ! empty( $settings['_icons']['enable'] ),
				),
				'arrangement' => array(
					'#type'          => 'sortablecheckboxes',
					'#horizontal'    => true,
					'#options'       => $icons_options,
					'#default_value' => isset( $settings['_icons']['arrangement'] ) ? $settings['_icons']['arrangement'] : $icons_defaults,
					'#states'        => $icons_states,
				),
				'size'        => array(
					'#title'         => __( 'Icon size', 'directories-pro' ),
					'#type'          => 'select',
					'#horizontal'    => true,
					'#options'       => $application->System_Icon_sizeOptions(),
					'#default_value' => isset( $settings['_icons']['size'] ) ? $settings['_icons']['size'] : 'sm',
					'#states'        => $icons_states,
				),
				'position'    => array(
					'#title'         => __( 'Icon position', 'directories-pro' ),
					'#type'          => 'select',
					'#horizontal'    => true,
					'#options'       => array(
						'tl' => __( 'Top left', 'directories-pro' ),
						'tr' => __( 'Top right', 'directories-pro' ),
						'bl' => __( 'Bottom left', 'directories-pro' ),
						'br' => __( 'Bottom right', 'directories-pro' ),
					),
					'#default_value' => isset( $settings['_icons']['position'] ) ? $settings['_icons']['position'] : 'tl',
					'#states'        => $icons_states,
				),
			);
		}
		if ( ! empty( $settings_form ) ) {
			if ( isset( $settings_form['#tabs'] ) ) {
				$form['settings'] = array(
					'#tree'                => true,
					'#tree_allow_override' => false,
					'#weight'              => 2,
				);
				foreach ( $settings_form['#tabs'] as $tab_name => $tab_info ) {
					if ( $tab_name === 'labels'
						&& $labellable
					) {
						$_settings_form = $application->Display_Labels_settingsForm(
							$bundle,
							isset( $settings['labels'] ) ? $settings['labels'] : array(),
							array( 'settings', $tab_name ),
							array( 'general', 'settings', '_labels', 'arrangement' )
						);
					} elseif ( $tab_name === 'buttons'
						&& $buttonable
					) {
						$_settings_form = $application->Display_Buttons_settingsForm(
							$bundle,
							isset( $settings['buttons'] ) ? $settings['buttons'] : array(),
							$display->name,
							array( 'settings', $tab_name ),
							array( 'general', 'settings', '_buttons', 'arrangement' ),
							true
						);
					} elseif ( $tab_name === 'icons'
						&& $iconable
					) {
						$_settings_form = $application->Display_Icons_settingsForm(
							$bundle,
							isset( $settings['icons'] ) ? $settings['icons'] : array(),
							$display,
							array( 'settings', $tab_name ),
							array( 'general', 'settings', '_icons', 'arrangement' ),
							true
						);
					} else {
						$_settings_form = (array) @$element->displayElementSettingsForm(
							$bundle,
							$settings,
							$_display,
							array( 'settings', $tab_name ),
							$tab_name,
							$is_edit,
							isset( $submittedValues['settings'][ $tab_name ] ) ? $submittedValues['settings'][ $tab_name ] : array()
						);
					}
					if ( ! $_settings_form ) {
						continue;
					}

					$_tab_name                     = 'settings-' . $tab_name;
					$form['settings'][ $tab_name ] = array(
						'#tab' => $_tab_name,
					) + $_settings_form;
					if ( is_string( $tab_info ) ) {
						$tab_info = array(
							'#title' => $tab_info,
						);
					}
					if ( ! isset( $tab_info['#weight'] ) ) {
						$tab_info['#weight'] = $tab_weight += 5;
					}
					if ( isset( $form['#tabs'][ $_tab_name ] ) ) {
						$form['#tabs'][ $_tab_name ]             += $tab_info;
						$form['#tabs'][ $_tab_name ]['#disabled'] = false;
					} else {
						$form['#tabs'][ $_tab_name ] = $tab_info;
					}
				}
				unset( $settings_form['#tabs'] );
			}
			if ( isset( $settings_form['#header'] ) ) {
				$form['#header'] += (array) $settings_form['#header'];
				unset( $settings_form['#header'] );
			}
			$form['general']['settings']  = array(
				'#tree'                => true,
				'#tree_allow_override' => false,
				'#type'                => 'fieldset',
				'#weight'              => 10,
			);
			$form['general']['settings'] += $settings_form;
		} else {
			$form['#tabs']['general']['#disabled'] = true;
		}

		// Heading settings
		if ( ! isset( $info['headingable'] )
			|| false !== $info['headingable']
		) {
			$label_settings  = isset( $element_data['heading'] ) ? $element_data['heading'] : ( isset( $info['headingable'] ) && is_array( $info['headingable'] ) ? $info['headingable'] : array() );
			$form['heading'] = $application->Display_ElementLabelSettingsForm( $label_settings, array( 'heading' ), false );
			if ( $_display->type === 'entity' ) {
				$form['heading']['label_custom']['#description']           = $application->System_Util_availableTags(
					$application->Entity_Tokens(
						$bundle,
						true,
						array(
							'site'           => true,
							'current_user'   => true,
							'auto_increment' => true,
						)
					)
				);
				$form['heading']['label_custom']['#description_no_escape'] = true;
			}
		}

		// Visibility settings
		if ( ! empty( $bundle->info['parent'] )
			|| ! empty( $bundle->info['parent_field'] )
		) {
			if ( ! isset( $info['can_hide_on_parent'] )
				|| $info['can_hide_on_parent']
			) {
				$form['visibility']['hide_on_parent'] = array(
					'#title'         => __( 'Hide on parent content page', 'directories-pro' ),
					'#type'          => 'checkbox',
					'#default_value' => ! empty( $element_data['visibility']['hide_on_parent'] ),
					'#weight'        => 50,
				);
			}
		}
		if ( $_display->type === 'entity' ) {
			if ( $bundle->entitytype_name === 'post' ) {
				$form['visibility']['author_only'] = array(
					'#type'          => 'checkbox',
					'#title'         => __( 'Visible to item author only', 'directories-pro' ),
					'#default_value' => ! empty( $element_data['visibility']['author_only'] ),
					'#horizontal'    => true,
					'#weight'        => 30,
				);
			}
			if ( ! isset( $info['designable'] )
				|| false !== $info['designable']
			) {
				if ( $_display->name === 'detailed' ) {
					$form['visibility']['globalize']        = array(
						'#type'          => 'checkbox',
						'#title'         => __( 'Add rendered content to global scope', 'directories-pro' ),
						'#default_value' => ! empty( $element_data['visibility']['globalize'] ),
						'#weight'        => 99,
					);
					$form['visibility']['globalize_remove'] = array(
						'#type'          => 'checkbox',
						'#title'         => __( 'Remove rendered content from display', 'directories-pro' ),
						'#default_value' => ! empty( $element_data['visibility']['globalize_remove'] ),
						'#weight'        => 99,
						'#states'        => array(
							'visible' => array(
								'input[name="visibility[globalize]"]' => array(
									'type'  => 'checked',
									'value' => true,
								),
							),
						),
					);
				}
			}
			if ( $application->isMobileDetectable() ) {
				$form['visibility']['hide_on_mobile'] = array(
					'#type'          => 'checkbox',
					'#title'         => __( 'Hide on mobile devices', 'directories-pro' ),
					'#default_value' => ! empty( $element_data['visibility']['hide_on_mobile'] ),
					'#weight'        => 98,
				);
			}
		} elseif ( $_display->type === 'form'
			&& ! empty( $info['can_admin_only'] )
		) {
			$form['visibility']['admin_only'] = array(
				'#type'          => 'checkbox',
				'#title'         => __( 'Visible in backend only', 'directories-pro' ),
				'#default_value' => ! empty( $element_data['visibility']['admin_only'] ),
				'#weight'        => 40,
			);
		}

		// Advanced settings
		if ( ! isset( $info['designable'] )
			|| false !== $info['designable']
		) {
			$form['advanced']['css_class'] = array(
				'#title'         => __( 'CSS class', 'directories-pro' ),
				'#type'          => 'textfield',
				'#default_value' => isset( $element_data['advanced']['css_class'] ) ? $element_data['advanced']['css_class'] : null,
			);
			$form['advanced']['css_id']    = array(
				'#title'                 => __( 'CSS ID', 'directories-pro' ),
				'#type'                  => 'textfield',
				'#default_value'         => isset( $element_data['advanced']['css_id'] ) ? $element_data['advanced']['css_id'] : null,
				'#description'           => $_display->type === 'entity' ? $application->System_Util_availableTags( array( '%id%' ) ) : null,
				'#description_no_escape' => true,
			);
			if ( isset( $info['designable'] )
				&& is_array( $info['designable'] )
			) {
				if ( in_array( 'margin', $info['designable'] )
					|| in_array( 'padding', $info['designable'] )
				) {
					$sizes = $application->System_Util_sizeOptions( true );
					foreach ( array(
						'margin'  => array(
							0     => _x( 'Margin', 'directories-pro' ),
							'add' => __( 'Add margin', 'directories-pro' ),
						),
						'padding' => array(
							0     => _x( 'Padding', 'directories-pro' ),
							'add' => __( 'Add padding', 'directories-pro' ),
						),
					) as $css_prop => $css_prop_labels ) {
						if ( in_array( $css_prop, $info['designable'] ) ) {
							$form['advanced'][ $css_prop . '_enable' ] = array(
								'#title'         => $css_prop_labels['add'],
								'#type'          => 'checkbox',
								'#default_value' => ! empty( $element_data['advanced'][ $css_prop . '_enable' ] ),
							);
							foreach ( array(
								'top'    => __( 'Top', 'directories-pro' ),
								'right'  => __( 'Right', 'directories-pro' ),
								'bottom' => __( 'Bottom', 'directories-pro' ),
								'left'   => __( 'Left', 'directories-pro' ),
							) as $css_pos => $css_pos_label ) {
								$key                      = $css_prop . '_' . $css_pos;
								$form['advanced'][ $key ] = array(
									'#title'         => $css_prop_labels[0] . ' - ' . $css_pos_label,
									'#type'          => 'select',
									'#options'       => $sizes,
									'#default_value' => isset( $element_data['advanced'][ $key ] ) ? $element_data['advanced'][ $key ] : null,
									'#states'        => array(
										'visible' => array(
											'input[name="advanced[' . $css_prop . '_enable]"]' => array(
												'type'  => 'checked',
												'value' => true,
											),
										),
									),
								);
							}
						}
					}
				}
				if ( in_array( 'font', $info['designable'] ) ) {
					$form['advanced'] += $this->fontSettingsForm( $application, isset( $element_data['advanced'] ) ? $element_data['advanced'] : array(), array( 'advanced' ) );
				}
				if ( in_array( 'z-index', $info['designable'] ) ) {
					$form['advanced'] += $this->zIndexSettingsForm( $application, isset( $element_data['advanced'] ) ? $element_data['advanced'] : array(), array( 'advanced' ) );
				}
			}
		}
		if ( $_display->type === 'entity'
			&& ! empty( $info['cacheable'] )
		) {
			$form['advanced']['cache'] = $application->System_Util_cacheSettingsForm(
				isset( $element_data['advanced']['cache'] ) ? $element_data['advanced']['cache'] : null,
				is_array( $info['cacheable'] ) ? $info['cacheable'] : null
			);
		}

		// Let other components modify settings
		$form = $application->Filter( 'display_element_settings_form', $form, array( $bundle, $_display, $element, $element_data ) );

		// Add tabs if settings available
		$weight     = 30;
		$tab_weight = 50;
		foreach ( array(
			'heading'    => _x( 'Heading', 'settings tab', 'directories-pro' ),
			'visibility' => _x( 'Visibility', 'settings tab', 'directories-pro' ),
			'advanced'   => _x( 'Advanced', 'settings tab', 'directories-pro' ),
		) as $key => $label ) {
			$weight += 10;
			if ( ! empty( $form[ $key ] ) ) {
				$form[ $key ]         += array(
					'#tab'                 => $key,
					'#tree'                => true,
					'#tree_allow_override' => false,
					'#horizontal_children' => true,
					'#weight'              => ++$weight,
				);
				$form['#tabs'][ $key ] = array(
					'#title'  => $label,
					'#weight' => ++$tab_weight,
				);
			}
		}

		return $form;
	}

	public static function filterSettings( array &$settings ) {
		// Check settings and remove if empty
		$check = array(
			'visibility' => array( 'hide_on_parent', 'hide_on_mobile' ),
			'advanced'   => array( 'css_class', 'css_id' ),
		);
		foreach ( array_keys( $check ) as $tab ) {
			foreach ( $check[ $tab ] as $setting ) {
				if ( empty( $settings[ $tab ][ $setting ] ) ) {
					unset( $settings[ $tab ][ $setting ] );
				}
			}
			if ( empty( $settings[ $tab ] ) ) {
				$settings[ $tab ] = null;
			}
		}
	}

	public static function _filterSettings( Form $form, array &$settings ) {
		self::filterSettings( $settings );
	}

	protected function _getResponsiveWidthOptions() {
		return array(
			'xs'  => '< 360px',
			'xsm' => '>= 360px',
			'sm'  => '>= 576px',
			'md'  => '>= 768px',
			'lg'  => '>= 992px',
			'xl'  => '>= 1200px',
			'xxl' => '>= 1400px',
		);
	}

	protected function _getCssSizeOptions() {
		return array(
			1 => __( 'X-Small', 'directories-pro' ),
			2 => __( 'Small', 'directories-pro' ),
			3 => __( 'Medium', 'directories-pro' ),
			4 => __( 'Large', 'directories-pro' ),
			5 => __( 'X-Large', 'directories-pro' ),
		);
	}

	public function fontSettingsForm( Application $application, array $settings, array $parents = array(), array $options = array() ) {
		$options += array(
			'prefix'                 => '',
			'bundle'                 => null,
			'horizontal'             => true,
			'exclude_class_settings' => false,
			'exclude_color_settings' => false,
		);
		$form     = array(
			'font_size'     => array(
				'#title'         => $options['prefix'] . __( 'Font size', 'directories-pro' ),
				'#type'          => 'select',
				'#default_value' => isset( $settings['font_size'] ) ? $settings['font_size'] : '',
				'#options'       => array(
					''    => __( 'Default', 'directories-pro' ),
					'rel' => __( 'Relative size', 'directories-pro' ),
					'px'  => __( 'Absolute size', 'directories-pro' ),
				),
				'#horizontal'    => $options['horizontal'],
			),
			'font_size_rel' => array(
				'#type'          => 'slider',
				'#default_value' => isset( $settings['font_size_rel'] ) ? $settings['font_size_rel'] : 1,
				'#min_value'     => 0.1,
				'#max_value'     => 3,
				'#step'          => 0.05,
				'#field_prefix'  => 'x',
				'#states'        => array(
					'visible' => array(
						$font_size_selector = sprintf( 'select[name="%s"]', $application->Form_Form_fieldName( array_merge( $parents, array( 'font_size' ) ) ) ) => array( 'value' => 'rel' ),
					),
				),
				'#horizontal'    => $options['horizontal'],
			),
			'font_size_abs' => array(
				'#type'          => 'slider',
				'#default_value' => isset( $settings['font_size_abs'] ) ? $settings['font_size_abs'] : 16,
				'#min_value'     => 1,
				'#max_value'     => 50,
				'#step'          => 1,
				'#field_suffix'  => 'px',
				'#states'        => array(
					'visible' => array(
						$font_size_selector => array( 'value' => 'px' ),
					),
				),
				'#horizontal'    => $options['horizontal'],
			),
		);
		if ( ! $options['exclude_class_settings'] ) {
			$form += array(
				'font_weight' => array(
					'#title'         => $options['prefix'] . __( 'Font weight', 'directories-pro' ),
					'#type'          => 'select',
					'#default_value' => isset( $settings['font_weight'] ) ? $settings['font_weight'] : '',
					'#options'       => array(
						'light' => __( 'Light', 'directories-pro' ),
						''      => __( 'Default', 'directories-pro' ),
						'bold'  => __( 'Bold', 'directories-pro' ),
					),
					'#horizontal'    => $options['horizontal'],
				),
				'font_style'  => array(
					'#title'         => $options['prefix'] . __( 'Font style', 'directories-pro' ),
					'#type'          => 'select',
					'#default_value' => isset( $settings['font_style'] ) ? $settings['font_style'] : '',
					'#options'       => array(
						''       => __( 'Default', 'directories-pro' ),
						'italic' => __( 'Italic', 'directories-pro' ),
					),
					'#horizontal'    => $options['horizontal'],
				),
			);
		}
		if ( isset( $options['bundle'] )
			&& $options['bundle'] instanceof Bundle
		) {
			$form['font_color'] = $application->System_Color_settingsForm(
				$settings['font_color'],
				array_merge( $parents, array( 'font_color' ) ),
				array(
					'bundle'     => $options['bundle'],
					'title'      => $options['prefix'] . __( 'Font color', 'directories-pro' ),
					'horizontal' => $options['horizontal'],
				),
			);
		}
		return $form;
	}

	public function zIndexSettingsForm( Application $application, array $settings, array $parents = array(), $horizontal = true, $prefix = '' ) {
		return array(
			'z_index' => array(
				'#title'         => $prefix . __( 'Z-index', 'directories-pro' ),
				'#type'          => 'slider',
				'#default_value' => isset( $settings['z_index'] ) ? $settings['z_index'] : null,
				'#min_value'     => 0,
				'#max_value'     => 20,
				'#min_text'      => __( 'Auto', 'directories-pro' ),
				'#integer'       => true,
				'#horizontal'    => $horizontal,
			),
		);
	}
}
