<?php

/**
 * @package JPageBuilder
 * @author Joomla! Extensions Store
 * @copyright (C) 2024 - Joomla! Extensions Store
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
 */
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;

// No direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
class JpagebuilderAddonAjax_contact extends JpagebuilderAddons {
	public static $salt = '3a1q3ko70zwa2lxnui73qk3hm7g2xq6oe7bi0ydk0eulifabjb';
	/**
	 * The addon frontend render method.
	 * The returned HTML string will render to the frontend page.
	 *
	 * @return string The HTML string.
	 * @since 1.0.0
	 */
	public function render() {
		// CSRF token
		HTMLHelper::_ ( 'jquery.token' );

		$settings = $this->addon->settings;
		$class = (isset ( $settings->class ) && $settings->class) ? $settings->class : '';
		$title = (isset ( $settings->title ) && $settings->title) ? $settings->title : '';
		$heading_selector = (isset ( $settings->heading_selector ) && $settings->heading_selector) ? $settings->heading_selector : 'h3';

		// Addon options
		$recipient_email = (isset ( $settings->recipient_email ) && $settings->recipient_email) ? $settings->recipient_email : '';
		$from_email = (isset ( $settings->from_email ) && $settings->from_email) ? $settings->from_email : '';
		$from_name = (isset ( $settings->from_name ) && $settings->from_name) ? $settings->from_name : '';
		$show_phone = (isset ( $settings->show_phone ) && $settings->show_phone) ? $settings->show_phone : '';
		$formcaptcha = (isset ( $settings->formcaptcha ) && $settings->formcaptcha) ? $settings->formcaptcha : '';
		$captcha_type = (isset ( $settings->captcha_type )) ? $settings->captcha_type : 'default';
		$captcha_question = (isset ( $settings->captcha_question ) && $settings->captcha_question) ? $settings->captcha_question : '';
		$captcha_answer = (isset ( $settings->captcha_answer ) && $settings->captcha_answer) ? $settings->captcha_answer : '';
		
		$params = ComponentHelper::getParams ( 'com_jpagebuilder' );
		$turnstyleSitekey = $params->get ( 'turnstyle_sitekey', '' );
		$turnstyleSecretkey = $params->get ( 'turnstyle_secretkey', '' );
		
		$button_text = Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SEND' );
		$use_custom_button = (isset ( $settings->use_custom_button ) && $settings->use_custom_button) ? $settings->use_custom_button : 0;
		$show_checkbox = (isset ( $settings->show_checkbox ) && $settings->show_checkbox) ? $settings->show_checkbox : 0;
		$checkbox_title = (isset ( $settings->checkbox_title ) && $settings->checkbox_title) ? $settings->checkbox_title : '';
		$button_class = (isset ( $settings->button_type ) && $settings->button_type) ? ' jpb-btn-' . $settings->button_type : ' jpb-btn-success';
		$button_text = (isset ( $settings->button_text ) && $settings->button_text) ? $settings->button_text : Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SEND' );
		$button_aria_text = (isset ( $settings->button_text ) && $settings->button_text) ? $settings->button_text : Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SEND' );

		$name_input_col = (isset ( $settings->name_input_col ) && $settings->name_input_col) ? ' jpb-col-sm-' . $settings->name_input_col : ' jpb-col-sm-12';
		$email_input_col = (isset ( $settings->email_input_col ) && $settings->email_input_col) ? ' jpb-col-sm-' . $settings->email_input_col : ' jpb-col-sm-12';
		$captcha_input_col = (isset ( $settings->captcha_input_col ) && $settings->captcha_input_col) ? ' jpb-col-sm-' . $settings->captcha_input_col : ' jpb-col-sm-12';
		$subject_input_col = (isset ( $settings->subject_input_col ) && $settings->subject_input_col) ? ' jpb-col-sm-' . $settings->subject_input_col : ' jpb-col-sm-12';
		$phone_input_col = (isset ( $settings->phone_input_col ) && $settings->phone_input_col) ? ' jpb-col-sm-' . $settings->phone_input_col : ' jpb-col-sm-12';
		$message_input_col = (isset ( $settings->message_input_col ) && $settings->message_input_col) ? ' jpb-col-sm-' . $settings->message_input_col : ' jpb-col-sm-12';

		$show_label = (isset ( $settings->show_label ) && $settings->show_label) ? $settings->show_label : false;

		if ($use_custom_button) {
			$button_class .= (isset ( $settings->button_size ) && $settings->button_size) ? ' jpb-btn-' . $settings->button_size : '';
			$button_class .= (isset ( $settings->button_shape ) && $settings->button_shape) ? ' jpb-btn-' . $settings->button_shape : ' jpb-btn-rounded';
			$button_class .= (isset ( $settings->button_appearance ) && $settings->button_appearance) ? ' jpb-btn-' . $settings->button_appearance : '';
			$button_class .= (isset ( $settings->button_block ) && $settings->button_block) ? ' ' . $settings->button_block : '';
			$button_icon = (isset ( $settings->button_icon ) && $settings->button_icon) ? $settings->button_icon : '';
			$button_icon_position = (isset ( $settings->button_icon_position ) && $settings->button_icon_position) ? $settings->button_icon_position : 'left';

			$icon_arr = array_filter ( explode ( ' ', $button_icon ) );

			if (count ( $icon_arr ) === 1) {
				$button_icon = 'fa ' . $button_icon;
			}

			if ($button_icon_position === 'left') {
				$button_text = ($button_icon) ? '<span class="' . $button_icon . '" aria-hidden="true"></span> ' . $button_text : $button_text;
			} else {
				$button_text = ($button_icon) ? $button_text . ' <span class="' . $button_icon . '" aria-hidden="true"></span>' : $button_text;
			}
		}

		$output = '<div class="jpb-addon jpb-addon-ajax-contact ' . $class . '">';

		if ($title) {
			$output .= '<' . $heading_selector . ' class="jpb-addon-title">' . $title . '</' . $heading_selector . '>';
		}

		$output .= '<div class="jpb-ajax-contact-content">';
		$output .= '<form class="jpb-ajaxt-contact-form">';
		$output .= '<div class="jpb-row">';

		$output .= '<div class="jpb-form-group ' . $name_input_col . '">';
		if ($show_label) {
			$output .= '<label for="name">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_NAME' ) . '</label>';
		}
		$output .= '<input type="text" name="name" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_NAME' ) . '" required="required">';
		$output .= '</div>';

		$output .= '<div class="jpb-form-group ' . $email_input_col . '">';
		if ($show_label) {
			$output .= '<label for="email">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_EMAIL' ) . '</label>';
		}
		$output .= '<input type="email" name="email" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_EMAIL' ) . '" required="required">';
		$output .= '</div>';

		if (! empty ( $show_phone )) {
			$output .= '<div class="jpb-form-group ' . $phone_input_col . '">';
			if ($show_label) {
				$output .= '<label for="phone">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_PHONE' ) . '</label>';
			}
			$output .= '<input type="text" name="phone" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_PHONE' ) . '" required="required">';
			$output .= '</div>';
		}

		$output .= '<div class="jpb-form-group ' . $subject_input_col . '">';
		if ($show_label) {
			$output .= '<label for="subject">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SUBJECT' ) . '</label>';
		}
		$output .= '<input type="text" name="subject" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SUBJECT' ) . '" required="required">';
		$output .= '</div>';

		$output .= '<div class="jpb-form-group ' . $message_input_col . '">';
		if ($show_label) {
			$output .= '<label for="message">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_MESSAGE' ) . '</label>';
		}
		$output .= '<textarea name="message" rows="5" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_MESSAGE' ) . '" required="required"></textarea>';
		$output .= '</div>';

		if ($formcaptcha && $captcha_type == 'default') {
			$output .= '<div class="jpb-form-group ' . $captcha_input_col . '">';
			if ($show_label) {
				$output .= '<label for="captcha_question">' . $captcha_question . '</label>';
			}
			$output .= '<input type="text" name="captcha_question" class="jpb-form-control" placeholder="' . $captcha_question . '" required="required">';
			$output .= '</div>';
		} elseif($formcaptcha && $captcha_type == 'gcaptcha') {
			$output .= '<div class="js-cf-captcha-wrapper jpb-form-group jpb-col-sm-12"></div>';
		} elseif($formcaptcha && $captcha_type == 'turnstyle') {
			$output .= '<div class="jpb-form-group jpb-col-sm-12"><div class="cf-turnstile" data-sitekey="' . $turnstyleSitekey . '" data-error-callback="turnstileError"></div></div>';
		}

		$output .= '</div>';

		$hidden_value = array (
				'recipient_email' => base64_encode ( $recipient_email ),
				'from_email' => base64_encode ( $from_email ),
				'from_name' => base64_encode ( $from_name )
		);
		$hidden_json = json_encode ( $hidden_value );
		$hidden_base64 = base64_encode ( $hidden_json );

		$encrypted_salt_key = md5 ( self::$salt . $hidden_base64 );

		$output .= '<input type="hidden" name="form_id" value="' . $hidden_base64 . ':' . $encrypted_salt_key . '" >';

		$output .= '<input type="hidden" name="addon_id" value="' . $this->addon->id . '">';

		if ($formcaptcha && $captcha_type == 'default') {
			$output .= '<input type="hidden" name="captcha_answer" value="' . md5 ( $captcha_answer ) . '">';
		}

		if ($show_checkbox) {
			$output .= '<div class="jpb-form-group">';
			$output .= '<div class="jpb-form-check">';
			$output .= '<input class="jpb-form-check-input" type="checkbox" name="agreement" id="agreement-' . $this->addon->id . '" required="required">';
			$output .= '<label class="jpb-form-check-label" for="agreement-' . $this->addon->id . '">' . $checkbox_title . '</label>';
			$output .= '</div>';
			$output .= '</div>';
		}

		$output .= '<input type="hidden" name="captcha_type" value="' . $captcha_type . '">';
		$output .= '<div class="jpb-form-button">';
		$output .= '<button type="submit" id="btn-' . $this->addon->id . '" aria-label="' . strip_tags ( $button_aria_text ) . '" class="jpb-btn' . $button_class . '">' . $button_text . '</button>';
		$output .= '</div>';
		$output .= '</form>';
		$output .= '<div style="display:none;margin-top:10px;" class="jpb-ajax-contact-status"></div>';

		$output .= '</div>';

		$output .= '</div>';

		return $output;
	}

	/**
	 * Get ajax value.
	 *
	 * @return void
	 * @since 1.0.0
	 */
	public static function getAjax() {

		// If cache isn't enable
		if (! Factory::getApplication()->getConfig()->get ( 'caching' ) && ! PluginHelper::getPlugin ( 'system', 'cache' )) {
			// Check CSRF
			Session::checkToken () or die ( 'Restricted Access' );
		}

		// include page builder page model
		require_once JPATH_BASE . '/components/com_jpagebuilder/models/page.php';

		$input = Factory::getApplication ()->getInput();
		$viewid = $input->get ( 'id', 0, 'int' );

		$config = Factory::getApplication ()->getConfig();
		$mail = Factory::getContainer()->get(Joomla\CMS\Mail\MailerFactoryInterface::class)->createMailer($config);
		$message = '';
		$showcaptcha = false;
		$turnstyleToken = null;
		$turnstyleCaptcha = false;
		
		// inputs
		$inputs = $input->get ( 'data', array (), 'Array' );

		foreach ( $inputs as $input ) {

			if ($input ['name'] == 'form_id') {
				$data = $input ['value'];
				$hidden_data = explode ( ':', $data );
				$encrypted_salt_key = md5 ( self::$salt . $hidden_data [0] );

				if ($encrypted_salt_key === $hidden_data [1]) {
					$decrypted_data = json_decode ( base64_decode ( $hidden_data [0] ) );
					$recipient = base64_decode ( $decrypted_data->recipient_email );
					$from_email = base64_decode ( $decrypted_data->from_email );
					$from_name = base64_decode ( $decrypted_data->from_name );
				} else {
					die ( 'Restricted Access' );
				}
			}

			if ($input ['name'] == 'captcha_type') {
				$captcha_type = $input ['value'];
			}

			if ($input ['name'] == 'view_type') {
				$view_type = $input ['value'];
			}

			if ($input ['name'] == 'addon_id') {
				$addon_id = $input ['value'];
			}

			if ($input ['name'] == 'module_id') {
				$module_id = $input ['value'];
			}

			if ($input ['name'] == 'email') {
				$email = $input ['value'];
			}

			if ($input ['name'] == 'name') {
				$name = $input ['value'];
			}

			if ($input ['name'] == 'subject') {
				$subject = $input ['value'];
			}

			if ($input ['name'] == 'phone') {
				$phone = $input ['value'];
			}

			if ($input ['name'] == 'message') {
				$message = nl2br ( $input ['value'] );
			}

			if ($input ['name'] == 'captcha_question') {
				$captcha_question = $input ['value'];
			}

			if ($input ['name'] == 'captcha_answer') {
				$captcha_answer = $input ['value'];
				$showcaptcha = true;
			}

			if ($input ['name'] == 'cf-turnstile-response') {
				$turnstyleToken = $input ['value'];
				$turnstyleCaptcha = true;
			}

			if ($input ['name'] == 'agreement') {
				$agreement = $input ['value'];
			}
		}

		// get addon infos
		if ($view_type == 'module') {
			$item_data = new stdClass ();
			$page_info = self::getPageInfoById ( $module_id, $view_type, 'new' );

			if (empty ( $page_info )) // if old version of module
			{
				$page_info = self::getPageInfoById ( $module_id, $view_type );
				$item_data->text = json_encode ( json_decode ( $page_info->params )->content );
			} else // if new version of module
			{
				$item_data->text = $page_info->content ?? $item_data->text;
			}
		} elseif ($view_type == 'article') {
			$item_data = new stdClass ();
			$item_data = self::getPageInfoById ( $viewid, $view_type );
		} else {
			$model = new JpagebuilderModelPage ();
			$item_data = $model->getItem ( $viewid );
		}

		$output = array ();
		$output ['status'] = false;

		// Match has addon id
		if (self::verifyAddon ( $item_data->content ?? $item_data->text, $addon_id ) == false) {
			$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_FAILED' ) . '</span>';
			return json_encode ( $output );
		}

		if ($showcaptcha) {
			if (md5 ( $captcha_question ) != $captcha_answer) {
				$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_WRONG_CAPTCHA' ) . '</span>';
				return json_encode ( $output );
			}
		}

		// Turnstyle validation here
		if ($turnstyleCaptcha) {
			if (empty($turnstyleToken)) {
				$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_WRONG_CAPTCHA' ) . '</span>';
				return json_encode ( $output );
			}
			
			$params = ComponentHelper::getParams ( 'com_jpagebuilder' );
			$turnstyleSecretkey = $params->get ( 'turnstyle_secretkey', '' );
			
			$verifyURL = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
			$data = [
					"secret" => $turnstyleSecretkey,
					"response" => $turnstyleToken,
					"remoteip" => $_SERVER["REMOTE_ADDR"]
			];
			
			$ch = curl_init($verifyURL);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			$response = curl_exec($ch);
			$responseData = json_decode($response, true);
			
			if (!$responseData["success"]) {
				$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_WRONG_CAPTCHA' ) . '</span>';
				return json_encode ( $output );
			}
		}

		// Get sender UP
		$senderip = isset ( $_SERVER ['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER ['HTTP_X_FORWARDED_FOR'] : $_SERVER ['REMOTE_ADDR'];

		// Subject Structure
		$site_name = isset ( $_SERVER ['SERVER_NAME'] ) ? $_SERVER ['SERVER_NAME'] : '';
		$mailSubject = $subject . ' | ' . $site_name;

		// Message structure
		$mailBody = '<div>';

		if (isset ( $name ) && $name) {
			$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_NAME' ) . '</strong>: ' . $name . '</p>';
		}

		$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_EMAIL' ) . '</strong>: ' . $email . '</p>';

		if (isset ( $phone ) && $phone) {
			$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_PHONE' ) . '</strong>: ' . $phone . '</p>';
		}

		if (isset ( $message ) && $message) {
			$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_MESSAGE' ) . '</strong>: ' . $message . '</p>';
		}

		if (isset ( $agreement ) && $agreement) {
			$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_TAC' ) . '</strong>: ' . Text::_ ( 'JYES' ) . '</p>';
		} else {
			$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_TAC' ) . '</strong>: ' . Text::_ ( 'JNO' ) . '</p>';
		}

		$mailBody .= '<p><strong>' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SENDER_IP' ) . '</strong>: ' . $senderip . '</p>';
		$mailBody .= '</div>';

		$config = Factory::getApplication()->getConfig();

		$senderMail = $config->get ( 'mailfrom' );
		$senderName = $config->get ( 'fromname' );

		// $sender = array( $email, $name );

		if (! empty ( $from_email )) {
			$senderMail = $from_email;
			$senderName = $from_name;
		}

		if (empty ( $senderMail ) && empty ( $senderName )) {
			$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_FAILED' ) . '</span>';
		}

		if (empty ( $recipient )) {
			$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_FAILED' ) . '</span>';
		}

		$isHtmlMode = true;
		$attachment = $cc = $bcc = null;

		if ($mail->sendMail ( $senderMail, $senderName, $recipient, $mailSubject, $mailBody, $isHtmlMode, $cc, $bcc, $attachment, $email, $name )) {
			$output ['status'] = true;
			$output ['content'] = '<span class="jpb-text-success">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SUCCESS' ) . '</span>';
		} else {
			$output ['content'] = '<span class="jpb-text-danger">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_FAILED' ) . '</span>';
		}

		return json_encode ( $output );
	}

	/**
	 * Get page by ID.
	 *
	 * @param int $the
	 *        	page ID.
	 * @param string $view_type
	 * @param string $version
	 *
	 * @return void
	 * @since 1.0.0
	 */
	public static function getPageInfoById($item_id, $view_type = 'page', $version = '') {
		$db = Factory::getContainer()->get('DatabaseDriver');
		$query = method_exists ( $db, 'createQuery' ) ? $db->createQuery () : $db->getQuery ( true );
		$query->select ( array (
				'a.*'
		) );

		if ($view_type == 'module') {
			if ($version == 'new') {
				$query->from ( $db->quoteName ( '#__jpagebuilder', 'a' ) );
				$query->where ( $db->quoteName ( 'a.extension_view' ) . " = " . $db->quote ( 'module' ) );
				$query->where ( $db->quoteName ( 'a.view_id' ) . " = " . $db->quote ( ( int ) $item_id ) );
			} else {
				$query->from ( $db->quoteName ( '#__modules', 'a' ) );
				$query->where ( $db->quoteName ( 'a.id' ) . " = " . $db->quote ( ( int ) $item_id ) );
			}
		} else if ($view_type == 'article') {
			$query->from ( $db->quoteName ( '#__jpagebuilder', 'a' ) );
			$query->where ( $db->quoteName ( 'a.view_id' ) . " = " . $db->quote ( ( int ) $item_id ) );
		} else {
			$query->from ( $db->quoteName ( '#__jpagebuilder', 'a' ) );
			$query->where ( $db->quoteName ( 'a.id' ) . " = " . $db->quote ( ( int ) $item_id ) );
		}

		$db->setQuery ( $query );
		$result = $db->loadObject ();

		return $result;
	}
	
	/**
	 * Attach inline scripts.
	 *
	 * @return string
	 */
	public function js() {
		$settings = $this->addon->settings;
		if(!isset($settings->captcha_type)) {
			$settings->captcha_type = 'gcaptcha';
		}
		$captcha_type = $settings->captcha_type;
		
		if($captcha_type == 'gcaptcha') {
			$js = "var jpagebuilder_recaptcha_label = '" . Text::_('COM_JPAGEBUILDER_ADDON_CAPTCHA_ROBOT', true) . "';";
			$js .= "var jpagebuilder_required_label = '" . Text::_('COM_JPAGEBUILDER_ADDON_CAPTCHA_REQUIRED', true) . "';";
			return $js;
		}
		
		return '';
	}
	
	public function css() {
		$settings = $this->addon->settings;
		$addon_id = '#jpb-addon-' . $this->addon->id;
		$layout_path = JPATH_ROOT . '/components/com_jpagebuilder/layouts';
		$css_path = new FileLayout ( 'addon.css.button', $layout_path );
		$cssHelper = new JpagebuilderCSSHelper ( $addon_id );
		$css = '';

		$use_custom_button = (isset ( $settings->use_custom_button ) && $settings->use_custom_button) ? $settings->use_custom_button : 0;

		if ($use_custom_button) {
			$css .= $css_path->render ( array (
					'addon_id' => $addon_id,
					'options' => $this->addon->settings,
					'id' => 'btn-' . $this->addon->id
			) );
		}

		$inputProps = [ 
				'field_bg_color' => 'background',
				'field_color' => 'color',
				'field_font_size' => 'font-size',
				'field_border_color' => 'border-color',
				'field_border_width' => 'border-width',
				'field_border_radius' => 'border-radius',
				'field_padding' => 'padding',
				'input_height' => 'height'
		];

		$inputUnits = [ 
				'field_bg_color' => false,
				'field_color' => false,
				'field_border_color' => false,
				'field_padding' => false,
				'field_border_width' => false
		];

		$modifiers = [ 
				'field_padding' => 'spacing'
		];

		$fieldStyle = $cssHelper->generateStyle ( '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', $settings, $inputProps, $inputUnits, $modifiers );

		$inputPropsTextArea = [ 
				'field_bg_color' => 'background',
				'field_color' => 'color',
				'field_font_size' => 'font-size',
				'field_border_color' => 'border-color',
				'field_border_width' => 'border-width',
				'field_border_radius' => 'border-radius',
				'field_padding' => 'padding',
				'textarea_height' => 'height'
		];
		$fieldTextAreaStyle = $cssHelper->generateStyle ( '.jpb-ajaxt-contact-form div.jpb-form-group textarea', $settings, $inputPropsTextArea, $inputUnits, $modifiers );

		$fieldMarginStyle = $cssHelper->generateStyle ( '.jpb-ajaxt-contact-form div.jpb-form-group', $settings, [ 
				'field_margin' => 'margin'
		], false, [ 
				'field_margin' => 'spacing'
		] );

		$fieldHoverStyle = $cssHelper->generateStyle ( ".jpb-ajaxt-contact-form .jpb-form-group input:hover,
			.jpb-ajaxt-contact-form .jpb-form-group input:active,
			.jpb-ajaxt-contact-form .jpb-form-group input:focus,
			.jpb-ajaxt-contact-form .jpb-form-group textarea:hover,
			.jpb-ajaxt-contact-form .jpb-form-group textarea:active,
			.jpb-ajaxt-contact-form .jpb-form-group textarea:focus", $settings, [ 
				'field_hover_bg_color' => 'background',
				'field_focus_border_color' => 'border-color'
		], false );

		$placeholderStyle = $cssHelper->generateStyle ( '.jpb-ajaxt-contact-form .jpb-form-group input::placeholder,.jpb-ajaxt-contact-form .jpb-form-group textarea::placeholder', $settings, [ 
				'field_placeholder_color' => 'color'
		], false );
		$hoverPlaceholderStyle = $cssHelper->generateStyle ( '.jpb-ajaxt-contact-form .jpb-form-group input:hover::placeholder,.jpb-ajaxt-contact-form .jpb-form-group textarea:hover::placeholder', $settings, [ 
				'field_hover_placeholder_color' => 'color'
		], false );
		$buttonStyle = $cssHelper->generateStyle ( '.jpb-btn span', $settings, [ 
				'button_icon_margin' => 'margin'
		], false, [ 
				'button_icon_margin' => 'spacing'
		] );
		$buttonPositionStyle = $cssHelper->generateStyle ( '.jpb-form-button', $settings, [ 
				'button_position' => 'text-align'
		], false );
		$transformCss = $cssHelper->generateTransformStyle ( '.jpb-ajax-contact-content', $settings, 'transform' );

		$css .= $fieldMarginStyle;
		$css .= $fieldStyle;
		$css .= $fieldTextAreaStyle;
		$css .= $fieldHoverStyle;
		$css .= $placeholderStyle;
		$css .= $hoverPlaceholderStyle;
		$css .= $buttonStyle;
		$css .= $buttonPositionStyle;
		$css .= $transformCss;

		return $css;
	}

	/**
	 * Attach the required scripts.
	 *
	 * @return array
	 * @since 1.0.0
	 */
	public function scripts() {
		// Avoid edit mode exec
		if(is_array($this->addon)) {
			return;
		}
		
		$app = Factory::getApplication();
		$doc = $app->getDocument ();
		$settings = $this->addon->settings;
		if(!isset($settings->captcha_type)) {
			$settings->captcha_type = 'gcaptcha';
		}
		$captcha_type = $settings->captcha_type;
		
		if($captcha_type == 'gcaptcha') {
			$wa = $doc->getWebAssetManager();
			$wa->useScript('jquery');
			return array (
					'components/com_jpagebuilder/assets/js/addons/recaptcha.js'
			);
		}
		
		if($captcha_type == 'turnstyle') {
			$wa = $doc->getWebAssetManager();
			$wa->registerAndUseScript('jpagebuilder.turnstile', 'https://challenges.cloudflare.com/turnstile/v0/api.js', [], ['defer'=>true, 'async'=>true]);
			return array (
					'components/com_jpagebuilder/assets/js/addons/turnstyle.js'
			);
		}
	}
	
	/**
	 * Attach the required styles.
	 *
	 * @return array
	 * @since 2.0.0
	 */
	public function stylesheets() {
		$stylesheet = [];
		$settings = isset($this->addon->settings) ? $this->addon->settings : null;
		if(!$settings) {
			return;
		}
		
		$captcha_type = $settings->captcha_type;
		if($captcha_type == 'gcaptcha') {
			$stylesheet = [
				'components/com_jpagebuilder/assets/css/recaptcha.css'
			];
		}
		
		return $stylesheet;
	}
	
	public static function verifyAddon($pageContent, $addonId) {
		$addonInfo = false;
		$pageContent = json_decode ( $pageContent );

		foreach ( $pageContent as $key => $row ) {
			foreach ( $row->columns as $key => $column ) {
				foreach ( $column->addons as $key => $addon ) {

					// if direct addon
					if (($addon->id == $addonId) && ($addon->name == 'ajax_contact')) {
						return true;
						break;
					}

					// if has inner array
					if (isset ( $addon->columns ) && count ( $addon->columns ) && $addon->columns) {
						foreach ( $addon->columns as $key => $inner_column ) {
							foreach ( $inner_column->addons as $key => $inner_addon ) {
								if (($inner_addon->id == $addonId) && ($inner_addon->name == 'ajax_contact')) {
									return true;
									break;
								}
							}
						}
					} // END:: has inner columns

					// if repeatable addon (tab, accordion)
					$inner_items = 'jp_' . $addon->name . '_item';
					if (isset ( $addon->settings->$inner_items ) && count ( $addon->settings->$inner_items ) && $addon->settings->$inner_items) {
						foreach ( $addon->settings->$inner_items as $inner_item ) {
							if (isset ( $inner_item->content ) && is_array ( $inner_item->content ) && ! empty ( $inner_item->content )) {
								foreach ( $inner_item->content as $inner_addon ) {
									if (($inner_addon->id == $addonId) && ($inner_addon->name == 'ajax_contact')) {
										return true;
										break;
									}
								}
							}
						}
					} // END:: repeatable addon (tab, accordion)
				}
			}
		}
		return false;
	}
	public static function getFrontendEditor() {
		$lodash = new JpagebuilderLodashlib ( '#jpb-addon-{{ data.id }}' );
		$output = '
		<#
		var classList = "";

		if (!_.isEmpty(data.button_type) && data.button_type !== undefined) {
			classList += " jpb-btn-"+data.button_type;
		} else {
			classList += " jpb-btn-success";
		}
		
		if (data.button_size !== undefined) {
			classList += " jpb-btn-"+data.button_size;
		}
		if (!_.isEmpty(data.button_shape) && data.button_shape !== undefined) {
			classList += " jpb-btn-"+data.button_shape;
		} else {
			classList += " jpb-btn-rounded";
		}
		if(!_.isEmpty(data.button_appearance)) {
			classList += " jpb-btn-"+data.button_appearance;
		}
		if (data.button_block !== undefined) {
			classList += " " + data.button_block;
		}
		var modern_font_style = false;
		var button_fontstyle = data.button_fontstyle || "";
		var button_font_style = data.button_font_style || "";

        var button_padding = "";
        var button_padding_sm = "";
        var button_padding_xs = "";

        if(data.button_padding){
            if(_.isObject(data.button_padding)){
                if(data.button_padding.md.trim() !== ""){
                    button_padding = data.button_padding.md.split(" ").map(item => {
                        if(_.isEmpty(item)){
                            return "0";
                        }
                        return item;
                    }).join(" ")
                }

                if(data.button_padding.sm.trim() !== ""){
                    button_padding_sm = data.button_padding.sm.split(" ").map(item => {
                        if(_.isEmpty(item)){
                            return "0";
                        }
                        return item;
                    }).join(" ")
                }

                if(data.button_padding.xs.trim() !== ""){
                    button_padding_xs = data.button_padding.xs.split(" ").map(item => {
                        if(_.isEmpty(item)){
                            return "0";
                        }
                        return item;
                    }).join(" ")
                }
            } else {
                if(data.button_padding.trim() !== ""){
                    button_padding = data.button_padding.split(" ").map(item => {
                        if(_.isEmpty(item)){
                                return "0";
                        }
                        return item;
                    }).join(" ")
                }
            }
        }
		#>
		<style type="text/css">';
		$output .= '
			#jpb-addon-{{ data.id }} #btn-{{ data.id }}.jpb-btn-{{ data.button_type }} {
				letter-spacing: {{ data.button_letterspace }};
				<# if(_.isObject(button_font_style) && button_font_style.underline) { #>
					text-decoration: underline;
					<# modern_font_style = true #>
				<# } #>

				<# if(_.isObject(button_font_style) && button_font_style.italic) { #>
					font-style: italic;
					<# modern_font_style = true #>
				<# } #>

				<# if(_.isObject(button_font_style) && button_font_style.uppercase) { #>
					text-transform: uppercase;
					<# modern_font_style = true #>
				<# } #>

				<# if(_.isObject(button_font_style) && button_font_style.weight) { #>
					font-weight: {{ button_font_style.weight }};
					<# modern_font_style = true #>
				<# } #>

				<# if(!modern_font_style) { #>
					<# if(_.isArray(button_fontstyle)) { #>
						<# if(button_fontstyle.indexOf("underline") !== -1){ #>
							text-decoration: underline;
						<# } #>
						<# if(button_fontstyle.indexOf("uppercase") !== -1){ #>
							text-transform: uppercase;
						<# } #>
						<# if(button_fontstyle.indexOf("italic") !== -1){ #>
							font-style: italic;
						<# } #>
						<# if(button_fontstyle.indexOf("lighter") !== -1){ #>
							font-weight: lighter;
						<# } else if(button_fontstyle.indexOf("normal") !== -1){#>
							font-weight: normal;
						<# } else if(button_fontstyle.indexOf("bold") !== -1){#>
							font-weight: bold;
						<# } else if(button_fontstyle.indexOf("bolder") !== -1){#>
							font-weight: bolder;
						<# } #>
					<# } #>
				<# } #>
			}

			';

		$output .= $lodash->unit ( 'margin-top', '.jpb-addon-title', 'data.title_margin_top', 'px' );
		$output .= $lodash->unit ( 'margin-bottom', '.jpb-addon-title', 'data.title_margin_bottom', 'px' );

		// Link
		$output .= ' <# if (data.button_type == "link") { #>';
		$output .= $lodash->unit ( 'border-bottom-width', '#btn-{{ data.id }}.jpb-btn-link', 'data.link_button_border_width', 'px', false );
		$output .= $lodash->unit ( 'padding-bottom', '#btn-{{ data.id }}.jpb-btn-link', 'data.link_button_padding_bottom', 'px', false );
		$output .= '<# } #>';

		// Custom
		$output .= '<# if (data.button_type == "custom") { #>';
		$output .= $lodash->color ( 'color', '#btn-{{ data.id }}.jpb-btn-custom:hover', 'data.button_color_hover' );
		$output .= $lodash->color ( 'background-color', '#btn-{{ data.id }}.jpb-btn-custom:hover', 'data.button_background_color' );

		// Outline
		$output .= '<# if(data.button_appearance == "outline") { #>';
		$output .= $lodash->border ( 'border-color', '#btn-{{ data.id }}.jpb-btn-custom', 'data.button_background_color' );
		$output .= $lodash->border ( 'border-color', '#btn-{{ data.id }}.jpb-btn-custom:hover', 'data.button_background_color_hover' );

		// 3D
		$output .= '<# } else if (data.button_appearance == "3d") { #>';
		$output .= $lodash->border ( 'border-bottom-color', '#btn-{{ data.id }}.jpb-btn-custom', 'data.button_background_color_hover' );
		$output .= $lodash->color ( 'background-color', '#btn-{{ data.id }}.jpb-btn-custom', 'data.button_background_color' );

		// Gradient
		$output .= '<# } else if (data.button_appearance == "gradient") { #>';
		$output .= $lodash->color ( 'background-color', '#btn-{{ data.id }}.jpb-btn-custom', 'data.button_background_gradient' );
		$output .= '#jpb-addon-{{ data.id }} #btn-{{ data.id }}.jpb-btn-custom { border: none; }';
		$output .= $lodash->color ( 'background-color', '#btn-{{ data.id }}.jpb-btn-custom:hover', 'data.button_background_gradient_hover' );

		// Hover
		$output .= ' <# } else { #>';
		$output .= $lodash->color ( 'background-color', '#btn-{{ data.id }}.jpb-btn-custom:hover', 'data.button_background_color' );
		$output .= '<# } #>';

		$output .= '<# } #>';

		// Textarea
		$output .= $lodash->color ( 'color', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_color' );
		$output .= $lodash->unit ( 'background', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_bg_color', '', false );
		$output .= $lodash->unit ( 'font-size', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_font_size', 'px', false );
		$output .= $lodash->unit ( 'border-radius', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_border_radius', 'px', false );
		$output .= $lodash->border ( 'border-color', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_border_color' );
		$output .= $lodash->border ( 'border-width', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_border_width' );
		$output .= $lodash->spacing ( 'padding', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.field_padding' );
		$output .= '#jpb-addon-{{ data.id }} .jpb-ajaxt-contact-form div.jpb-form-group textarea { transition:.35s; }';

		$output .= $lodash->color ( 'color', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_color' );
		$output .= $lodash->unit ( 'background', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_bg_color', '', false );
		$output .= $lodash->unit ( 'font-size', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_font_size', 'px', false );
		$output .= $lodash->unit ( 'border-radius', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_border_radius', 'px', false );
		$output .= $lodash->border ( 'border-color', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_border_color' );
		$output .= $lodash->border ( 'border-width', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_border_width' );
		$output .= $lodash->spacing ( 'padding', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.field_padding' );
		$output .= '#jpb-addon-{{ data.id }} .jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input) { transition:.35s; }';

		$output .= $lodash->unit ( 'height', '.jpb-ajaxt-contact-form .jpb-form-group input:not(.jpb-form-check-input)', 'data.input_height', 'px' );
		$output .= $lodash->unit ( 'height', '.jpb-ajaxt-contact-form div.jpb-form-group textarea', 'data.textarea_height', 'px' );

		$output .= $lodash->unit ( 'margin', '.jpb-ajaxt-contact-form div.jpb-form-group', 'data.field_margin', '' );

		$output .= $lodash->color ( 'color', '.jpb-ajaxt-contact-form .jpb-form-group input::placeholder, .jpb-ajaxt-contact-form .jpb-form-group textarea::placeholder', 'data.field_placeholder_color' );
		$output .= '#jpb-addon-{{ data.id }} .jpb-ajaxt-contact-form .jpb-form-group input::placeholder, #jpb-addon-{{ data.id }} .jpb-ajaxt-contact-form .jpb-form-group textarea::placeholder { opacity: 1; }';

		$output .= $lodash->color ( 'color', '.jpb-ajaxt-contact-form .jpb-form-group input:hover::placeholder, .jpb-ajaxt-contact-form .jpb-form-group textarea:hover::placeholder', 'data.field_hover_placeholder_color' );
		$output .= '#jpb-addon-{{ data.id }} .jpb-ajaxt-contact-form .jpb-form-group input:hover::placeholder, #jpb-addon-{{ data.id }} .jpb-ajaxt-contact-form .jpb-form-group textarea:hover::placeholder { opacity: 1; }';

		$output .= $lodash->unit ( 'background', '.jpb-ajaxt-contact-form .jpb-form-group input:hover, .jpb-ajaxt-contact-form .jpb-form-group input:active, .jpb-ajaxt-contact-form .jpb-form-group input:focus, .jpb-ajaxt-contact-form .jpb-form-group textarea:hover, .jpb-ajaxt-contact-form .jpb-form-group textarea:active,.jpb-ajaxt-contact-form .jpb-form-group textarea:focus', 'data.field_hover_bg_color', '', false );
		$output .= $lodash->color ( 'color', '.jpb-ajaxt-contact-form .jpb-form-group input:hover, .jpb-ajaxt-contact-form .jpb-form-group input:active, .jpb-ajaxt-contact-form .jpb-form-group input:focus, .jpb-ajaxt-contact-form .jpb-form-group textarea:hover, .jpb-ajaxt-contact-form .jpb-form-group textarea:active,.jpb-ajaxt-contact-form .jpb-form-group textarea:focus', 'data.field_hover_color' );
		$output .= $lodash->border ( 'border-color', '.jpb-ajaxt-contact-form .jpb-form-group input:hover, .jpb-ajaxt-contact-form .jpb-form-group input:active, .jpb-ajaxt-contact-form .jpb-form-group input:focus, .jpb-ajaxt-contact-form .jpb-form-group textarea:hover, .jpb-ajaxt-contact-form .jpb-form-group textarea:active,.jpb-ajaxt-contact-form .jpb-form-group textarea:focus', 'data.field_focus_border_color' );

		// Title
		$titleTypographyFallbacks = [ 
				'font' => 'data.title_font_family',
				'size' => 'data.title_fontsize',
				'line_height' => 'data.title_lineheight',
				'letter_spacing' => 'data.title_letterspace',
				'weight' => 'data.title_font_style?.weight',
				'italic' => 'data.title_font_style?.italic',
				'underline' => 'data.title_font_style?.underline',
				'uppercase' => 'data.title_font_style?.uppercase'
		];

		$output .= $lodash->typography ( '.jpb-addon-title', 'data.title_typography', $titleTypographyFallbacks );

		// link
		$output .= '<# if (data.button_type == "link") { #>';
		$output .= $lodash->color ( 'color', '#btn-{{ data.id }}.jpb-btn-link', 'data.link_button_color' );
		$output .= $lodash->border ( 'border-color', '#btn-{{ data.id }}.jpb-btn-link', 'data.link_border_color' );
		$output .= '#jpb-addon-{{ data.id }} #btn-{{ data.id }}.jpb-btn-link { text-decoration: none; }';
		$output .= '#jpb-addon-{{ data.id }} #btn-{{ data.id }}.jpb-btn-link { border-radius: 0; }';

		// Hover
		$output .= '<# if (data.link_button_status == "hover" && "#btn-{{ data.id }} .jpb-btn-link:focus") { #>';
		$output .= $lodash->color ( 'color', '#btn-{{ data.id }} .jpb-btn-link:hover', 'data.link_button_hover_color' );
		$output .= $lodash->border ( 'border-color', '#btn-{{ data.id }} .jpb-btn-link:hover', 'data.link_button_border_hover_color' );
		$output .= '<# } #>';
		$output .= '<# } #>';

		// Custom
		$output .= '<# if(data.button_type == "custom") { #>';
		$output .= $lodash->spacing ( 'padding', '#btn-{{ data.id }} .jpb-btn-custom', 'data.button_padding' );
		$output .= $lodash->unit ( 'font-size', '#btn-{{ data.id }} .jpb-btn-custom', 'data.fontsize' );
		$output .= $lodash->color ( 'color', '#btn-{{ data.id }} .jpb-btn-custom', 'data.button_color' );
		$output .= '<# } #>';
		$output .= $lodash->spacing ( 'margin', '.jpb-btn span', 'data.button_icon_margin' );
		$output .= $lodash->alignment ( 'text-align', '.jpb-btn-align', 'data.button_position' );
		$output .= $lodash->generateTransformCss ( '.jpb-ajax-contact-content', 'data.transform' );
		$output .= '
        </style>
		<div class="jpb-addon jpb-addon-ajax-contact {{ data.class }}">
			<# if( !_.isEmpty( data.title ) ){ #><{{ data.heading_selector }} class="jpb-addon-title jp-inline-editable-element" data-id={{data.id}} data-fieldName="title" contenteditable="true">{{ data.title }}</{{ data.heading_selector }}><# } #>
			<div class="jpb-ajax-contact-content">
				<form class="jpb-ajaxt-contact-form">
					<div class="jpb-row">
						<div class="jpb-form-group jpb-col-sm-{{ data.name_input_col || 12 }}">
							<# if(data.show_label){ #>
								<label for="name">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_NAME' ) . '</label>
							<# } #>
							<input type="text" name="name" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_NAME' ) . '" required="required">
						</div>

						<div class="jpb-form-group jpb-col-sm-{{ data.email_input_col || 12 }}">
							<# if(data.show_label){ #>
								<label for="email">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_EMAIL' ) . '</label>
							<# } #>
							<input type="email" name="email" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_EMAIL' ) . '" required="required">
                        </div>
                        
                        <# if(data.hasOwnProperty("show_phone") && Number(data.show_phone) !== 0) { #>
                            <div class="jpb-form-group jpb-col-sm-{{ data.phone_input_col || 12 }}">
                                <# if(data.show_label){ #>
                                    <label for="subject">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_PHONE' ) . '</label>
                                <# } #>
                                <input type="text" name="phone" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_PHONE' ) . '" required="required">
                            </div>
                        <# } #>

						<div class="jpb-form-group jpb-col-sm-{{ data.subject_input_col || 12 }}">
							<# if(data.show_label){ #>
								<label for="subject">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SUBJECT' ) . '</label>
							<# } #>
							<input type="text" name="subject" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SUBJECT' ) . '" required="required">
                        </div>

						<div class="jpb-form-group jpb-col-sm-{{ data.message_input_col || 12 }}">
							<# if(data.show_label){ #>
								<label for="message">' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_MESSAGE' ) . '</label>
							<# } #>
							<textarea name="message" rows="5" class="jpb-form-control" placeholder="' . Text::_ ( 'COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_MESSAGE' ) . '" required="required"></textarea>
						</div>

						<# 
								const isCaptchaEnabled = [true, "true", 1, "1"].includes(data.formcaptcha);
						#>

						<# if(isCaptchaEnabled && data.captcha_type == "default") { #>
							<div class="jpb-form-group jpb-col-sm-{{ data.captcha_input_col || 12 }}">
								<# if(data.show_label){ #>
									<label for="captcha_question">{{ data.captcha_question }}</label>
								<# } #>
								<input type="text" name="captcha_question" class="jpb-form-control" placeholder="{{ data.captcha_question }}" required="required">
							</div>
						<# } #>
					</div>
                    <# if(isCaptchaEnabled && data.captcha_type == "gcaptcha"){ #>
                        <div class="jpb-row">
                            <div class="jpb-form-group jpb-col-sm-12">
                                <img src="components/com_jpagebuilder/assets/images/captcha.png" >
                            </div>
                        </div>
					<# } #>

					<# if(isCaptchaEnabled && data.captcha_type == "turnstyle"){ #>
                        <div class="jpb-row">
                            <div class="jpb-form-group jpb-col-sm-12">
                                <img src="components/com_jpagebuilder/assets/images/turnstile.png" >
                            </div>
                        </div>
					<# } #>

                    <# if(data.show_checkbox){ #>
                        <div class="jpb-row">
                            <div class="jpb-form-group jpb-col-sm-12">
                                <div class="jpb-form-check">
                                    <input class="jpb-form-check-input" type="checkbox" id="agreement" required="required">
                                    <label class="jpb-form-check-label" for="agreement">{{{ data.checkbox_title }}}</label>
                                </div>
                            </div>
                        </div>
                    <# }
                        let iconLeft = "";
                        let iconRight = "";

                        let icon_arr = (typeof data.button_icon !== "undefined" && data.button_icon) ? data.button_icon.split(" ") : "";
                        let icon_name = icon_arr.length === 1 ? "fa "+data.button_icon : data.button_icon;
                                    
                        if(data.button_icon_position == "left" && !_.isEmpty(data.button_icon)){
                            iconLeft = \'<span class="\' + icon_name + \'"></span>\';
                        } else {
                            iconRight = \'<span class="\' + icon_name + \'"></span>\';
                        }
                    #>
					<# let button_text = !_.isEmpty(data.button_text) ? data.button_text : "' . Text::_ ( "COM_JPAGEBUILDER_ADDON_AJAX_CONTACT_SEND" ) . '";#>
                    <div class="jpb-row">
                        <div class="jpb-col-sm-12 jpb-btn-align">
                            <button type="button" id="btn-{{ data.id }}" class="jpb-btn {{classList}}">{{{iconLeft}}} {{ button_text }} {{{iconRight}}}</button>
                        </div>
                    </div>
				</form>
			</div>
		</div>';

		return $output;
	}
}