<?php
/**
 * Thrive Themes - https://thrivethemes.com
 *
 * @package thrive-visual-editor
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Silence is golden!
}

/**
 * Class TCB_Contact_Form_Element
 *
 * Element class
 */
class TCB_Contact_Form_Element extends TCB_Cloud_Template_Element_Abstract {

	/**
	 * Element category that will be displayed in the sidebar
	 *
	 * @return string
	 */
	public function category() {

		return $this->get_thrive_advanced_label();
	}

	/**
	 * Name of the Element in sidebar
	 *
	 * @return string
	 */
	public function name() {

		return __( 'Contact Form', 'thrive-cb' );
	}

	/**
	 * Which svg symbol id to use
	 *
	 * @return string
	 */
	public function icon() {

		return 'contact_form';
	}

	/**
	 * When element is selected in editor this identifier
	 * establishes element _type
	 *
	 * @see TVE.main.element_selected() TVE._type()
	 *
	 * @return string
	 */
	public function identifier() {

		return '.thrv-contact-form';
	}

	protected function html() {
		return tcb_template( 'elements/' . $this->tag() . '.php', $this, true );
	}

	/**
	 * Filters the Contact Form Input Types
	 *
	 * @return array
	 */
	public function get_types() {
		require_once dirname( dirname( __FILE__ ) ) . '/class-tcb-contact-form.php';

		$types = TCB_Contact_Form::get_types();

		foreach ( $types as $key => $value ) {
			if ( ! empty( $value['validation_error'] ) ) {
				unset( $types[ $key ]['validation_error'] );
			}
		}

		return $types;
	}

	public function own_components() {

		$contact_form = array(

			'contact_form' => array(
				'config' => array(
					'FieldsControl'          => array(
						'config' => array(
							'sortable' => true,
							'tpl'      => 'controls/contact-form/preview-list-item',
							'types'    => $this->get_types(),
						),
					),
					'AddRemoveLabels'        => array(
						'config'     => array(
							'name'    => '',
							'label'   => __( 'Labels', 'thrive-cb' ),
							'default' => true,
						),
						'css_suffix' => ' label',
						'css_prefix' => '',
						'extends'    => 'Switch',
					),
					'AddRemoveRequiredMarks' => array(
						'config'  => array(
							'name'    => '',
							'label'   => __( 'Required Marks', 'thrive-cb' ),
							'default' => true,
						),
						'extends' => 'Switch',
					),
				),
			),
			'typography'   => array(
				'hidden' => true,
			),
			'animation'    => array(
				'hidden' => true,
			),
		);

		return array_merge( $contact_form, $this->group_component() );
	}

	/**
	 * Group Edit Properties
	 *
	 * @return array|bool
	 */
	public function has_group_editing() {

		return array(
			'exit_label'    => __( 'Exit Group Styling', 'thrive-cb' ),
			'select_values' => array(
				array(
					'value'    => 'all_cf_items',
					'selector' => '.tve-cf-item',
					'name'     => __( 'Grouped Form Items', 'thrive-cb' ),
					'singular' => __( '-- Form Item %s', 'thrive-cb' ),
				),
				array(
					'value'    => 'all_inputs',
					'selector' => '.tve-cf-input',
					'name'     => __( 'Grouped Inputs', 'thrive-cb' ),
					'singular' => __( '-- Input %s', 'thrive-cb' ),
				),
				array(
					'value'    => 'all_labels',
					'selector' => '.tve-cf-item label',
					'name'     => __( 'Grouped Labels', 'thrive-cb' ),
					'singular' => __( '-- Label %s', 'thrive-cb' ),
				),
			),
		);
	}

	public function is_placeholder() {
		return false;
	}
}
