<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

if ( ! class_exists( 'SftcyWordformBuildForm' ) ) {
	class SftcyWordformBuildForm {
		public static $wordform_form_id                = '';
		public static $form_elements                   = array();
		public static $built_html_form_elements        = array();
		public static $disable_submit_button           = false;
		public static $sc_wordform_size                = '';          // small | medium | large
		public static $sc_wordform_submit_button_align = 'left';      // left | center | right
		public static $sc_wordform_form_name_align     = 'center';    // left | center | right
		public static $wordform_file_input_element_built = false;
		public static $wordform_payment_settings       = array();

		/**
		 * Normalize limited/basic-tier element settings before rendering.
		 *
		 * @param string $element_type Element type.
		 * @param array  $element      Element data.
		 * @return array
		 */
		private static function wordform_normalize_element_for_current_tier( $element_type = '', $element = array() ) {
			if ( ! is_array( $element ) ) {
				return array();
			}

			$element_type = sanitize_key( $element_type );
			$tier         = class_exists( 'SftcyWordformFeatures' ) ? SftcyWordformFeatures::wordform_get_product_tier() : 'pro';

			if ( 'basic' !== $tier ) {
				return $element;
			}

			switch ( $element_type ) {
				case 'upload':
					$element['multiple'] = 'false';
					$element['multiOption'] = array(
						array(
							'label'         => 'Image',
							'checkStatus'   => 'true',
							'fileTypeValue' => 'image',
						),
					);
					break;

				case 'date':
					unset( $element['calendarAccentColor'], $element['calendarSurfaceColor'], $element['calendarTextColor'] );
					$element['minDate']            = '';
					$element['maxDate']            = '';
					$element['disablePastDates']   = 'false';
					$element['disableFutureDates'] = 'false';
					break;

				case 'datetime':
					unset( $element['calendarAccentColor'], $element['calendarSurfaceColor'], $element['calendarTextColor'] );
					$element['minDateTime']            = '';
					$element['maxDateTime']            = '';
					$element['disablePastDateTimes']   = 'false';
					$element['disableFutureDateTimes'] = 'false';
					break;
			}

			return $element;
		}


		public static function sc_wordform_build_form_from_elements( $form_id = '' ) {
			self::$wordform_form_id = $form_id;
			// Reset each time before build the each form
			self::$built_html_form_elements = array();
			self::$wordform_payment_settings = SftcyWordformBase::wordform_settings_page_payment_config();
			foreach ( self::$form_elements as $key => $element ) {
				$element_type = isset( $element['type'] ) ? sanitize_key( $element['type'] ) : '';
				if ( class_exists( 'SftcyWordformFeatures' ) && ! SftcyWordformFeatures::wordform_is_builder_element_available( $element_type ) ) {
					continue;
				}

				$element = self::wordform_normalize_element_for_current_tier( $element_type, $element );

				switch ( $element['type'] ) {
					case 'text':
						self::build_text( $key, $element );
						break;
					case 'firstlastname':
						self::build_firstlastname( $key, $element );
						break;
					case 'number':
						self::build_number( $key, $element );
						break;
					case 'textarea':
						self::build_textarea( $key, $element );
						break;
					case 'richeditor':
						self::build_richeditor( $key, $element );
						break;
					case 'range':
						self::build_range( $key, $element );
						break;	
					case 'url':
						self::build_url( $key, $element );
						break;	
					case 'tel':
						self::build_tel( $key, $element );
						break;	
					case 'date':
						self::build_date( $key, $element );
						break;
					case 'time':
						self::build_time( $key, $element );
						break;
					case 'datetime':
						self::build_datetime( $key, $element );
						break;
					case 'radio':
						self::build_radio( $key, $element );
						break;
					case 'checkbox':
						self::build_checkbox( $key, $element );
						break;
					case 'select':
						self::build_select( $key, $element );
						break;
					case 'email':
						self::build_email( $key, $element );
						break;
					case 'address':
						self::build_address( $key, $element );
						break;
					case 'sectionhtml':
						self::build_sectionhtml( $key, $element );
						break;
					case 'maskinput':
						self::build_maskinput( $key, $element );
						break;
					case 'hidden':
						self::build_hidden( $key, $element );
						break;
					case 'captcha':
						self::build_captcha( $key, $element );
						break;
					case 'gcaptcha':
						self::build_gcaptcha( $key, $element );
						break;
					case 'hcaptcha':
						self::build_hcaptcha( $key, $element );
						break;
					case 'upload':
						self::build_upload( $key, $element );
						break;
					case 'rating':
						self::build_rating( $key, $element );
						break;
					case 'likert':
						self::build_likert( $key, $element );
						break;
					case 'signature':
						self::build_signature( $key, $element );
						break;
					case 'pagebreak':
						// Structural builder element. Frontend step wrappers are assembled later.
						break;
					case 'terms':
						self::build_terms( $key, $element );
						break;	
					case 'gdpr':
						self::build_gdpr( $key, $element );
						break;
					case 'payment_item':
						self::build_payment_item( $key, $element );
						break;
					case 'payment_coupon':
						self::build_payment_coupon( $key, $element );
						break;
					case 'payment_method':
						self::build_payment_method( $key, $element );
						break;
					case 'payment_custom_amount':
						self::build_payment_custom_amount( $key, $element );
						break;
					case 'payment_quantity':
						self::build_payment_quantity( $key, $element );
						break;
					case 'payment_summary':
						self::build_payment_summary( $key, $element );
						break;
					case 'stripe':
						self::build_stripe( $key, $element );
						break;
					case 'paypal':
						self::build_paypal( $key, $element );
						break;
					case 'square':
						self::build_square( $key, $element );
						break;
					case 'authorizenet':
						self::build_authorizenet( $key, $element );
						break;
				} // switch
			} // foreach

			// Include form name - submit button with form tag
			self::include_form_name_with_submit_info();
			// Include validation messages based on wordform ID 
			self::wordform_validation_messages();

			return self::$built_html_form_elements;
		}

		/**
		 * Payment settings used by frontend payment elements.
		 *
		 * @return array
		 */
		public static function wordform_get_payment_settings() {
			if ( ! is_array( self::$wordform_payment_settings ) || empty( self::$wordform_payment_settings ) ) {
				self::$wordform_payment_settings = SftcyWordformBase::wordform_settings_page_payment_config();
			}

			return self::$wordform_payment_settings;
		}

		/**
		 * Resolve a readable symbol for the configured currency code.
		 *
		 * @param string $currency_code Payment currency code.
		 * @return string
		 */
		public static function wordform_get_payment_currency_symbol( $currency_code = 'USD' ) {
			$currency_code = strtoupper( sanitize_text_field( $currency_code ) );
			$currency_map  = array(
				'USD' => '$',
				'EUR' => 'EUR',
				'GBP' => 'GBP',
				'BDT' => 'BDT',
				'AUD' => 'AUD',
				'CAD' => 'CAD',
				'INR' => 'INR',
				'JPY' => 'JPY',
			);

			return isset( $currency_map[ $currency_code ] ) ? $currency_map[ $currency_code ] : $currency_code;
		}

		/**
		 * Format payment amounts consistently across frontend payment elements.
		 *
		 * @param mixed $amount Amount value.
		 * @return string
		 */
		public static function wordform_format_payment_amount( $amount = 0 ) {
			$payment_settings = self::wordform_get_payment_settings();
			$currency_code    = isset( $payment_settings['payment_currency'] ) ? $payment_settings['payment_currency'] : 'USD';
			$symbol_position  = isset( $payment_settings['payment_currency_symbol_position'] ) ? $payment_settings['payment_currency_symbol_position'] : 'before';
			$currency_symbol  = self::wordform_get_payment_currency_symbol( $currency_code );
			$formatted_amount = number_format( (float) $amount, 2, '.', '' );

			if ( 'after' === $symbol_position ) {
				return $formatted_amount . ' ' . $currency_symbol;
			}

			return $currency_symbol . $formatted_amount;
		}

		/**
		 * Get shared field help text for supported frontend elements.
		 *
		 * @param array $element Field element settings.
		 * @return string
		 */
		private static function wordform_get_field_help_text( $element = array() ) {
			return isset( $element['helpText'] ) ? sanitize_text_field( $element['helpText'] ) : '';
		}

		/**
		 * Render frontend help text below the field label when configured.
		 *
		 * @param array $element Field element settings.
		 * @return string
		 */
		private static function wordform_render_field_help_text( $element = array() ) {
			$help_text = self::wordform_get_field_help_text( $element );

			if ( empty( $help_text ) ) {
				return '';
			}

			return '<div class="sc-wordform-built-field-help-text">' . esc_html( $help_text ) . '</div>';
		}

		/**
		 * Get a normalized frontend field-width value for supported fields.
		 *
		 * @param array $element Field element settings.
		 * @return string
		 */
		private static function wordform_get_field_width_value( $element = array() ) {
			$field_width = isset( $element['fieldWidth'] ) ? sanitize_key( $element['fieldWidth'] ) : 'full';

			if ( ! in_array( $field_width, array( 'full', 'half', 'third' ), true ) ) {
				$field_width = 'full';
			}

			return $field_width;
		}

		/**
		 * Build a frontend wrapper class string for shared width/custom class options.
		 *
		 * @param string $base_class Base field wrapper class.
		 * @param array  $element    Field element settings.
		 * @return string
		 */
		private static function wordform_get_shared_wrapper_classnames( $base_class = '', $element = array() ) {
			$classes   = array( sanitize_html_class( $base_class ) );
			$classes[] = 'sc-wordform-built-field-width-' . self::wordform_get_field_width_value( $element );

			if ( ! empty( $element['customCssClass'] ) ) {
				$custom_classes = preg_split( '/\s+/', sanitize_text_field( $element['customCssClass'] ) );
				if ( is_array( $custom_classes ) ) {
					foreach ( $custom_classes as $custom_class ) {
						$custom_class = sanitize_html_class( $custom_class );
						if ( ! empty( $custom_class ) ) {
							$classes[] = $custom_class;
						}
					}
				}
			}

			$classes = array_filter( array_unique( $classes ) );
			return implode( ' ', $classes );
		}

		/**
		 * Get a shared default value for supported text-like fields.
		 *
		 * @param array $element Field element settings.
		 * @return string
		 */
		private static function wordform_get_shared_default_value( $element = array() ) {
			return isset( $element['defaultValue'] ) ? sanitize_text_field( $element['defaultValue'] ) : '';
		}

		/**
		 * Render an HTML value attribute for supported shared default values.
		 *
		 * @param array $element Field element settings.
		 * @return string
		 */
		private static function wordform_render_shared_default_value_attribute( $element = array() ) {
			$default_value = self::wordform_get_shared_default_value( $element );

			if ( '' === $default_value ) {
				return '';
			}

			return ' value="' . esc_attr( $default_value ) . '"';
		}

		/**
		 * Build Text Field
		 * $param - $element - array
		 */
		public static function build_text( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][text][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][text][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][text][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			$label                            = '<div class="sc-wordform-built-text-element-label-wrapper"><label class="sc-wordform-built-text-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<input type="text" class="sc-wordform-built-text-element" name="' . esc_attr( $name ) . '"' . self::wordform_render_shared_default_value_attribute( $element ) . ' ' . $placeholder_text . esc_attr( $required ) . '/>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-text-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build First Name & Last Name Field
		 * $param - $element - array
		 */
		public static function build_firstlastname( $key = 0, $element = array() ) {
			$name_first              = 'wordform[' . self::$wordform_form_id . '][firstlastname][' . $key . '][values][first][]';
			$name_last               = 'wordform[' . self::$wordform_form_id . '][firstlastname][' . $key . '][values][last][]';
			$label_hidden_name       = 'wordform[' . self::$wordform_form_id . '][firstlastname][' . $key . '][label]';
			$label_first_hidden_name = 'wordform[' . self::$wordform_form_id . '][firstlastname][' . $key . '][labelFirst]';
			$label_last_hidden_name  = 'wordform[' . self::$wordform_form_id . '][firstlastname][' . $key . '][labelLast]';
			$value_required_status   = 'wordform[' . self::$wordform_form_id . '][firstlastname][' . $key . '][required]';

			// Label First Name
			if ( isset( $element['labelFirst'] ) ) {
				$labelname_first = sanitize_text_field( $element['labelFirst'] );
			} else {
				$labelname_first = '';
			}

			// Label Last Name
			if ( isset( $element['labelLast'] ) ) {
				$labelname_last = sanitize_text_field( $element['labelLast'] );
			} else {
				$labelname_last = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_first_required = $labelname_first . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-first-' . esc_attr( $key ) . '"></small>';
				$labelname_last_required = $labelname_last . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-last-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_first_required = $labelname_first;
				$labelname_last_required = $labelname_last;
			}
							

			// Placeholder Text First Name
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text_first = ' placeholder = "'. esc_attr( $element['placeholderTextFirst'] ) . '" ';
			} else {				
				$placeholder_text_first = '';
			}

			// Placeholder Text Last Name
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text_last = ' placeholder = "'. esc_attr( $element['placeholderTextLast'] ) . '" ';
			} else {				
				$placeholder_text_last = '';
			}

			// Generate HTML template
			$help_text_markup = self::wordform_render_field_help_text( $element );
			$first_lastname_template = '
			<div  class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-firstlastname-wrapper', $element ) ) . '">
' . $help_text_markup . '

			<div class="sc-wordform-built-firstlastname-row">
				
				<!-- First Name -->
				<div class="sc-wordform-built-first-name-wrapper">
					<label class="sc-wordform-built-text-element-label">' . $labelname_first_required . '</label>
					<input type="text" class = "sc-wordform-built-first-name" name = "' . esc_attr($name_first) . '" ' . $placeholder_text_first  . $required . '>
				</div>

				<!-- Last Name -->
				<div class="sc-wordform-built-last-name-wrapper">
					<label class="sc-wordform-built-text-element-label">' . $labelname_last_required . '</label>
					<input type="text" class="sc-wordform-built-last-name" name="' . esc_attr($name_last)  . '" ' .  $placeholder_text_last . $required . '>
				</div>

			</div>

			<!-- Hidden meta fields -->
			<input type="hidden" name="'. esc_attr($label_hidden_name) . '" value="' . esc_attr($labelname_first) . ' ' . esc_attr($labelname_last) . '">
			<input type="hidden" name="'. esc_attr($label_first_hidden_name) . '" value="' . esc_attr($labelname_first) . '">
			<input type="hidden" name="'. esc_attr($label_last_hidden_name) . '" value="' . esc_attr($labelname_last) . '">
			<input type="hidden" name="'. esc_attr($value_required_status) . '" value="' . esc_attr($element['required']) . '">

			</div>
			';
			self::$built_html_form_elements[] = $first_lastname_template;			
		}


		/**
		 * Build Number Field
		 * $param - $element - array
		 */
		public static function build_number( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][number][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][number][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][number][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			$label                            = '<div class="sc-wordform-built-number-element-label-wrapper"><label class="sc-wordform-built-number-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<input type="number" class="sc-wordform-built-number-element" name="' . esc_attr( $name ) . '"' . self::wordform_render_shared_default_value_attribute( $element ) . ' ' . $placeholder_text . esc_attr( $required ) . '/>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-number-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Textarea Field
		 * $param - $element - array
		 */
		public static function build_textarea( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][textarea][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][textarea][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][textarea][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			$label                            = '<div class="sc-wordform-built-textarea-element-label-wrapper"><label class="sc-wordform-built-textarea-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<textarea class="sc-wordform-built-textarea-element" name="' . esc_attr( $name ) . '" ' . $placeholder_text . esc_attr( $required ) . '>' . esc_textarea( self::wordform_get_shared_default_value( $element ) ) . '</textarea>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-textarea-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Rich Text Editor field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_richeditor( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][richeditor][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][richeditor][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][richeditor][' . $key . '][required]';
			$labelname             = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Rich Text Editor', 'wordform-pro' );
			$placeholder_show      = ! isset( $element['placeholderShow'] ) || 'true' === (string) $element['placeholderShow'];
			$placeholder_text      = isset( $element['placeholderText'] ) ? sanitize_text_field( $element['placeholderText'] ) : __( 'Write your response...', 'wordform-pro' );
			$min_height            = isset( $element['minHeight'] ) ? max( 140, min( 420, absint( $element['minHeight'] ) ) ) : 180;
			$is_required           = isset( $element['required'] ) && 'true' === (string) $element['required'];
			$labelname_required    = $is_required ? $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>' : $labelname;

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-richeditor-wrapper', $element ) ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-richeditor-element-label-wrapper"><label class="sc-wordform-built-richeditor-element-label">' . $labelname_required . '</label></div>';
			$wrapper_with_element .= self::wordform_render_field_help_text( $element );
			$wrapper_with_element .= '<div class="sc-wordform-built-richeditor-shell" data-wordform-rich-editor>';
			$wrapper_with_element .= '<div class="sc-wordform-built-richeditor-toolbar" data-wordform-rich-toolbar>';
			$wrapper_with_element .= '<button type="button" class="sc-wordform-built-richeditor-tool" data-wordform-rich-command="bold" aria-label="' . esc_attr__( 'Bold', 'wordform-pro' ) . '" title="' . esc_attr__( 'Bold', 'wordform-pro' ) . '"><i class="fa-solid fa-bold" aria-hidden="true"></i></button>';
			$wrapper_with_element .= '<button type="button" class="sc-wordform-built-richeditor-tool" data-wordform-rich-command="italic" aria-label="' . esc_attr__( 'Italic', 'wordform-pro' ) . '" title="' . esc_attr__( 'Italic', 'wordform-pro' ) . '"><i class="fa-solid fa-italic" aria-hidden="true"></i></button>';
			$wrapper_with_element .= '<button type="button" class="sc-wordform-built-richeditor-tool" data-wordform-rich-command="underline" aria-label="' . esc_attr__( 'Underline', 'wordform-pro' ) . '" title="' . esc_attr__( 'Underline', 'wordform-pro' ) . '"><i class="fa-solid fa-underline" aria-hidden="true"></i></button>';
			$wrapper_with_element .= '<button type="button" class="sc-wordform-built-richeditor-tool" data-wordform-rich-command="insertUnorderedList" aria-label="' . esc_attr__( 'Bullet list', 'wordform-pro' ) . '" title="' . esc_attr__( 'Bullet list', 'wordform-pro' ) . '"><i class="fa-solid fa-list-ul" aria-hidden="true"></i></button>';
			$wrapper_with_element .= '<button type="button" class="sc-wordform-built-richeditor-tool" data-wordform-rich-command="createLink" aria-label="' . esc_attr__( 'Insert link', 'wordform-pro' ) . '" title="' . esc_attr__( 'Insert link', 'wordform-pro' ) . '"><i class="fa-solid fa-link" aria-hidden="true"></i></button>';
			$wrapper_with_element .= '<button type="button" class="sc-wordform-built-richeditor-tool" data-wordform-rich-command="removeFormat" aria-label="' . esc_attr__( 'Clear formatting', 'wordform-pro' ) . '" title="' . esc_attr__( 'Clear formatting', 'wordform-pro' ) . '"><i class="fa-solid fa-eraser" aria-hidden="true"></i></button>';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-richeditor-surface" data-wordform-rich-surface contenteditable="true" role="textbox" aria-multiline="true" data-placeholder="' . esc_attr( $placeholder_show ? $placeholder_text : '' ) . '" style="min-height:' . esc_attr( $min_height ) . 'px;"></div>';
			$wrapper_with_element .= '<textarea class="sc-wordform-built-richeditor-value" data-wordform-rich-hidden name="' . esc_attr( $name ) . '" hidden></textarea>';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Range Field
		 * $param - $element - array
		 */
		public static function build_range( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][range][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][range][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][range][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Min Value
			if ( isset( $element['min'] ) ) {
				$min = sanitize_text_field( $element['min'] );
			} else {
				$min = 0;
			}
			// Max Value
			if ( isset( $element['max'] ) ) {
				$max = sanitize_text_field( $element['max'] );
			} else {
				$max = 100;
			}
			// Default Value
			if ( isset( $element['default'] ) ) {
				$default = sanitize_text_field( $element['default'] );
			} else {
				$default = 50;
			}
			// Step Value
			if ( isset( $element['step'] ) ) {
				$step = sanitize_text_field( $element['step'] );
			} else {
				$step = 5;
			}


			$label                            = '<div class="sc-wordform-built-range-element-label-wrapper"><label class="sc-wordform-built-range-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<input type="range" class="sc-wordform-built-range-element" name="' . esc_attr( $name ) . '" min="' . esc_attr( $min ) . '" max="' . esc_attr( $max ) . '" step="' . esc_attr( $step ) . '" value="' . esc_attr( $default ) . '" ' . esc_attr( $required ) . '/>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$span                             = '<span class="wordform-range-element-selected-value">' . esc_attr( $default ) . '</span>';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-range-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . $span . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Rating Field
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_rating( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][rating][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][rating][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][rating][' . $key . '][required]';
			$scale_hidden_name     = 'wordform[' . self::$wordform_form_id . '][rating][' . $key . '][scale]';
			$low_text_name         = 'wordform[' . self::$wordform_form_id . '][rating][' . $key . '][lowText]';
			$high_text_name        = 'wordform[' . self::$wordform_form_id . '][rating][' . $key . '][highText]';

			$labelname          = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Rating', 'wordform-pro' );
			$rating_scale       = isset( $element['scale'] ) ? max( 3, min( 10, absint( $element['scale'] ) ) ) : 5;
			$low_text           = isset( $element['lowText'] ) ? sanitize_text_field( $element['lowText'] ) : __( 'Poor', 'wordform-pro' );
			$high_text          = isset( $element['highText'] ) ? sanitize_text_field( $element['highText'] ) : __( 'Excellent', 'wordform-pro' );
			$is_required        = isset( $element['required'] ) && 'true' === (string) $element['required'];
			$labelname_required = $is_required ? $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>' : $labelname;

			$stars_markup = '';
			for ( $index = 1; $index <= $rating_scale; $index++ ) {
				$stars_markup .= '<button type="button" class="sc-wordform-built-rating-star" data-wordform-rating-value="' . esc_attr( $index ) . '" aria-label="' . esc_attr( sprintf( __( '%1$d of %2$d', 'wordform-pro' ), $index, $rating_scale ) ) . '" aria-pressed="false"><i class="fa-solid fa-star" aria-hidden="true"></i></button>';
			}

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-rating-wrapper', $element ) ) . '" data-wordform-rating-wrapper data-wordform-rating-max="' . esc_attr( $rating_scale ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-rating-element-label-wrapper"><label class="sc-wordform-built-rating-element-label">' . $labelname_required . '</label></div>';
			$wrapper_with_element .= self::wordform_render_field_help_text( $element );
			$wrapper_with_element .= '<div class="sc-wordform-built-rating-stars" data-wordform-rating-stars>' . $stars_markup . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-rating-scale-labels"><span class="sc-wordform-built-rating-scale-low">' . esc_html( $low_text ) . '</span><span class="sc-wordform-built-rating-scale-high">' . esc_html( $high_text ) . '</span></div>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-built-rating-value" name="' . esc_attr( $name ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $scale_hidden_name ) . '" value="' . esc_attr( $rating_scale ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $low_text_name ) . '" value="' . esc_attr( $low_text ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $high_text_name ) . '" value="' . esc_attr( $high_text ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Likert / Matrix field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_likert( $key = 0, $element = array() ) {
			$base_name              = 'wordform[' . self::$wordform_form_id . '][likert][' . $key . ']';
			$label_hidden_name      = $base_name . '[label]';
			$value_required_status  = $base_name . '[required]';
			$labelname              = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Likert Scale', 'wordform-pro' );
			$row_labels             = isset( $element['rowLabels'] ) && is_array( $element['rowLabels'] ) ? array_values( array_filter( array_map( 'sanitize_text_field', $element['rowLabels'] ) ) ) : array();
			$column_labels          = isset( $element['columnLabels'] ) && is_array( $element['columnLabels'] ) ? array_values( array_filter( array_map( 'sanitize_text_field', $element['columnLabels'] ) ) ) : array();

			if ( empty( $row_labels ) ) {
				$row_labels = array( 'Quality', 'Speed', 'Support' );
			}
			if ( count( $column_labels ) < 2 ) {
				$column_labels = array( 'Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree' );
			}

			$is_required        = isset( $element['required'] ) && 'true' === (string) $element['required'];
			$labelname_required = $is_required ? $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>' : $labelname;

			$header_cells = '<th scope="col" class="sc-wordform-built-likert-header-cell is-corner"></th>';
			foreach ( $column_labels as $column_index => $column_label ) {
				$header_cells .= '<th scope="col" class="sc-wordform-built-likert-header-cell">' . esc_html( $column_label ) . '</th>';
			}

			$body_rows = '';
			foreach ( $row_labels as $row_index => $row_label ) {
				$row_name  = $base_name . '[values][' . $row_index . ']';
				$row_cells = '<th scope="row" class="sc-wordform-built-likert-row-label">' . esc_html( $row_label ) . '</th>';
				foreach ( $column_labels as $column_index => $column_label ) {
					$choice_id = 'sc-wordform-likert-' . self::$wordform_form_id . '-' . $key . '-' . $row_index . '-' . $column_index;
					$row_cells .= '<td class="sc-wordform-built-likert-choice-cell"><label class="sc-wordform-built-likert-choice-label" for="' . esc_attr( $choice_id ) . '"><input type="radio" id="' . esc_attr( $choice_id ) . '" class="sc-wordform-built-likert-choice-input" name="' . esc_attr( $row_name ) . '" value="' . esc_attr( $column_label ) . '" /><span class="sc-wordform-built-likert-choice-ui" aria-hidden="true"></span><span class="sc-wordform-built-likert-choice-mobile-label">' . esc_html( $column_label ) . '</span></label></td>';
				}
				$body_rows .= '<tr class="sc-wordform-built-likert-row" data-wordform-likert-row="' . esc_attr( $row_index ) . '">' . $row_cells . '</tr>';
			}

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-likert-wrapper', $element ) ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-likert-element-label-wrapper"><label class="sc-wordform-built-likert-element-label">' . $labelname_required . '</label></div>';
			$wrapper_with_element .= self::wordform_render_field_help_text( $element );
			$wrapper_with_element .= '<div class="sc-wordform-built-likert-table-shell"><table class="sc-wordform-built-likert-table"><thead><tr>' . $header_cells . '</tr></thead><tbody>' . $body_rows . '</tbody></table></div>';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			foreach ( $row_labels as $row_index => $row_label ) {
				$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $base_name . '[rowLabels][' . $row_index . ']' ) . '" value="' . esc_attr( $row_label ) . '" />';
			}
			foreach ( $column_labels as $column_index => $column_label ) {
				$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $base_name . '[columnLabels][' . $column_index . ']' ) . '" value="' . esc_attr( $column_label ) . '" />';
			}
			$wrapper_with_element .= '</div>';

			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Url Field
		 * $param - $element - array
		 */
		public static function build_url( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][url][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][url][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][url][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}
			
			$label                            = '<div class="sc-wordform-built-url-element-label-wrapper"><label class="sc-wordform-built-url-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<input type="url" class="sc-wordform-built-url-element" name="' . esc_attr( $name ) . '"' . self::wordform_render_shared_default_value_attribute( $element ) . ' ' . $placeholder_text . esc_attr( $required ) . '/>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-url-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Tel Field
		 * $param - $element - array
		 */
		public static function build_tel( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][tel][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][tel][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][tel][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			// Phone Number Minimum Length Value
			if ( isset( $element['minlength'] ) && isset( $element['minlength'] ) > 0 ) {
				$minlength = sanitize_text_field( $element['minlength'] );
			} else {
				$minlength = 6;
			}

			// Phone Number Maximum Length Value
			if ( isset( $element['maxlength'] ) && isset( $element['maxlength'] ) > 0 ) {
				$maxlength = sanitize_text_field( $element['maxlength'] );
			} else {
				$maxlength = 14;
			}

			// Regex Pattern Value - Remove escaping or unexpected chars 
			if ( isset( $element['pattern'] ) && ! empty( isset( $element['pattern'] ) ) ) {
				$regex_pattern = self::cleanRegexPattern( $element['pattern'] );
			} else {
				// Generic Flexible International - Pattern="^\+?[0-9]{6,14}$" - Ex: +33123456789,49891234567
				$regex_pattern = '^\+?[0-9]{6,14}$';
			}

			// Tel Hints true | false - If true then add element to show example phone number of selected regex pattern next to Tel label name
			if ( isset( $element['telhints'] ) && $element['telhints'] == 'true' ) {				
				// If true - get tel hnts example numbers
				if ( isset( $element['telhintsNumber'] ) && ! empty( $element['telhintsNumber'] )  ) {
					$telhints = ' ( <small class="wordform-tel-element-phone-hints"><em>'. $element['telhintsNumber'] . '</em></small> )';
				}
				else {
					// Tel hints example number not found - so keep empty
					$telhints = '';	
				}
			} else {
				$telhints = '';
			}

			$label                            = '<div class="sc-wordform-built-tel-element-label-wrapper"><label class="sc-wordform-built-tel-element-label" >' . $labelname_required . $telhints . '</label></div>';
			$input                            = '<input type="tel" class="sc-wordform-built-tel-element" name="' . esc_attr( $name ) . '" minlength="' . esc_attr( $minlength ) . '" maxlength="' . esc_attr( $maxlength ) . '" pattern="' . esc_attr( $regex_pattern ) . '"' . self::wordform_render_shared_default_value_attribute( $element ) . ' ' . $placeholder_text . esc_attr( $required ) . '/>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';			
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-tel-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}


		/**
		 * Build Date Field
		 * $param - $element - array
		 */
		public static function build_date( $key = 0, $element = array() ) {
			// Get today's date
			$today = new DateTime();			
			// Clone for previous and next year
			$prevYear = clone $today;
			$nextYear = clone $today;
			// Modify dates
			$prevYear->modify('-1 year');
			$nextYear->modify('+1 year');
			// Format as YYYY-MM-DD
			$today = $today->format('Y-m-d');
			$prevYear = $prevYear->format('Y-m-d');
			$nextYear = $nextYear->format('Y-m-d');

			$name                  = 'wordform[' . self::$wordform_form_id . '][date][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][date][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][date][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			// // Min Date Value - Format: YYYY-MM-DD
			// if ( isset( $element['min'] ) ) {				
			// 	// If Min date greater than Today's date then fix it - set Min date -1 year back from Today's date
			// 	$min = ( $element['min'] > $today )? date("Y-m-d", strtotime( $today . " -1 year")) : sanitize_text_field( $element['min'] );
			// } else {
			// 	$min = $prevYear; 
			// }

			// // Max Date Value - Format: YYYY-MM-DD
			// if ( isset( $element['max'] ) ) {
			// 	// If Max date less than Today's date then fix it - set Max date +1 year ahead from Today's date
			// 	$max = ( $element['max'] < $element['min'] )? date("Y-m-d", strtotime( $today . " +1 year")) : sanitize_text_field( $element['max'] );
			// } else {
			// 	$max = $nextYear;
			// }

			// If checked then show Default Date - Format: YYYY-MM-DD
			if ( isset( $element['showDefaultDate'] ) && $element['showDefaultDate'] == 'true' ) {
				$format = 'Y-m-d';
				$date = $element['defaultDate'];				
				$d = DateTime::createFromFormat($format, $date);				
				// If date format found valid - '2025-09-21'
    			if ( $d && $d->format($format) === $date ) {
					$default_date = sanitize_text_field( $element['defaultDate'] );
				} else {
					$default_date = '';	
				}				
			} else {
				$default_date = '';
			}

			// Default Date Display Format
			if ( isset( $element['defaultDateFormat'] ) && ! empty( $element['defaultDateFormat'] ) ) {
				$date_display_format = $element['defaultDateFormat'];
			}
			else {
				$date_display_format = 'Month D, YYYY';
			}

			$calendar_accent_color  = ! empty( $element['calendarAccentColor'] ) ? sanitize_hex_color( $element['calendarAccentColor'] ) : '#2563eb';
			$calendar_surface_color = ! empty( $element['calendarSurfaceColor'] ) ? sanitize_hex_color( $element['calendarSurfaceColor'] ) : '#ffffff';
			$calendar_text_color    = ! empty( $element['calendarTextColor'] ) ? sanitize_hex_color( $element['calendarTextColor'] ) : '#0f172a';
			$min_date               = ! empty( $element['minDate'] ) ? sanitize_text_field( $element['minDate'] ) : '';
			$max_date               = ! empty( $element['maxDate'] ) ? sanitize_text_field( $element['maxDate'] ) : '';
			$disable_past_dates     = ( isset( $element['disablePastDates'] ) && 'true' === (string) $element['disablePastDates'] ) ? 'true' : 'false';
			$disable_future_dates   = ( isset( $element['disableFutureDates'] ) && 'true' === (string) $element['disableFutureDates'] ) ? 'true' : 'false';
			$current_site_date      = current_time( 'Y-m-d' );

			// Input Field Calendar SVG Icon
			$calendar_icon = '<span class="sc-wordform-built-date-element-input-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 24 24">  <path d="M19 4h-1V2h-2v2H8V2H6v2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z"/></svg></span>';
			// $calendar_icon = '';	

			$label                            = '<div class="sc-wordform-built-date-element-label-wrapper"><label class="sc-wordform-built-date-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<div class="sc-wordform-built-date-input-shell"><input type="text" class="sc-wordform-built-date-element" data-default-date="' . esc_attr( $default_date ) . '" data-display-format="'. esc_attr( $date_display_format ) . '" data-calendar-accent-color="' . esc_attr( $calendar_accent_color ) . '" data-calendar-surface-color="' . esc_attr( $calendar_surface_color ) . '" data-calendar-text-color="' . esc_attr( $calendar_text_color ) . '" data-min-date="' . esc_attr( $min_date ) . '" data-max-date="' . esc_attr( $max_date ) . '" data-disable-past-dates="' . esc_attr( $disable_past_dates ) . '" data-disable-future-dates="' . esc_attr( $disable_future_dates ) . '" data-current-site-date="' . esc_attr( $current_site_date ) . '" value="" ' . $placeholder_text . esc_attr( $required ) . ' />' . $calendar_icon . '</div>';			
			$input                           .= '<input type="hidden" class="sc-wordform-built-date-element-hidden-rawdate" name="' . esc_attr( $name ) . '" value="'. $default_date . '" />';						
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';						
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';			
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][date][' . esc_attr( $key ) . '][defaultDateFormat]" value="' . esc_attr( $date_display_format ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][date][' . esc_attr( $key ) . '][minDate]" value="' . esc_attr( $min_date ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][date][' . esc_attr( $key ) . '][maxDate]" value="' . esc_attr( $max_date ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][date][' . esc_attr( $key ) . '][disablePastDates]" value="' . esc_attr( $disable_past_dates ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][date][' . esc_attr( $key ) . '][disableFutureDates]" value="' . esc_attr( $disable_future_dates ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-date-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Time Field
		 * $param - $element - array
		 */
		public static function build_time( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][time][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][time][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][time][' . $key . '][required]';

			$labelname = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : '';

			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {
				$placeholder_text = ' placeholder = "' . esc_attr( $element['placeholderText'] ) . '" ';
			} else {
				$placeholder_text = '';
			}

			$default_value = isset( $element['defaultTime'] ) ? sanitize_text_field( $element['defaultTime'] ) : '';
			$time_display_mode = isset( $element['timeDisplayMode'] ) && '12h' === sanitize_text_field( $element['timeDisplayMode'] ) ? '12h' : '24h';
			$time_display_format = '12h' === $time_display_mode ? 'hh:mm TT' : 'HH:mm';
			$clock_icon = '<span class="sc-wordform-built-time-element-input-clock-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M12 1a11 11 0 1 0 11 11A11.013 11.013 0 0 0 12 1zm0 20a9 9 0 1 1 9-9a9.01 9.01 0 0 1-9 9zm.5-14h-1v6l5.25 3.15l.5-.85l-4.75-2.8z"/></svg></span>';

			$label                            = '<div class="sc-wordform-built-time-element-label-wrapper"><label class="sc-wordform-built-time-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<div class="sc-wordform-built-time-input-shell"><input type="text" class="sc-wordform-built-time-element" data-time-format="' . esc_attr( $time_display_format ) . '" data-default-time="' . esc_attr( $default_value ) . '" value="" ' . $placeholder_text . esc_attr( $required ) . ' />' . $clock_icon . '</div>';
			$input                           .= '<input type="hidden" class="sc-wordform-built-time-element-hidden-rawtime" name="' . esc_attr( $name ) . '" value="' . esc_attr( $default_value ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][time][' . esc_attr( $key ) . '][timeDisplayMode]" value="' . esc_attr( $time_display_mode ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-time-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}


		/**
		 * Build DateTime Field
		 * $param - $element - array
		 */
		public static function build_datetime( $key = 0, $element = array() ) {
			// echo '<pre>';
			// print_r( $element );
			// echo '</pre>';
			// exit;

			// Get today's date
			$today = new DateTime();			
			// Clone for previous and next year
			$prevYear = clone $today;
			$nextYear = clone $today;
			// Modify dates
			$prevYear->modify('-1 year');
			$nextYear->modify('+1 year');
			// Format as YYYY-MM-DD
			$today = $today->format('Y-m-d');
			$prevYear = $prevYear->format('Y-m-d');
			$nextYear = $nextYear->format('Y-m-d');

			$name                  = 'wordform[' . self::$wordform_form_id . '][datetime][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][datetime][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][datetime][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			// Default DateTime Setting Options
			// none: Do not show defaut datetime | setDateTime: Show selected DateTime | currentDateTime: Show current DateTime  - to form users
			$default_datetime_setting = isset( $element['defaultDateTimeSetting'] ) && ! empty( $element['defaultDateTimeSetting'] ) ? $element['defaultDateTimeSetting'] : 'currentDateTime';

			// Show Placeholder Text - If PlaceholderShow is checked & Default Display DateTime setting is 'none'
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				 
				if ( $default_datetime_setting == 'none' ) {
					$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
				}								
				else {
					$placeholder_text = '';	
				}
			} else {				
				$placeholder_text = '';
			}


			// DateTime Display Format
			if ( isset( $element['defaultDateTimeFormat'] ) && ! empty( $element['defaultDateTimeFormat'] ) ) {
				$datetime_display_format = $element['defaultDateTimeFormat'];
			}
			else {
				$datetime_display_format = 'yy-mm-dd HH:mm';
			}

			// Resolve the default datetime shown to frontend users based on the selected mode.
			if ( isset( $default_datetime_setting ) && 'currentDateTime' === $default_datetime_setting ) {
				$default_date_time = current_time( 'Y-m-d H:i' );
			} elseif ( isset( $default_datetime_setting ) && 'setDateTime' === $default_datetime_setting && ! empty( $element['defaultDateTime'] ) ) {
				$default_date_time = sanitize_text_field( $element['defaultDateTime'] );
			} else {
				$default_date_time = '';
			}

			// DateTime Display Format Hint
			if ( isset( $element['displayFormatHint'] ) && ! empty( $element['displayFormatHint'] ) ) {
				
			}
			// DateTime Display Format Hint Hint true | false - If true shown next to DateTime label name
			if ( isset( $element['displayFormatHint'] ) && $element['displayFormatHint'] == 'true' ) {												
				$datetime_format_hint = ' ( <small class="wordform-datetime-element-format-hints"><em>'. $datetime_display_format . '</em></small> )';
			} else {
				$datetime_format_hint = '';
			}

			$calendar_accent_color  = ! empty( $element['calendarAccentColor'] ) ? sanitize_hex_color( $element['calendarAccentColor'] ) : '#2563eb';
			$calendar_surface_color = ! empty( $element['calendarSurfaceColor'] ) ? sanitize_hex_color( $element['calendarSurfaceColor'] ) : '#ffffff';
			$calendar_text_color    = ! empty( $element['calendarTextColor'] ) ? sanitize_hex_color( $element['calendarTextColor'] ) : '#0f172a';
			$min_datetime           = ! empty( $element['minDateTime'] ) ? sanitize_text_field( $element['minDateTime'] ) : '';
			$max_datetime           = ! empty( $element['maxDateTime'] ) ? sanitize_text_field( $element['maxDateTime'] ) : '';
			$disable_past_dates     = ( isset( $element['disablePastDates'] ) && 'true' === (string) $element['disablePastDates'] ) ? 'true' : 'false';
			$disable_future_dates   = ( isset( $element['disableFutureDates'] ) && 'true' === (string) $element['disableFutureDates'] ) ? 'true' : 'false';
			$current_site_datetime  = current_time( 'Y-m-d H:i' );

			// Input Field Calendar SVG Icon
			$calendar_icon = '<span class="sc-wordform-built-datetime-element-input-calendar-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 24 24">  <path d="M19 4h-1V2h-2v2H8V2H6v2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z"/></svg></span>';
			$clock_icon = '<span class="sc-wordform-built-datetime-element-input-clock-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M12 1a11 11 0 1 0 11 11A11.013 11.013 0 0 0 12 1zm0 20a9 9 0 1 1 9-9a9.01 9.01 0 0 1-9 9zm.5-14h-1v6l5.25 3.15l.5-.85l-4.75-2.8z"/></svg></span>';

			$label                            = '<div class="sc-wordform-built-date-element-label-wrapper"><label class="sc-wordform-built-datetime-element-label" >' . $labelname_required . $datetime_format_hint . '</label></div>';
			$input                            = '<div class="sc-wordform-built-datetime-input-shell"><input type="text" class="sc-wordform-built-datetime-element" data-datetime-format="' . esc_attr( $datetime_display_format ) . '" data-datetime-value="' . esc_attr( $default_date_time ) .  '" data-calendar-accent-color="' . esc_attr( $calendar_accent_color ) . '" data-calendar-surface-color="' . esc_attr( $calendar_surface_color ) . '" data-calendar-text-color="' . esc_attr( $calendar_text_color ) . '" data-min-datetime="' . esc_attr( $min_datetime ) . '" data-max-datetime="' . esc_attr( $max_datetime ) . '" data-disable-past-dates="' . esc_attr( $disable_past_dates ) . '" data-disable-future-dates="' . esc_attr( $disable_future_dates ) . '" data-current-site-datetime="' . esc_attr( $current_site_datetime ) . '" value="" ' . $placeholder_text . esc_attr( $required ) . ' />' . $calendar_icon . $clock_icon . '</div>';			
			$input                           .= '<input type="hidden" class="sc-wordform-built-datetime-element-hidden-rawdatetime" name="' . esc_attr( $name ) . '" value="'. $default_date_time . '" />';						
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';						
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';			
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][datetime][' . esc_attr( $key ) . '][defaultDateTimeFormat]" value="' . esc_attr( $datetime_display_format ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][datetime][' . esc_attr( $key ) . '][timeDisplayMode]" value="' . esc_attr( isset( $element['timeDisplayMode'] ) && '12h' === sanitize_text_field( $element['timeDisplayMode'] ) ? '12h' : '24h' ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][datetime][' . esc_attr( $key ) . '][minDateTime]" value="' . esc_attr( $min_datetime ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][datetime][' . esc_attr( $key ) . '][maxDateTime]" value="' . esc_attr( $max_datetime ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][datetime][' . esc_attr( $key ) . '][disablePastDates]" value="' . esc_attr( $disable_past_dates ) . '" />';
			$input                           .= '<input type="hidden" name="wordform[' . esc_attr( self::$wordform_form_id ) . '][datetime][' . esc_attr( $key ) . '][disableFutureDates]" value="' . esc_attr( $disable_future_dates ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-datetime-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Email Field
		 * $param - $element - array
		 */
		public static function build_email( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][email][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][email][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][email][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			$label                            = '<div class="sc-wordform-built-email-element-label-wrapper"><label class="sc-wordform-built-email-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<input type="email" class="sc-wordform-built-email-element" name="' . esc_attr( $name ) . '"' . self::wordform_render_shared_default_value_attribute( $element ) . ' ' . $placeholder_text . esc_attr( $required ) . '/>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-email-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Address Field
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_address( $key = 0, $element = array() ) {
			$base_name              = 'wordform[' . self::$wordform_form_id . '][address][' . $key . ']';
			$label_hidden_name      = $base_name . '[label]';
			$value_required_status  = $base_name . '[required]';
			$labelname              = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : 'Address';
			$placeholder_show       = ! isset( $element['placeholderShow'] ) || 'true' === (string) $element['placeholderShow'];
			$street_placeholder     = isset( $element['placeholderStreet'] ) ? sanitize_text_field( $element['placeholderStreet'] ) : 'Street Address';
			$city_placeholder       = isset( $element['placeholderCity'] ) ? sanitize_text_field( $element['placeholderCity'] ) : 'City';
			$state_placeholder      = isset( $element['placeholderState'] ) ? sanitize_text_field( $element['placeholderState'] ) : 'State / Region';
			$zip_placeholder        = isset( $element['placeholderZip'] ) ? sanitize_text_field( $element['placeholderZip'] ) : 'ZIP / Postal Code';
			$country_placeholder    = isset( $element['placeholderCountry'] ) ? sanitize_text_field( $element['placeholderCountry'] ) : 'Country';
			$is_required            = isset( $element['required'] ) && 'true' === (string) $element['required'];
			$required_attr          = $is_required ? ' required ' : '';
			$labelname_required     = $is_required ? $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>' : $labelname;
			$street_placeholder_attr = $placeholder_show ? ' placeholder="' . esc_attr( $street_placeholder ) . '"' : '';
			$city_placeholder_attr   = $placeholder_show ? ' placeholder="' . esc_attr( $city_placeholder ) . '"' : '';
			$state_placeholder_attr  = $placeholder_show ? ' placeholder="' . esc_attr( $state_placeholder ) . '"' : '';
			$zip_placeholder_attr    = $placeholder_show ? ' placeholder="' . esc_attr( $zip_placeholder ) . '"' : '';
			$country_placeholder_attr = $placeholder_show ? ' placeholder="' . esc_attr( $country_placeholder ) . '"' : '';

			$label = '<div class="sc-wordform-built-address-element-label-wrapper"><label class="sc-wordform-built-address-element-label">' . $labelname_required . '</label></div>';
			$input = '<div class="sc-wordform-built-address-grid">';
			$input .= '<input type="text" class="sc-wordform-built-address-element sc-wordform-built-address-street" name="' . esc_attr( $base_name . '[values][street]' ) . '"' . $street_placeholder_attr . esc_attr( $required_attr ) . ' />';
			$input .= '<div class="sc-wordform-built-address-grid-inner">';
			$input .= '<input type="text" class="sc-wordform-built-address-element sc-wordform-built-address-city" name="' . esc_attr( $base_name . '[values][city]' ) . '"' . $city_placeholder_attr . esc_attr( $required_attr ) . ' />';
			$input .= '<input type="text" class="sc-wordform-built-address-element sc-wordform-built-address-state" name="' . esc_attr( $base_name . '[values][state]' ) . '"' . $state_placeholder_attr . esc_attr( $required_attr ) . ' />';
			$input .= '</div>';
			$input .= '<div class="sc-wordform-built-address-grid-inner">';
			$input .= '<input type="text" class="sc-wordform-built-address-element sc-wordform-built-address-zip" name="' . esc_attr( $base_name . '[values][zip]' ) . '"' . $zip_placeholder_attr . esc_attr( $required_attr ) . ' />';
			$input .= '<input type="text" class="sc-wordform-built-address-element sc-wordform-built-address-country" name="' . esc_attr( $base_name . '[values][country]' ) . '"' . $country_placeholder_attr . esc_attr( $required_attr ) . ' />';
			$input .= '</div>';
			$input .= '</div>';
			$input .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-address-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Section / HTML block.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_sectionhtml( $key = 0, $element = array() ) {
			$labelname = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : 'Section Title';
			$content   = isset( $element['content'] ) ? wp_kses_post( $element['content'] ) : '';

			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-sectionhtml-wrapper', $element ) ) . '">';
			$wrapper_with_element            .= '<div class="sc-wordform-built-sectionhtml-title">' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element            .= '<div class="sc-wordform-built-sectionhtml-content">' . wpautop( $content ) . '</div>';
			$wrapper_with_element            .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Mask Input field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_maskinput( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][maskinput][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][maskinput][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][maskinput][' . $key . '][required]';
			$pattern_hidden_name   = 'wordform[' . self::$wordform_form_id . '][maskinput][' . $key . '][pattern]';
			$labelname             = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : 'Masked Input';
			$pattern               = isset( $element['pattern'] ) ? sanitize_text_field( $element['pattern'] ) : '^[A-Z]{2}-[0-9]{5}$';
			$is_required           = isset( $element['required'] ) && 'true' === (string) $element['required'];
			$required_attr         = $is_required ? ' required ' : '';
			$labelname_required    = $is_required ? $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>' : $labelname;
			$placeholder_text      = '';

			if ( isset( $element['placeholderShow'] ) && 'true' === (string) $element['placeholderShow'] ) {
				$placeholder_value = isset( $element['placeholderText'] ) ? sanitize_text_field( $element['placeholderText'] ) : 'AB-12345';
				$placeholder_text  = ' placeholder="' . esc_attr( $placeholder_value ) . '" ';
			}

			$label                            = '<div class="sc-wordform-built-maskinput-element-label-wrapper"><label class="sc-wordform-built-maskinput-element-label">' . $labelname_required . '</label></div>';
			$input                            = '<input type="text" class="sc-wordform-built-maskinput-element" name="' . esc_attr( $name ) . '"' . self::wordform_render_shared_default_value_attribute( $element ) . $placeholder_text . ' pattern="' . esc_attr( $pattern ) . '"' . esc_attr( $required_attr ) . ' />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $pattern_hidden_name ) . '" value="' . esc_attr( $pattern ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-maskinput-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Hidden field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_hidden( $key = 0, $element = array() ) {
			$name               = 'wordform[' . self::$wordform_form_id . '][hidden][' . $key . '][values][]';
			$label_hidden_name  = 'wordform[' . self::$wordform_form_id . '][hidden][' . $key . '][label]';
			$default_value_name = 'wordform[' . self::$wordform_form_id . '][hidden][' . $key . '][defaultValue]';
			$labelname          = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : 'Hidden Field';
			$default_value      = isset( $element['defaultValue'] ) ? sanitize_text_field( $element['defaultValue'] ) : '';

			$wrapper_with_element             = '<input type="hidden" class="sc-wordform-built-hidden-element" name="' . esc_attr( $name ) . '" value="' . esc_attr( $default_value ) . '" />';
			$wrapper_with_element            .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element            .= '<input type="hidden" name="' . esc_attr( $default_value_name ) . '" value="' . esc_attr( $default_value ) . '" />';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Signature field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_signature( $key = 0, $element = array() ) {
			$name                   = 'wordform[' . self::$wordform_form_id . '][signature][' . $key . '][values][]';
			$label_hidden_name      = 'wordform[' . self::$wordform_form_id . '][signature][' . $key . '][label]';
			$value_required_status  = 'wordform[' . self::$wordform_form_id . '][signature][' . $key . '][required]';
			$clear_button_text_name = 'wordform[' . self::$wordform_form_id . '][signature][' . $key . '][clearButtonText]';
			$canvas_height_name     = 'wordform[' . self::$wordform_form_id . '][signature][' . $key . '][canvasHeight]';
			$labelname              = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Signature', 'wordform-pro' );
			$clear_button_text      = isset( $element['clearButtonText'] ) ? sanitize_text_field( $element['clearButtonText'] ) : __( 'Clear Signature', 'wordform-pro' );
			$canvas_height          = isset( $element['canvasHeight'] ) ? max( 120, min( 360, absint( $element['canvasHeight'] ) ) ) : 180;
			$is_required            = isset( $element['required'] ) && 'true' === (string) $element['required'];
			$labelname_required     = $is_required ? $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>' : $labelname;

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-signature-wrapper', $element ) ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-signature-element-label-wrapper"><label class="sc-wordform-built-signature-element-label">' . $labelname_required . '</label></div>';
			$wrapper_with_element .= self::wordform_render_field_help_text( $element );
			$wrapper_with_element .= '<div class="sc-wordform-built-signature-canvas-shell" data-wordform-signature-shell style="height:' . esc_attr( $canvas_height ) . 'px;">';
			$wrapper_with_element .= '<canvas class="sc-wordform-built-signature-canvas" data-wordform-signature-canvas data-wordform-signature-height="' . esc_attr( $canvas_height ) . '"></canvas>';
			$wrapper_with_element .= '<div class="sc-wordform-built-signature-placeholder">' . esc_html__( 'Sign here', 'wordform-pro' ) . '</div>';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-signature-actions"><button type="button" class="button button-secondary sc-wordform-built-signature-clear-button" data-wordform-signature-clear>' . esc_html( $clear_button_text ) . '</button></div>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-built-signature-data" name="' . esc_attr( $name ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $clear_button_text_name ) . '" value="' . esc_attr( $clear_button_text ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $canvas_height_name ) . '" value="' . esc_attr( $canvas_height ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Captcha Field
		 * $param - $key - int
		 * $param - $element - array
		 */
		public static function build_captcha( $key = 0, $element = array() ) {
			$name                        = 'wordform[' . self::$wordform_form_id . '][captcha][' . $key . '][values][]';
			$label_hidden_name           = 'wordform[' . self::$wordform_form_id . '][captcha][' . $key . '][label]';
			$value_required_status       = 'wordform[' . self::$wordform_form_id . '][captcha][' . $key . '][required]';
			$captcha_value_hidden_name   = 'wordform[' . self::$wordform_form_id . '][captcha][' . $key . '][captcha]';
			$captcha_created_hidden_name = 'wordform[' . self::$wordform_form_id . '][captcha][' . $key . '][captcha_created_status]';
			$captcha_session_hidden_name = 'wordform[' . self::$wordform_form_id . '][captcha][' . $key . '][captcha_session_name]';
			$captcha_transient_name      = 'sftcy_wordform_' . str_replace( '-', '_', self::$wordform_form_id ) . '_' . $key . '_' . random_int( 99999, 9999999 );

			// Template Name
			if ( isset( $element['templateName'] ) && ! empty( $element['templateName'] ) ) {
				$template_name = sanitize_text_field( $element['templateName'] );
			} else {
				$template_name = 'all'; // Default - render all templates randomly
			}

			$captcha_style_mode       = isset( $element['styleMode'] ) ? sanitize_key( $element['styleMode'] ) : 'template';
			$captcha_background_color = isset( $element['backgroundColor'] ) ? sanitize_hex_color( $element['backgroundColor'] ) : '#eef2ff';
			$captcha_text_color       = isset( $element['textColor'] ) ? sanitize_hex_color( $element['textColor'] ) : '#111827';
			$captcha_noise_color      = isset( $element['noiseColor'] ) ? sanitize_hex_color( $element['noiseColor'] ) : '#cbd5e1';
			$captcha_digit_length     = isset( $element['digitLength'] ) ? absint( $element['digitLength'] ) : 4;
			$captcha_font_style       = isset( $element['fontStyle'] ) ? sanitize_key( $element['fontStyle'] ) : 'blackopsone';

			// Captcha template Align
			if ( isset( $element['align'] ) && ! empty( $element['align'] ) ) {				
				$align = $element['align'];
			} else {				
				$align = '';
			}

			// Generate Captcha
			$captcha = SftcyWordformCaptcha::wordform_create_captcha_image(
				$template_name,
				$captcha_digit_length,
				array(
					'styleMode'       => $captcha_style_mode,
					'backgroundColor' => $captcha_background_color ? $captcha_background_color : '#eef2ff',
					'textColor'       => $captcha_text_color ? $captcha_text_color : '#111827',
					'noiseColor'      => $captcha_noise_color ? $captcha_noise_color : '#cbd5e1',
					'fontStyle'       => $captcha_font_style,
				)
			);
			if ( isset( $captcha['status'] ) && $captcha['status'] === 'success' ) {
				$captcha_container      = '<div class="sc-wordform-captcha-container-wrapper ' . $align . '"><img src="' . $captcha['imageBase64Src'] . '" alt="Captcha Image" /></div>';
				$captcha_value          = $captcha['captchaValue'];
				$captcha_created_status = 'success';
				set_transient( $captcha_transient_name, $captcha_value, SftcyWordformCaptcha::wordform_captcha_session_expired_duration() );
			} else {
				$captcha_container      = '<div class="sc-wordform-captcha-container-wrapper ' . $align .' "></div>';
				$captcha_value          = '';
				$captcha_created_status = 'fail';
			}

			if ( isset( $element['label'] ) && '' !== trim( (string) $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = __( 'Captcha', 'wordform-pro' );
			}

			$is_required = ! isset( $element['required'] ) || 'true' === (string) $element['required'];
			$required    = $is_required ? ' required ' : '';

			// Placeholder Text
			if ( isset( $element['placeholderShow'] ) && $element['placeholderShow'] == 'true' ) {				
				$placeholder_text = ' placeholder = "'. $element['placeholderText'] .'" ';
			} else {				
				$placeholder_text = '';
			}

			if ( $is_required ) {
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$labelname_required = $labelname . ' <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			}

			$label                            = '<div class="sc-wordform-built-captcha-element-label-wrapper"><label class="sc-wordform-built-captcha-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<input type="text" class="sc-wordform-built-captcha-element" name="' . esc_attr( $name ) . '" ' . $placeholder_text . esc_attr( $required ) . '/>';
			$input                           .= $captcha_container;
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $is_required ? 'true' : 'false' ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $captcha_value_hidden_name ) . '" value="' . esc_attr( $captcha_value ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $captcha_created_hidden_name ) . '" value="' . esc_attr( $captcha_created_status ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $captcha_session_hidden_name ) . '" value="' . esc_attr( $captcha_transient_name ) . '" />';
			$wrapper_with_element             = '<div class="sc-wordform-built-captcha-wrapper">' . $label . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}


		/**
		 * Build Google reCaptcha Field
		 * $param - $key - int
		 * $param - $element - array
		 */
		public static function build_gcaptcha( $key = 0, $element = array() ) {
			// reCaptcha Settings
			$re_captcha_container = '';			
			$gcaptcha_data = SftcyWordformBase::wordform_settings_page_grecaptcha_config();
			$recaptcha_theme = $gcaptcha_data['gcaptcha-theme']; // dark | light

			$name                         = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][values][]';
			$label_hidden_name            = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][label]';
			$value_required_status        = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][required]';
			$gcaptcha_token_hidden_name   = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][token]';
			$gcaptcha_action_hidden_name  = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][action]';
			$gcaptcha_type_hidden_name 	  = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][type]';
			$gcaptcha_version_hidden_name = 'wordform[' . self::$wordform_form_id . '][gcaptcha][' . $key . '][version]';

            // Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

            // Label Show | Hide
			if ( isset( $element['labelshow'] ) && $element['labelshow'] == 'true' ) {
				$label_show = true;
			} else {
				$label_show = false;
			}			

			// Captcha protection always required as default
			$required           			  = ' required ';
			// $labelname_required 			  = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';			
			$labelname_required 			  = $labelname . '<small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';			
			$input                            = '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$input                           .= '<input type="hidden" class="wordform-gcaptcha-token-value" name="' . esc_attr( $gcaptcha_token_hidden_name ) . '" value="" />';
			$input                           .= '<input type="hidden" class="wordform-gcaptcha-action-value" name="' . esc_attr( $gcaptcha_action_hidden_name ) . '" value="" />';
			$input                           .= '<input type="hidden" class="wordform-gcaptcha-type-value" name="' . esc_attr( $gcaptcha_type_hidden_name ) . '" value="'. esc_attr( $gcaptcha_data['gcaptcha-type'] ) .'" />';
			$input                           .= '<input type="hidden" class="wordform-gcaptcha-version-value" name="' . esc_attr( $gcaptcha_version_hidden_name ) . '" value="'. esc_attr( $gcaptcha_data['gcaptcha-version'] ) .'" />';

			$label                            = '<div class="sc-wordform-built-gcaptcha-element-label-wrapper"><label class="sc-wordform-built-gcaptcha-element-label" >' . $labelname_required . '</label></div>';
			$error_markup                     = '<div class="sc-wordform-built-gcaptcha-error-wrapper"><small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small></div>';

			// When Keys are V2 Checkbox [ Classic || Enterprise ] DO NOT use data-size="invisible"			
			// When Keys are V3 invisible [ Classic || Enterprise ] use data-size="invisible"			
			if ( ! empty( $gcaptcha_data['gcaptcha-site-key'] ) && $gcaptcha_data['gcaptcha-version'] == 'v2' ) {								
				$re_captcha_container         = '<div class="g-recaptcha" data-sitekey="' . $gcaptcha_data['gcaptcha-site-key'] . '" data-theme="' . $recaptcha_theme . '"></div>';				
			}
			else if ( ! empty( $gcaptcha_data['gcaptcha-site-key'] ) && $gcaptcha_data['gcaptcha-version'] == 'v3' ) {
				//  $re_captcha_container         = '<div class="g-recaptcha" data-sitekey="' . $gcaptcha_data['gcaptcha-site-key'] . '" data-size="invisible" data-theme="' . $recaptcha_theme . '"></div>';
				$re_captcha_container         = '<div class="g-recaptcha" data-sitekey="' . $gcaptcha_data['gcaptcha-site-key'] . '" data-size="invisible" data-theme="' . $recaptcha_theme . '"></div>';
			}
			else {
				$re_captcha_container         = '';
			}			
			
			// Show | Hide reCaptcha Label Name
			if ( $label_show ) {
 				$wrapper_with_element          = '<div class="sc-wordform-built-gcaptcha-wrapper">' . $label . $input . $re_captcha_container . $error_markup . '</div>';
			}
			else {
				$wrapper_with_element          = '<div class="sc-wordform-built-gcaptcha-wrapper">' . $input . $re_captcha_container . $error_markup . '</div>';
			}

			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build hCaptcha Field
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_hcaptcha( $key = 0, $element = array() ) {
			$hcaptcha_data = SftcyWordformBase::wordform_settings_page_hcaptcha_config();
			$hcaptcha_theme = isset( $hcaptcha_data['hcaptcha-theme'] ) ? $hcaptcha_data['hcaptcha-theme'] : 'light';

			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][hcaptcha][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][hcaptcha][' . $key . '][required]';
			$token_hidden_name     = 'wordform[' . self::$wordform_form_id . '][hcaptcha][' . $key . '][token]';

			$labelname = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'hCaptcha', 'wordform-pro' );
			$label_show = ( isset( $element['labelshow'] ) && true == $element['labelshow'] );

			$input  = '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$input .= '<input type="hidden" class="wordform-hcaptcha-token-value" name="' . esc_attr( $token_hidden_name ) . '" value="" />';

			$label_markup = '<div class="sc-wordform-built-hcaptcha-element-label-wrapper"><label class="sc-wordform-built-hcaptcha-element-label">' . esc_html( $labelname ) . '<small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small></label></div>';
			$error_markup = '<div class="sc-wordform-built-hcaptcha-error-wrapper"><small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small></div>';

			if ( ! empty( $hcaptcha_data['hcaptcha-site-key'] ) ) {
				$captcha_container = '<div class="h-captcha" data-sitekey="' . esc_attr( $hcaptcha_data['hcaptcha-site-key'] ) . '" data-theme="' . esc_attr( $hcaptcha_theme ) . '"></div>';
			} else {
				$captcha_container = '<div class="sc-wordform-hcaptcha-placeholder">' . esc_html__( 'Configure hCaptcha keys in Settings to activate this field.', 'wordform-pro' ) . '</div>';
			}

			if ( $label_show ) {
				$wrapper_with_element = '<div class="sc-wordform-built-hcaptcha-wrapper">' . $label_markup . $input . $captcha_container . $error_markup . '</div>';
			} else {
				$wrapper_with_element = '<div class="sc-wordform-built-hcaptcha-wrapper">' . $input . $captcha_container . $error_markup . '</div>';
			}

			self::$built_html_form_elements[] = $wrapper_with_element;
		}


		/**
		 * Build Radio Field
		 * $param - $element - array
		 */
		public static function build_radio( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][radio][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][radio][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][radio][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			// Options
			if ( isset( $element['multiOption'] ) && is_array( $element['multiOption'] ) && array_filter( $element['multiOption'] ) ) {
				$multi_options = '';
				foreach ( $element['multiOption'] as $option ) {
					$options = '';
					$checked = $option['checkStatus'] == 'true' ? ' checked ' : '';

					$options .= '<div class="sc-wordform-built-radio-element-option-wrapper">';
					// $options .= '<input type="radio" class="sc-wordform-built-radio-element" name="' . esc_attr( $name ) . '" value="' . sanitize_text_field( $option['optionText'] ) . '"' . esc_attr( $checked ) . '/>';
					// $options .= '<label class="sc-wordform-built-radio-element-option-text-label">' . sanitize_text_field( $option['optionText'] ) . '</label>';

					$options .= '<label class="sc-wordform-built-radio-element-option-text-label"><input type="radio" class="sc-wordform-built-radio-element" name="' . esc_attr( $name ) . '" value="' . sanitize_text_field( $option['optionText'] ) . '"' . esc_attr( $checked ) . '/>';
					$options .= sanitize_text_field( $option['optionText'] ) . '</label>';

					$options .= '</div>';

					$multi_options .= $options;
				} // foreach
			}

			$label                            = '<div class="sc-wordform-built-radio-element-label-wrapper"><label class="sc-wordform-built-radio-element-label" >' . $labelname_required . '</label></div>';
			$input                            = $multi_options;
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-radio-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Checkbox Field
		 * $param - $element - array
		 */
		public static function build_checkbox( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][checkbox][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][checkbox][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][checkbox][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			// Options
			if ( isset( $element['multiOption'] ) && is_array( $element['multiOption'] ) && array_filter( $element['multiOption'] ) ) {
				$multi_options = '';
				foreach ( $element['multiOption'] as $option ) {
					$options = '';
					$checked = $option['checkStatus'] == 'true' ? ' checked ' : '';

					$options .= '<div class="sc-wordform-built-checkbox-element-option-wrapper">';
					// $options .= '<input type="checkbox" class="sc-wordform-built-checkbox-element" name="' . esc_attr( $name ) . '" value="' . sanitize_text_field( $option['optionText'] ) . '"' . esc_attr( $checked ) . '/>';
					// $options .= '<label class="sc-wordform-built-checkbox-element-option-text-label">' . sanitize_text_field( $option['optionText'] ) . '</label>';

					$options .= '<label class="sc-wordform-built-checkbox-element-option-text-label"><input type="checkbox" class="sc-wordform-built-checkbox-element" name="' . esc_attr( $name ) . '" value="' . sanitize_text_field( $option['optionText'] ) . '"' . esc_attr( $checked ) . '/>';
					$options .=  sanitize_text_field( $option['optionText'] ) . '</label>';

					$options .= '</div>';

					$multi_options .= $options;
				}
			}

			$label                            = '<div class="sc-wordform-built-checkbox-element-label-wrapper"><label class="sc-wordform-built-checkbox-element-label" >' . $labelname_required . '</label></div>';
			$input                            = $multi_options;
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-checkbox-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Select Field
		 * $param - $element - array
		 */
		public static function build_select( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][select][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][select][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][select][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			// Options
			if ( isset( $element['multiOption'] ) && is_array( $element['multiOption'] ) && array_filter( $element['multiOption'] ) ) {
				$multi_options = '';
				foreach ( $element['multiOption'] as $option ) {
					$options = '';
					$checked = $option['checkStatus'] == 'true' ? ' selected ' : '';

					$options .= '<option value="' . sanitize_text_field( $option['optionText'] ) . '" ' . esc_attr( $checked ) . '>' . sanitize_text_field( $option['optionText'] ) . '</option>';

					$multi_options .= $options;
				}
			}

			$label  = '<div class="sc-wordform-built-select-element-label-wrapper"><label class="sc-wordform-built-select-element-label" >' . $labelname_required . '</label></div>';
			$input  = '';
			$input .= '<div class="sc-wordform-built-select-element-wrapper">';
			$input .= '<select class="sc-wordform-built-select-element" name="' . esc_attr( $name ) . '" ' . esc_attr( $required ) . '>';
			$input .= $multi_options;
			$input .= '</select>';
			$input .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$input .= '</div>';

			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-select-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Upload Field
		 * Word file identified ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file
		 * @param Integer $key
		 * @param array $element
		 */
		public static function build_upload( $key = 0, $element = array() ) {            			
			$file_name             = 'wordform[' . self::$wordform_form_id . '][upload][' . $key . '][files][]';						
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][upload][' . $key . '][label]';
			$select_file_label_hidden_name = 'wordform[' . self::$wordform_form_id . '][upload][' . $key . '][selectFileLabel]';
			$file_allowed_types_name = 'wordform[' . self::$wordform_form_id . '][upload][' . $key . '][fileAllowed]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][upload][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Select File label
			if ( isset( $element['selectFileLabel'] ) ) {
				$selectfile_labelname = sanitize_text_field( $element['selectFileLabel'] );
			} else {
				$selectfile_labelname = __('Select File', 'wordform-pro' );
			}

			// Required
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';				
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			// Multiple
			if ( isset( $element['multiple'] ) && $element['multiple'] == 'true' ) {
				$multiple_file_upload = ' multiple ';				
			} else {
				$multiple_file_upload = '';								
			}

			// File Type Options
			if ( isset( $element['multiOption'] ) && is_array( $element['multiOption'] ) && array_filter( $element['multiOption'] ) ) {
				$multi_options = '';
				$allowed_file_types = [];
				foreach ( $element['multiOption'] as $option ) {						
					if ( isset( $option['checkStatus'] ) && $option['checkStatus'] == 'true' ) {
						switch ( $option['fileTypeValue'] ) {
							case 'image':								
								$allowed_file_types[] = 'image/jpg,image/jpeg,image/jpe,image/png,image/gif,image/webp';								 
								break;
							case 'pdf':								
								$allowed_file_types[] = '.pdf,application/pdf';
								break;
							case 'word':								
								$allowed_file_types[] = '.doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document';
								break;	
							case 'excel':
								$allowed_file_types[] = '.xls,.xlsx,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';			
								break;
							case 'csv':
								$allowed_file_types[] = '.csv,application/csv,text/csv,text/comma-separated-values';				
								break;
							case 'text':
								$allowed_file_types[] = '.txt,.asc,.c,.cc,.h,.srt,text/plain';				
								break;	
							case 'audio':
								$allowed_file_types[] = '.mp3,.m4a,.m4b,.aac,.wav,.ra,.ram,.mid,.midi,.wma,audio/mpeg,audio/aac,audio/wav,audio/x-realaudio,audio/midi,audio/x-ms-wma';
								break;
							case 'video':
								$allowed_file_types[] = '.mp4,.m4v,.mpeg,.mpg,.mpe,.mov,.qt,.avi,.webm,.wmv,.3gp,.3gpp,.3g2,.3gp2,video/mp4,video/mpeg,video/quicktime,video/avi,video/webm,video/x-ms-wmv,video/3gpp,video/3gpp2';
								break;		
						}		
					}					
				} // foreach
			    $accept_allowed_file_types = implode( ',', $allowed_file_types );	
			}

			$label                            = '<div class="sc-wordform-built-upload-element-label-wrapper"><label class="sc-wordform-built-upload-element-label" >' . $labelname_required . '</label></div>';			
			$input                            = '<label class="wordform-file-upload-label-wrapper" for="wordformFileUpload-' . esc_attr( $key ) .'"><i class="fa-solid fa-upload wordform-frontend-fileupload-icon"></i> <span class="wordform-frontend-upload-select-file-label">' . esc_html( $selectfile_labelname ) . '</span><br/>';
			$input							 .= '<input id="wordformFileUpload-' . esc_attr( $key ) .'" data-input-typefile-element-key="'. esc_attr( $key ) .'" type="file" accept="' . esc_attr( $accept_allowed_file_types ) . '" class="sc-wordform-built-upload-element" name="' . esc_attr( $file_name ) . '" ' . esc_attr( $required ) . esc_attr( $multiple_file_upload ) . ' /></label>';
			$input							 .= '<ul class="wordform-selected-file-names-list" id="wordformUploadFileSelectedList-' . esc_attr( $key ) .'"></ul>';
			$input                           .= '<small id="wordformUploadTempError-' . esc_attr( $key ) .'" class="sc-wordform-error-msg wordform-temporary-file-selection-error"></small>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $select_file_label_hidden_name ) . '" value="' . esc_attr( $selectfile_labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $file_allowed_types_name ) . '" value="' . esc_attr( $accept_allowed_file_types ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';			
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-upload-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$wordform_file_input_element_built = true;
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Payment Item Field.
		 *
		 * @param int   $key
		 * @param array $element
		 */
		public static function build_payment_item( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][payment_item][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][payment_item][' . $key . '][label]';
			$amount_hidden_name    = 'wordform[' . self::$wordform_form_id . '][payment_item][' . $key . '][amount]';
			$description_name      = 'wordform[' . self::$wordform_form_id . '][payment_item][' . $key . '][description]';
			$labelname             = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Payment Item', 'wordform-pro' );
			$description           = isset( $element['description'] ) ? sanitize_text_field( $element['description'] ) : __( 'Fixed price item', 'wordform-pro' );
			$amount_value          = isset( $element['amount'] ) ? (float) $element['amount'] : 0;
			$formatted_amount      = self::wordform_format_payment_amount( $amount_value );

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-payment-item-wrapper', $element ) ) . '" data-wordform-payment-role="item" data-wordform-payment-amount="' . esc_attr( number_format( $amount_value, 2, '.', '' ) ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-item-card">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-item-card-header">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-item-label">' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-item-amount">' . esc_html( $formatted_amount ) . '</div>';
			$wrapper_with_element .= '</div>';
			if ( ! empty( $description ) ) {
				$wrapper_with_element .= '<div class="sc-wordform-built-payment-item-description">' . esc_html( $description ) . '</div>';
			}
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-item-value" name="' . esc_attr( $name ) . '" value="' . esc_attr( number_format( $amount_value, 2, '.', '' ) ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $amount_hidden_name ) . '" value="' . esc_attr( number_format( $amount_value, 2, '.', '' ) ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $description_name ) . '" value="' . esc_attr( $description ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Coupon Field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_payment_coupon( $key = 0, $element = array() ) {
			$name                = 'wordform[' . self::$wordform_form_id . '][payment_coupon][' . $key . '][values][]';
			$label_hidden_name   = 'wordform[' . self::$wordform_form_id . '][payment_coupon][' . $key . '][label]';
			$coupon_id_name      = 'wordform[' . self::$wordform_form_id . '][payment_coupon][' . $key . '][couponId]';
			$discount_name       = 'wordform[' . self::$wordform_form_id . '][payment_coupon][' . $key . '][discountAmount]';
			$coupon_code_name    = 'wordform[' . self::$wordform_form_id . '][payment_coupon][' . $key . '][couponCode]';
			$labelname           = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Coupon Code', 'wordform-pro' );
			$placeholder_text    = isset( $element['placeholderText'] ) ? sanitize_text_field( $element['placeholderText'] ) : __( 'Enter coupon code', 'wordform-pro' );
			$apply_button_text   = isset( $element['applyButtonText'] ) ? sanitize_text_field( $element['applyButtonText'] ) : __( 'Apply Coupon', 'wordform-pro' );
			$remove_button_text  = isset( $element['removeButtonText'] ) ? sanitize_text_field( $element['removeButtonText'] ) : __( 'Remove Coupon', 'wordform-pro' );
			$invalid_message     = isset( $element['invalidMessage'] ) ? sanitize_text_field( $element['invalidMessage'] ) : __( 'Coupon code is not valid.', 'wordform-pro' );
			$applied_message     = isset( $element['appliedMessage'] ) ? sanitize_text_field( $element['appliedMessage'] ) : __( 'Coupon applied successfully.', 'wordform-pro' );

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-payment-coupon-wrapper', $element ) ) . '" data-wordform-payment-role="coupon" data-wordform-coupon-invalid-message="' . esc_attr( $invalid_message ) . '" data-wordform-coupon-applied-message="' . esc_attr( $applied_message ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-element-label-wrapper"><label class="sc-wordform-built-payment-element-label">' . esc_html( $labelname ) . '</label></div>';
			$wrapper_with_element .= self::wordform_render_field_help_text( $element );
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-coupon-input-row">';
			$wrapper_with_element .= '<input type="text" class="sc-wordform-built-payment-coupon-input" data-wordform-payment-role="coupon-input" value="" placeholder="' . esc_attr( $placeholder_text ) . '" />';
			$wrapper_with_element .= '<button type="button" class="button button-secondary sc-wordform-built-payment-coupon-apply-button" data-wordform-payment-role="coupon-apply"><span class="sc-wordform-payment-coupon-button-text">' . esc_html( $apply_button_text ) . '</span></button>';
			$wrapper_with_element .= '<button type="button" class="button button-link-delete sc-wordform-built-payment-coupon-remove-button wordform-payment-coupon-hidden" data-wordform-payment-role="coupon-remove"><span class="sc-wordform-payment-coupon-button-text">' . esc_html( $remove_button_text ) . '</span></button>';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<small class="sc-wordform-built-payment-coupon-message" data-wordform-payment-role="coupon-message" style="display:none;"></small>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-coupon-code" name="' . esc_attr( $name ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-coupon-id" name="' . esc_attr( $coupon_id_name ) . '" value="0" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-coupon-hidden-code" name="' . esc_attr( $coupon_code_name ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-coupon-discount" name="' . esc_attr( $discount_name ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build combined payment method selector.
		 *
		 * This element controls which visible gateway block should be used on the
		 * frontend while keeping Stripe and PayPal processing in their own elements.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_payment_method( $key = 0, $element = array() ) {
			$name                = 'wordform[' . self::$wordform_form_id . '][payment_method][' . $key . '][values][]';
			$label_hidden_name   = 'wordform[' . self::$wordform_form_id . '][payment_method][' . $key . '][label]';
			$labelname           = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Payment Method', 'wordform-pro' );
			$helper_text         = isset( $element['helperText'] ) ? sanitize_text_field( $element['helperText'] ) : __( 'Choose how you want to pay', 'wordform-pro' );
			$default_gateway     = isset( $element['defaultGateway'] ) ? sanitize_key( $element['defaultGateway'] ) : 'stripe';
			$available_gateways  = array();

			foreach ( self::$form_elements as $form_element ) {
				if ( isset( $form_element['type'] ) && in_array( $form_element['type'], array( 'stripe', 'paypal', 'square', 'authorizenet' ), true ) ) {
					$available_gateways[] = sanitize_key( $form_element['type'] );
				}
			}

			$available_gateways = array_values( array_unique( $available_gateways ) );
			if ( empty( $available_gateways ) ) {
				$available_gateways = array( 'stripe', 'paypal', 'square', 'authorizenet' );
			}

			if ( ! in_array( $default_gateway, $available_gateways, true ) ) {
				$default_gateway = reset( $available_gateways );
			}

			$wrapper_with_element  = '<div class="sc-wordform-built-payment-method-wrapper" data-wordform-payment-role="method-selector">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-element-label-wrapper"><label class="sc-wordform-built-payment-method-label">' . esc_html( $labelname ) . '</label></div>';
			if ( ! empty( $helper_text ) ) {
				$wrapper_with_element .= '<div class="sc-wordform-built-payment-method-helper-text">' . esc_html( $helper_text ) . '</div>';
			}
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-method-options">';

			foreach ( $available_gateways as $gateway_slug ) {
				$checked_attr  = ( $gateway_slug === $default_gateway ) ? ' checked="checked" ' : '';
				$gateway_label = __( 'Stripe', 'wordform-pro' );
				$gateway_icon  = 'fa-brands fa-stripe';
				if ( 'paypal' === $gateway_slug ) {
					$gateway_label = __( 'PayPal', 'wordform-pro' );
					$gateway_icon  = 'fa-brands fa-paypal';
				} elseif ( 'square' === $gateway_slug ) {
					$gateway_label = __( 'Square', 'wordform-pro' );
					$gateway_icon  = 'fa-solid fa-square';
				} elseif ( 'authorizenet' === $gateway_slug ) {
					$gateway_label = __( 'Authorize.Net', 'wordform-pro' );
					$gateway_icon  = 'fa-solid fa-building-columns';
				}
				$wrapper_with_element .= '<label class="sc-wordform-built-payment-method-option sc-wordform-built-payment-method-option-' . esc_attr( $gateway_slug ) . '" data-wordform-payment-method-option="' . esc_attr( $gateway_slug ) . '">';
				$wrapper_with_element .= '<input type="radio" class="sc-wordform-built-payment-method-option-input" name="' . esc_attr( $name ) . '" value="' . esc_attr( $gateway_slug ) . '"' . $checked_attr . ' />';
				$wrapper_with_element .= '<span class="sc-wordform-built-payment-method-option-card">';
				$wrapper_with_element .= '<span class="sc-wordform-built-payment-method-option-icon"><i class="' . esc_attr( $gateway_icon ) . '"></i></span>';
				$wrapper_with_element .= '<span class="sc-wordform-built-payment-method-option-text">' . esc_html( $gateway_label ) . '</span>';
				$wrapper_with_element .= '</span></label>';
			}

			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Custom Amount Field.
		 *
		 * @param int   $key
		 * @param array $element
		 */
		public static function build_payment_custom_amount( $key = 0, $element = array() ) {
			$name                    = 'wordform[' . self::$wordform_form_id . '][payment_custom_amount][' . $key . '][values][]';
			$label_hidden_name       = 'wordform[' . self::$wordform_form_id . '][payment_custom_amount][' . $key . '][label]';
			$value_required_status   = 'wordform[' . self::$wordform_form_id . '][payment_custom_amount][' . $key . '][required]';
			$default_amount_name     = 'wordform[' . self::$wordform_form_id . '][payment_custom_amount][' . $key . '][defaultAmount]';
			$min_amount_name         = 'wordform[' . self::$wordform_form_id . '][payment_custom_amount][' . $key . '][minAmount]';
			$labelname               = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Custom Amount', 'wordform-pro' );
			$placeholder_text        = isset( $element['placeholderText'] ) ? sanitize_text_field( $element['placeholderText'] ) : __( 'Enter amount', 'wordform-pro' );
			$default_amount          = isset( $element['defaultAmount'] ) && '' !== $element['defaultAmount'] ? (float) $element['defaultAmount'] : '';
			$min_amount              = isset( $element['minAmount'] ) && '' !== $element['minAmount'] ? (float) $element['minAmount'] : '';
			$payment_settings        = self::wordform_get_payment_settings();
			$currency_symbol         = self::wordform_get_payment_currency_symbol( isset( $payment_settings['payment_currency'] ) ? $payment_settings['payment_currency'] : 'USD' );
			$symbol_position         = isset( $payment_settings['payment_currency_symbol_position'] ) ? $payment_settings['payment_currency_symbol_position'] : 'before';

			if ( isset( $element['required'] ) && 'true' === $element['required'] ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			$before_symbol = ( 'before' === $symbol_position ) ? '<span class="sc-wordform-built-payment-input-currency before">' . esc_html( $currency_symbol ) . '</span>' : '';
			$after_symbol  = ( 'after' === $symbol_position ) ? '<span class="sc-wordform-built-payment-input-currency after">' . esc_html( $currency_symbol ) . '</span>' : '';

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-payment-custom-amount-wrapper', $element ) ) . '" data-wordform-payment-role="custom-amount">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-element-label-wrapper"><label class="sc-wordform-built-payment-element-label">' . $labelname_required . '</label></div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-input-row">';
			$wrapper_with_element .= $before_symbol;
			$wrapper_with_element .= '<input type="number" class="sc-wordform-built-payment-custom-amount-element sc-wordform-payment-calc-field" data-wordform-payment-role="custom-amount-input" data-default-amount="' . esc_attr( '' !== $default_amount ? number_format( $default_amount, 2, '.', '' ) : '' ) . '" min="' . esc_attr( '' !== $min_amount ? number_format( $min_amount, 2, '.', '' ) : '0' ) . '" step="0.01" name="' . esc_attr( $name ) . '" value="' . esc_attr( '' !== $default_amount ? number_format( $default_amount, 2, '.', '' ) : '' ) . '" placeholder="' . esc_attr( $placeholder_text ) . '"' . esc_attr( $required ) . ' />';
			$wrapper_with_element .= $after_symbol;
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( isset( $element['required'] ) ? $element['required'] : 'false' ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $default_amount_name ) . '" value="' . esc_attr( '' !== $default_amount ? number_format( $default_amount, 2, '.', '' ) : '' ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $min_amount_name ) . '" value="' . esc_attr( '' !== $min_amount ? number_format( $min_amount, 2, '.', '' ) : '' ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Quantity Field.
		 *
		 * @param int   $key
		 * @param array $element
		 */
		public static function build_payment_quantity( $key = 0, $element = array() ) {
			$name                    = 'wordform[' . self::$wordform_form_id . '][payment_quantity][' . $key . '][values][]';
			$label_hidden_name       = 'wordform[' . self::$wordform_form_id . '][payment_quantity][' . $key . '][label]';
			$value_required_status   = 'wordform[' . self::$wordform_form_id . '][payment_quantity][' . $key . '][required]';
			$min_quantity_name       = 'wordform[' . self::$wordform_form_id . '][payment_quantity][' . $key . '][minQuantity]';
			$max_quantity_name       = 'wordform[' . self::$wordform_form_id . '][payment_quantity][' . $key . '][maxQuantity]';
			$default_quantity_name   = 'wordform[' . self::$wordform_form_id . '][payment_quantity][' . $key . '][defaultQuantity]';
			$labelname               = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Quantity', 'wordform-pro' );
			$default_quantity        = isset( $element['defaultQuantity'] ) && '' !== $element['defaultQuantity'] ? absint( $element['defaultQuantity'] ) : 1;
			$min_quantity            = isset( $element['minQuantity'] ) && '' !== $element['minQuantity'] ? absint( $element['minQuantity'] ) : 1;
			$max_quantity            = isset( $element['maxQuantity'] ) && '' !== $element['maxQuantity'] ? absint( $element['maxQuantity'] ) : '';

			if ( isset( $element['required'] ) && 'true' === $element['required'] ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			$wrapper_with_element  = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-payment-quantity-wrapper', $element ) ) . '" data-wordform-payment-role="quantity">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-element-label-wrapper"><label class="sc-wordform-built-payment-element-label">' . $labelname_required . '</label></div>';
			$wrapper_with_element .= '<input type="number" class="sc-wordform-built-payment-quantity-element sc-wordform-payment-calc-field" data-wordform-payment-role="quantity-input" min="' . esc_attr( $min_quantity ) . '" ' . ( '' !== $max_quantity ? ' max="' . esc_attr( $max_quantity ) . '"' : '' ) . ' step="1" name="' . esc_attr( $name ) . '" value="' . esc_attr( $default_quantity ) . '"' . esc_attr( $required ) . ' />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( isset( $element['required'] ) ? $element['required'] : 'false' ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $default_quantity_name ) . '" value="' . esc_attr( $default_quantity ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $min_quantity_name ) . '" value="' . esc_attr( $min_quantity ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $max_quantity_name ) . '" value="' . esc_attr( $max_quantity ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Payment Summary Field.
		 *
		 * @param int   $key
		 * @param array $element
		 */
		public static function build_payment_summary( $key = 0, $element = array() ) {
			$name                = 'wordform[' . self::$wordform_form_id . '][payment_summary][' . $key . '][values][]';
			$label_hidden_name   = 'wordform[' . self::$wordform_form_id . '][payment_summary][' . $key . '][label]';
			$subtotal_name       = 'wordform[' . self::$wordform_form_id . '][payment_summary][' . $key . '][subtotal]';
			$empty_text_name     = 'wordform[' . self::$wordform_form_id . '][payment_summary][' . $key . '][emptyText]';
			$labelname           = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Payment Summary', 'wordform-pro' );
			$empty_text          = isset( $element['emptyText'] ) ? sanitize_text_field( $element['emptyText'] ) : __( 'Amounts will appear here', 'wordform-pro' );
			$formatted_zero      = self::wordform_format_payment_amount( 0 );

			$wrapper_with_element  = '<div class="sc-wordform-built-payment-summary-wrapper" data-wordform-payment-role="summary" data-empty-text="' . esc_attr( $empty_text ) . '">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-card">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-title">' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-empty-text">' . esc_html( $empty_text ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-totals">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-row"><span>' . esc_html__( 'Subtotal', 'wordform-pro' ) . '</span><strong class="sc-wordform-payment-subtotal-text">' . esc_html( $formatted_zero ) . '</strong></div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-row sc-wordform-built-payment-summary-discount-row" style="display:none;"><span>' . esc_html__( 'Discount', 'wordform-pro' ) . '</span><strong class="sc-wordform-payment-discount-text">-' . esc_html( $formatted_zero ) . '</strong></div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-summary-row sc-wordform-built-payment-summary-total-row"><span>' . esc_html__( 'Total', 'wordform-pro' ) . '</span><strong class="sc-wordform-payment-total-text">' . esc_html( $formatted_zero ) . '</strong></div>';
			$wrapper_with_element .= '</div></div>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-summary-total-input" name="' . esc_attr( $name ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-summary-subtotal-input" name="' . esc_attr( $subtotal_name ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-payment-summary-discount-input" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $empty_text_name ) . '" value="' . esc_attr( $empty_text ) . '" />';
			$wrapper_with_element .= '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Stripe gateway placeholder for public render.
		 *
		 * @param int   $key
		 * @param array $element
		 */
		public static function build_stripe( $key = 0, $element = array() ) {
			$name_status         = 'wordform[' . self::$wordform_form_id . '][stripe][' . $key . '][paymentStatus]';
			$name_intent_id      = 'wordform[' . self::$wordform_form_id . '][stripe][' . $key . '][paymentIntentId]';
			$name_method_id      = 'wordform[' . self::$wordform_form_id . '][stripe][' . $key . '][paymentMethodId]';
			$name_amount         = 'wordform[' . self::$wordform_form_id . '][stripe][' . $key . '][values][]';
			$name_currency       = 'wordform[' . self::$wordform_form_id . '][stripe][' . $key . '][paymentCurrency]';
			$label_hidden_name   = 'wordform[' . self::$wordform_form_id . '][stripe][' . $key . '][label]';
			$labelname           = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Stripe Payment', 'wordform-pro' );
			$description         = isset( $element['description'] ) ? sanitize_text_field( $element['description'] ) : __( 'Secure card payment via Stripe', 'wordform-pro' );
			$formatted_zero      = self::wordform_format_payment_amount( 0 );
			$payment_settings    = self::wordform_get_payment_settings();
			$currency_code       = isset( $payment_settings['payment_currency'] ) ? strtoupper( sanitize_text_field( $payment_settings['payment_currency'] ) ) : 'USD';
			$element_dom_id      = 'sc-wordform-stripe-card-element-' . sanitize_html_class( self::$wordform_form_id . '-' . $key );

			$wrapper_with_element  = '<div class="sc-wordform-built-payment-gateway-wrapper sc-wordform-built-payment-gateway-wrapper-stripe" data-wordform-payment-role="gateway" data-wordform-gateway="stripe">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-card">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-title"><i class="fa-brands fa-stripe"></i> ' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-description">' . esc_html( $description ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-payment-gateway-field-group sc-wordform-payment-gateway-field-group-card">';
			$wrapper_with_element .= '<label class="sc-wordform-payment-gateway-field-label">' . esc_html__( 'Card Details', 'wordform-pro' ) . '</label>';
			$wrapper_with_element .= '<div id="' . esc_attr( $element_dom_id ) . '" class="sc-wordform-stripe-card-element" data-wordform-stripe-element-id="' . esc_attr( $element_dom_id ) . '"></div>';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<small class="sc-wordform-built-payment-gateway-help-text">' . esc_html__( 'Your card will be charged when you submit the form.', 'wordform-pro' ) . '</small>';
			$wrapper_with_element .= '<small class="sc-wordform-error-msg wordform-payment-gateway-error" style="display:none;"></small>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-stripe-payment-status" name="' . esc_attr( $name_status ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-stripe-payment-intent-id" name="' . esc_attr( $name_intent_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-stripe-payment-method-id" name="' . esc_attr( $name_method_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-stripe-payment-amount" name="' . esc_attr( $name_amount ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-stripe-payment-currency" name="' . esc_attr( $name_currency ) . '" value="' . esc_attr( $currency_code ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '</div></div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build PayPal gateway for public render.
		 *
		 * @param int   $key
		 * @param array $element
		 */
		public static function build_paypal( $key = 0, $element = array() ) {
			$name_status       = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][paymentStatus]';
			$name_order_id     = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][orderId]';
			$name_capture_id   = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][captureId]';
			$name_payer_id     = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][payerId]';
			$name_amount       = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][values][]';
			$name_currency     = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][paymentCurrency]';
			$label_hidden_name = 'wordform[' . self::$wordform_form_id . '][paypal][' . $key . '][label]';
			$labelname         = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'PayPal Payment', 'wordform-pro' );
			$button_text       = isset( $element['buttonText'] ) ? sanitize_text_field( $element['buttonText'] ) : __( 'Pay with PayPal', 'wordform-pro' );
			$description       = isset( $element['description'] ) ? sanitize_text_field( $element['description'] ) : __( 'Checkout with your PayPal account', 'wordform-pro' );
			$formatted_zero    = self::wordform_format_payment_amount( 0 );
			$payment_settings  = self::wordform_get_payment_settings();
			$currency_code     = isset( $payment_settings['payment_currency'] ) ? strtoupper( sanitize_text_field( $payment_settings['payment_currency'] ) ) : 'USD';
			$button_dom_id     = 'sc-wordform-paypal-button-element-' . sanitize_html_class( self::$wordform_form_id . '-' . $key );

			$wrapper_with_element  = '<div class="sc-wordform-built-payment-gateway-wrapper sc-wordform-built-payment-gateway-wrapper-paypal" data-wordform-payment-role="gateway" data-wordform-gateway="paypal">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-card">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-title"><i class="fa-brands fa-paypal"></i> ' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-description">' . esc_html( $description ) . '</div>';
			$wrapper_with_element .= '<div id="' . esc_attr( $button_dom_id ) . '" class="sc-wordform-paypal-button-element" data-wordform-paypal-element-id="' . esc_attr( $button_dom_id ) . '" data-wordform-paypal-button-text="' . esc_attr( $button_text ) . '"></div>';
			$wrapper_with_element .= '<small class="sc-wordform-built-payment-gateway-help-text">' . esc_html__( 'Complete PayPal checkout, then WordForm will submit your form automatically.', 'wordform-pro' ) . '</small>';
			$wrapper_with_element .= '<small class="sc-wordform-error-msg wordform-payment-gateway-error" style="display:none;"></small>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-paypal-payment-status" name="' . esc_attr( $name_status ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-paypal-order-id" name="' . esc_attr( $name_order_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-paypal-capture-id" name="' . esc_attr( $name_capture_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-paypal-payer-id" name="' . esc_attr( $name_payer_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-paypal-payment-amount" name="' . esc_attr( $name_amount ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-paypal-payment-currency" name="' . esc_attr( $name_currency ) . '" value="' . esc_attr( $currency_code ) . '" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '</div></div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		public static function build_square( $key = 0, $element = array() ) {
			$name_status       = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][paymentStatus]';
			$name_payment_id   = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][paymentId]';
			$name_source_id    = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][sourceId]';
			$name_amount       = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][values][]';
			$name_currency     = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][paymentCurrency]';
			$name_card_brand   = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][cardBrand]';
			$name_last4        = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][last4]';
			$name_receipt_url  = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][receiptUrl]';
			$label_hidden_name = 'wordform[' . self::$wordform_form_id . '][square][' . $key . '][label]';
			$labelname         = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Square Payment', 'wordform-pro' );
			$description       = isset( $element['description'] ) ? sanitize_text_field( $element['description'] ) : __( 'Secure card payment via Square', 'wordform-pro' );
			$formatted_zero    = self::wordform_format_payment_amount( 0 );
			$payment_settings  = self::wordform_get_payment_settings();
			$currency_code     = isset( $payment_settings['payment_currency'] ) ? strtoupper( sanitize_text_field( $payment_settings['payment_currency'] ) ) : 'USD';
			$element_dom_id    = 'sc-wordform-square-card-element-' . sanitize_html_class( self::$wordform_form_id . '-' . $key );

			$wrapper_with_element  = '<div class="sc-wordform-built-payment-gateway-wrapper sc-wordform-built-payment-gateway-wrapper-square" data-wordform-payment-role="gateway" data-wordform-gateway="square">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-card">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-title"><i class="fa-solid fa-square"></i> ' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-description">' . esc_html( $description ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-payment-gateway-field-group sc-wordform-payment-gateway-field-group-card">';
			$wrapper_with_element .= '<label class="sc-wordform-payment-gateway-field-label">' . esc_html__( 'Card Details', 'wordform-pro' ) . '</label>';
			$wrapper_with_element .= '<div id="' . esc_attr( $element_dom_id ) . '" class="sc-wordform-square-card-element" data-wordform-square-element-id="' . esc_attr( $element_dom_id ) . '"></div>';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<small class="sc-wordform-built-payment-gateway-help-text">' . esc_html__( 'Enter card number, expiry, CVV, and ZIP inside the Square card field. WordForm will charge this payment when you click the main form submit button.', 'wordform-pro' ) . '</small>';
			$wrapper_with_element .= '<small class="sc-wordform-error-msg wordform-payment-gateway-error" style="display:none;"></small>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-payment-status" name="' . esc_attr( $name_status ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-payment-id" name="' . esc_attr( $name_payment_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-source-id" name="' . esc_attr( $name_source_id ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-payment-amount" name="' . esc_attr( $name_amount ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-payment-currency" name="' . esc_attr( $name_currency ) . '" value="' . esc_attr( $currency_code ) . '" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-card-brand" name="' . esc_attr( $name_card_brand ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-last4" name="' . esc_attr( $name_last4 ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-square-receipt-url" name="' . esc_attr( $name_receipt_url ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '</div></div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		public static function build_authorizenet( $key = 0, $element = array() ) {
			$name_status        = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][paymentStatus]';
			$name_transaction   = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][transactionId]';
			$name_response_code = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][responseCode]';
			$name_auth_code     = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][authCode]';
			$name_amount        = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][values][]';
			$name_currency      = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][paymentCurrency]';
			$name_account_num   = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][accountNumber]';
			$name_account_type  = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][accountType]';
			$label_hidden_name  = 'wordform[' . self::$wordform_form_id . '][authorizenet][' . $key . '][label]';
			$labelname          = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'Authorize.Net Payment', 'wordform-pro' );
			$description        = isset( $element['description'] ) ? sanitize_text_field( $element['description'] ) : __( 'Secure card payment via Authorize.Net', 'wordform-pro' );
			$formatted_zero     = self::wordform_format_payment_amount( 0 );
			$payment_settings   = self::wordform_get_payment_settings();
			$currency_code      = isset( $payment_settings['payment_currency'] ) ? strtoupper( sanitize_text_field( $payment_settings['payment_currency'] ) ) : 'USD';

			$wrapper_with_element  = '<div class="sc-wordform-built-payment-gateway-wrapper sc-wordform-built-payment-gateway-wrapper-authorizenet" data-wordform-payment-role="gateway" data-wordform-gateway="authorizenet">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-card">';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-title"><i class="fa-solid fa-building-columns"></i> ' . esc_html( $labelname ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-built-payment-gateway-description">' . esc_html( $description ) . '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-authorizenet-card-fields">';
			$wrapper_with_element .= '<div class="sc-wordform-payment-gateway-field-group">';
			$wrapper_with_element .= '<label class="sc-wordform-payment-gateway-field-label">' . esc_html__( 'Card Number', 'wordform-pro' ) . '</label>';
			$wrapper_with_element .= '<input type="text" class="sc-wordform-authorizenet-card-number" autocomplete="cc-number" placeholder="' . esc_attr__( 'Card Number', 'wordform-pro' ) . '" />';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-authorizenet-card-meta-row">';
			$wrapper_with_element .= '<div class="sc-wordform-payment-gateway-field-group">';
			$wrapper_with_element .= '<label class="sc-wordform-payment-gateway-field-label">' . esc_html__( 'MM/YY', 'wordform-pro' ) . '</label>';
			$wrapper_with_element .= '<input type="text" class="sc-wordform-authorizenet-expiry" autocomplete="cc-exp" placeholder="' . esc_attr__( 'MM/YY', 'wordform-pro' ) . '" />';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-payment-gateway-field-group">';
			$wrapper_with_element .= '<label class="sc-wordform-payment-gateway-field-label">' . esc_html__( 'CVV', 'wordform-pro' ) . '</label>';
			$wrapper_with_element .= '<input type="text" class="sc-wordform-authorizenet-cvv" autocomplete="cc-csc" placeholder="' . esc_attr__( 'CVV', 'wordform-pro' ) . '" />';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '<div class="sc-wordform-payment-gateway-field-group">';
			$wrapper_with_element .= '<label class="sc-wordform-payment-gateway-field-label">' . esc_html__( 'ZIP', 'wordform-pro' ) . '</label>';
			$wrapper_with_element .= '<input type="text" class="sc-wordform-authorizenet-postal" autocomplete="postal-code" placeholder="' . esc_attr__( 'ZIP', 'wordform-pro' ) . '" />';
			$wrapper_with_element .= '</div>';
			$wrapper_with_element .= '</div></div>';
			$wrapper_with_element .= '<small class="sc-wordform-built-payment-gateway-help-text">' . esc_html__( 'Complete your card details here. WordForm will charge this payment when you click the main form submit button.', 'wordform-pro' ) . '</small>';
			$wrapper_with_element .= '<small class="sc-wordform-error-msg wordform-payment-gateway-error" style="display:none;"></small>';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-payment-status" name="' . esc_attr( $name_status ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-transaction-id" name="' . esc_attr( $name_transaction ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-response-code" name="' . esc_attr( $name_response_code ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-auth-code" name="' . esc_attr( $name_auth_code ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-payment-amount" name="' . esc_attr( $name_amount ) . '" value="0.00" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-payment-currency" name="' . esc_attr( $name_currency ) . '" value="' . esc_attr( $currency_code ) . '" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-account-number" name="' . esc_attr( $name_account_num ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" class="sc-wordform-authorizenet-account-type" name="' . esc_attr( $name_account_type ) . '" value="" />';
			$wrapper_with_element .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$wrapper_with_element .= '</div></div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build Terms Field
		 * $param - $element - array
		 */
		public static function build_terms( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][terms][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][terms][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][terms][' . $key . '][required]';

			// Label
			if ( isset( $element['label'] ) ) {
				$labelname = sanitize_text_field( $element['label'] );
			} else {
				$labelname = '';
			}

			// Terms & Conditions Text
			if ( isset( $element['termsConditionsText'] ) && ! empty( $element['termsConditionsText'] ) ) {				
				$terms_conditions_text = trim( sanitize_text_field( $element['termsConditionsText'] ) );
			} else {				
				$terms_conditions_text = '';
			}

			// Terms & Conditions URL
			if ( isset( $element['termsConditionsUrl'] ) && ! empty( $element['termsConditionsUrl'] ) ) {				
				$terms_conditions_url = trim( $element['termsConditionsUrl'] );
			} else {				
				$terms_conditions_url = '';
			}

			// Terms & Conditions Text Clickable true | false
			if ( isset( $element['termsConditionsTextClickable'] ) &&  $element['termsConditionsTextClickable']  == 'true' ) {				
				$terms_conditions_final_text = '<a href="' . esc_url( $terms_conditions_url ) . '" target="_blank">' . $terms_conditions_text . '</a>';
			} else {				
				$terms_conditions_final_text = $terms_conditions_text;
			}

			// Terms & Conditions Required - if label name is empty then asterisk will be added at the end of terms & conditions text
			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				if ( empty( $labelname ) ) {
					$terms_conditions_final_text = $terms_conditions_final_text . '<span class="sc-wordform-required-field">*</span>';
					$labelname_required = '<small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
				}
				else {
					$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
				}
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			$label                            = '<div class="sc-wordform-built-terms-element-label-wrapper"><label class="sc-wordform-built-terms-element-label" >' . $labelname_required . '</label></div>';
			$input                            = '<div class="sc-wordform-built-terms-check-row">';
			$input                           .= '<input type="checkbox" id="wordformTermsChkBox-' . esc_attr( $key ) . '" class="sc-wordform-built-terms-element" name="' . esc_attr( $name ) . '" ' . esc_attr( $required ) . '/>';
			$input                           .= '<label for="wordformTermsChkBox-' . esc_attr( $key ) . '" class="sc-wordform-built-terms-conditions-text-label">' . $terms_conditions_final_text . '</label>';
			$input                           .= '</div>';
			$input                           .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input                           .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element             = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-terms-wrapper', $element ) ) . '">' . $label . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Build GDPR Consent field.
		 *
		 * @param int   $key
		 * @param array $element
		 * @return void
		 */
		public static function build_gdpr( $key = 0, $element = array() ) {
			$name                  = 'wordform[' . self::$wordform_form_id . '][gdpr][' . $key . '][values][]';
			$label_hidden_name     = 'wordform[' . self::$wordform_form_id . '][gdpr][' . $key . '][label]';
			$value_required_status = 'wordform[' . self::$wordform_form_id . '][gdpr][' . $key . '][required]';

			$labelname = isset( $element['label'] ) ? sanitize_text_field( $element['label'] ) : __( 'GDPR Consent', 'wordform-pro' );

			if ( isset( $element['gdprConsentText'] ) && ! empty( $element['gdprConsentText'] ) ) {
				$gdpr_consent_text = trim( sanitize_text_field( $element['gdprConsentText'] ) );
			} else {
				$gdpr_consent_text = __( 'I agree to the privacy policy and consent to data processing.', 'wordform-pro' );
			}

			if ( isset( $element['gdprPolicyUrl'] ) && ! empty( $element['gdprPolicyUrl'] ) ) {
				$gdpr_policy_url = trim( $element['gdprPolicyUrl'] );
			} else {
				$gdpr_policy_url = '';
			}

			if ( isset( $element['gdprConsentTextClickable'] ) && $element['gdprConsentTextClickable'] == 'true' ) {
				$gdpr_final_text = '<a href="' . esc_url( $gdpr_policy_url ) . '" target="_blank">' . $gdpr_consent_text . '</a>';
			} else {
				$gdpr_final_text = $gdpr_consent_text;
			}

			if ( isset( $element['required'] ) && $element['required'] == 'true' ) {
				$required           = ' required ';
				$labelname_required = $labelname . '<span class="sc-wordform-required-field">*</span> <small class="sc-wordform-error-msg validation-msg-' . esc_attr( $key ) . '"></small>';
			} else {
				$required           = '';
				$labelname_required = $labelname;
			}

			$label                = '<div class="sc-wordform-built-gdpr-element-label-wrapper"><label class="sc-wordform-built-gdpr-element-label" >' . $labelname_required . '</label></div>';
			$input                = '<div class="sc-wordform-built-gdpr-check-row">';
			$input               .= '<input type="checkbox" id="wordformGdprChkBox-' . esc_attr( $key ) . '" class="sc-wordform-built-gdpr-element" name="' . esc_attr( $name ) . '" ' . esc_attr( $required ) . '/>';
			$input               .= '<label for="wordformGdprChkBox-' . esc_attr( $key ) . '" class="sc-wordform-built-gdpr-consent-text-label">' . $gdpr_final_text . '</label>';
			$input               .= '</div>';
			$input               .= '<input type="hidden" name="' . esc_attr( $label_hidden_name ) . '" value="' . esc_attr( $labelname ) . '" />';
			$input               .= '<input type="hidden" name="' . esc_attr( $value_required_status ) . '" value="' . esc_attr( $element['required'] ) . '" />';
			$wrapper_with_element = '<div class="' . esc_attr( self::wordform_get_shared_wrapper_classnames( 'sc-wordform-built-gdpr-wrapper', $element ) ) . '">' . $label . self::wordform_render_field_help_text( $element ) . $input . '</div>';
			self::$built_html_form_elements[] = $wrapper_with_element;
		}

		/**
		 * Check whether the form uses multi-step structure.
		 *
		 * @return bool
		 */
		private static function wordform_has_pagebreaks() {
			foreach ( self::$form_elements as $element ) {
				if ( isset( $element['type'] ) && 'pagebreak' === $element['type'] ) {
					return true;
				}
			}

			return false;
		}

		/**
		 * Wrap rendered field markup into step panels based on saved Page Break elements.
		 *
		 * @param string $submit_markup          Final submit button markup.
		 * @param string $upload_progress_markup Upload progress markup.
		 * @return void
		 */
		private static function wordform_wrap_built_elements_into_steps( $submit_markup = '', $upload_progress_markup = '' ) {
			$steps               = array();
			$current_step        = array(
				'title'          => __( 'Step 1', 'wordform-pro' ),
				'previous'       => __( 'Back', 'wordform-pro' ),
				'previous_align' => 'left',
				'next'           => __( 'Next', 'wordform-pro' ),
				'next_align'     => 'right',
				'elements'       => array(),
			);
			$built_element_index = 0;

			foreach ( self::$form_elements as $element ) {
				$element_type = isset( $element['type'] ) ? sanitize_key( $element['type'] ) : '';

				if ( in_array( $element_type, array( 'form-name', 'submit-button' ), true ) ) {
					continue;
				}

				if ( 'pagebreak' === $element_type ) {
					if ( ! empty( $current_step['elements'] ) ) {
						$current_step['next'] = isset( $element['nextButtonText'] ) && '' !== trim( $element['nextButtonText'] ) ? sanitize_text_field( $element['nextButtonText'] ) : __( 'Next', 'wordform-pro' );
						$current_step['next_align'] = isset( $element['nextButtonAlign'] ) && in_array( $element['nextButtonAlign'], array( 'left', 'center', 'right' ), true ) ? sanitize_key( $element['nextButtonAlign'] ) : 'right';
						$steps[]              = $current_step;
					}

					$current_step = array(
						'title'          => isset( $element['stepTitle'] ) && '' !== trim( $element['stepTitle'] ) ? sanitize_text_field( $element['stepTitle'] ) : sprintf( __( 'Step %d', 'wordform-pro' ), count( $steps ) + 1 ),
						'previous'       => isset( $element['previousButtonText'] ) && '' !== trim( $element['previousButtonText'] ) ? sanitize_text_field( $element['previousButtonText'] ) : __( 'Back', 'wordform-pro' ),
						'previous_align' => isset( $element['previousButtonAlign'] ) && in_array( $element['previousButtonAlign'], array( 'left', 'center', 'right' ), true ) ? sanitize_key( $element['previousButtonAlign'] ) : 'left',
						'next'           => __( 'Next', 'wordform-pro' ),
						'next_align'     => 'right',
						'elements'       => array(),
					);
					continue;
				}

				if ( isset( self::$built_html_form_elements[ $built_element_index ] ) ) {
					if ( 'hidden' === $element_type ) {
						$current_step['elements'][] = self::$built_html_form_elements[ $built_element_index ];
					} else {
						$current_step['elements'][] = sprintf(
							'<div class="sc-wordform-step-field" data-wordform-step-field-type="%1$s" data-wordform-step-field-order="%2$d">%3$s</div>',
							esc_attr( $element_type ),
							esc_attr( $built_element_index ),
							self::$built_html_form_elements[ $built_element_index ]
						);
					}
					$built_element_index++;
				}
			}

			if ( ! empty( $current_step['elements'] ) ) {
				$steps[] = $current_step;
			}

			if ( empty( $steps ) ) {
				if ( '' !== $submit_markup ) {
					self::$built_html_form_elements[] = $submit_markup . $upload_progress_markup;
				}
				return;
			}

			$total_steps     = count( $steps );
			$progress_markup = '';
			$panels_markup   = '<div class="sc-wordform-step-panels" data-wordform-total-steps="' . esc_attr( $total_steps ) . '">';

			if ( $total_steps > 1 ) {
				$progress_markup .= '<div class="sc-wordform-step-progress" data-wordform-total-steps="' . esc_attr( $total_steps ) . '">';
				foreach ( $steps as $step_index => $step_data ) {
					$progress_markup .= sprintf(
						'<div class="sc-wordform-step-progress-item %1$s" data-wordform-step-progress="%2$d"><span class="sc-wordform-step-progress-number">%2$d</span><span class="sc-wordform-step-progress-title">%3$s</span></div>',
						0 === $step_index ? 'is-active' : '',
						esc_attr( $step_index + 1 ),
						esc_html( $step_data['title'] )
					);
				}
				$progress_markup .= '</div>';
			}

			foreach ( $steps as $step_index => $step_data ) {
				$is_last_step   = ( $step_index === ( $total_steps - 1 ) );
				$previous_align = isset( $step_data['previous_align'] ) && in_array( $step_data['previous_align'], array( 'left', 'center', 'right' ), true ) ? $step_data['previous_align'] : 'left';
				$next_align     = isset( $step_data['next_align'] ) && in_array( $step_data['next_align'], array( 'left', 'center', 'right' ), true ) ? $step_data['next_align'] : 'right';
				$submit_align   = in_array( self::$sc_wordform_submit_button_align, array( 'left', 'center', 'right' ), true ) ? self::$sc_wordform_submit_button_align : 'left';
				$stack_actions  = ( $is_last_step && $step_index > 0 && $previous_align === $submit_align ) || ( ! $is_last_step && $step_index > 0 && $previous_align === $next_align );
				$panels_markup .= sprintf(
					'<div class="sc-wordform-step-panel %1$s" data-wordform-step="%2$d">',
					0 === $step_index ? 'is-active' : '',
					esc_attr( $step_index + 1 )
				);
				if ( ! $is_last_step ) {
					$panels_markup .= '<div class="sc-wordform-step-panel-title">' . esc_html( $step_data['title'] ) . '</div>';
				}
				$panels_markup .= implode( '', $step_data['elements'] );
				$panels_markup .= sprintf(
					'<div class="sc-wordform-step-actions %1$s" data-wordform-prev-align="%2$s" data-wordform-next-align="%3$s" data-wordform-submit-align="%4$s">',
					trim( ( $stack_actions ? 'is-stacked ' : '' ) . ( $is_last_step ? 'is-final-step' : '' ) ),
					esc_attr( $previous_align ),
					esc_attr( $next_align ),
					esc_attr( $submit_align )
				);

				if ( $step_index > 0 ) {
					$panels_markup .= '<div class="sc-wordform-step-action-slot align-' . esc_attr( $previous_align ) . '"><button type="button" class="button button-secondary sc-wordform-step-previous-button">' . esc_html( $step_data['previous'] ) . '</button></div>';
				}

				if ( $is_last_step ) {
					$panels_markup .= '<div class="sc-wordform-step-action-slot align-' . esc_attr( $submit_align ) . ' action-slot-submit">' . $submit_markup . '</div>' . $upload_progress_markup;
				} else {
					$panels_markup .= '<div class="sc-wordform-step-action-slot align-' . esc_attr( $next_align ) . '"><button type="button" class="button button-primary sc-wordform-step-next-button">' . esc_html( $step_data['next'] ) . '</button></div>';
				}

				$panels_markup .= '</div></div>';
			}

			$panels_markup .= '</div>';
			self::$built_html_form_elements = array( $progress_markup . $panels_markup );
		}

		/**
		 * Build Form name & Submit button
		 * Include form name
		 * Include Submit button
		 */
		public static function include_form_name_with_submit_info() {
			$styles                 = self::sc_wordform_submit_button_customize();
			$sc_wordform_form_name  = '';
			$submit_markup          = '';
			$upload_progress_markup = '';
			$form_name_markup       = '';

			foreach ( self::$form_elements as $key => $element ) {

				// Include Form name Element //
				if ( $element['type'] == 'form-name' ) {
					if ( isset( $element['align'] ) && ! empty( $element['align'] ) ) {
						self::$sc_wordform_form_name_align = trim( $element['align'] );
					}

					$sc_wordform_form_name = sanitize_text_field( $element['label'] );
					if ( $element['hide'] == 'false' ) {
						$form_name_markup = '<div class="sc-wordform-built-form-formname-label-wrapper '. esc_attr( self::$sc_wordform_form_name_align ) .'"><h4>' . esc_html( $element['label'] ) . '</h4></div>';
					}

					if ( isset( $element['formClasses'] ) && ! empty( $element['formClasses'] ) ) {
						$class_names       = explode( ',', $element['formClasses'] );
						$sanitized_classes = array();
						foreach ( $class_names as $class_name ) {
							$class_name = trim( $class_name );
							$class_name = str_replace( ' ', '-', $class_name );
							$class_name = sanitize_text_field( $class_name );
							if ( ! empty( $class_name ) ) {
								$sanitized_classes[] = $class_name;
							}
						}

						if ( ! empty( $sanitized_classes ) ) {
							$existing_classes     = preg_split( '/\s+/', trim( $styles['form_class'] ) );
							$merged_classes       = array_unique( array_filter( array_merge( $existing_classes, $sanitized_classes ) ) );
							$styles['form_class'] = ' ' . implode( ' ', $merged_classes ) . ' ';
						}
					}
				}

				// Include Submit button Element //
				if ( $element['type'] == 'submit-button' ) {
					if ( isset( $element['align'] ) && ! empty( $element['align'] ) ) {
						self::$sc_wordform_submit_button_align = trim( $element['align'] );
					}

					if ( isset( $element['buttonFullWidth'] ) && $element['buttonFullWidth'] == 'true' )  {
						$submit_button_full_width_class = ' wordform-button-full-width ';
					}
					else {
						$submit_button_full_width_class = '';
					}

					$submit_loader_element = '<span class="wordform-users-form-submit-loading-icon" aria-hidden="true"><i class="fa-solid fa-arrows-spin fa-spin fa-lg"></i></span>';

					if ( self::$disable_submit_button ) {
						$submit_button = sprintf(
							'<button type="button" class="button button-primary %1$s %2$s">%3$s</button>',
							esc_attr( $styles['button_class'] ),
							esc_attr( $submit_button_full_width_class ),
							esc_html( $element['label'] )
						);
					} else {
						$submit_button = sprintf(
							'<button type="submit" class="button button-primary %1$s %2$s">%4$s<span class="wordform-users-form-submit-button-label">%3$s</span></button>',
							esc_attr( $styles['button_class'] ),
							esc_attr( $submit_button_full_width_class ),
							esc_html( $element['label'] ),
							$submit_loader_element
						);
					}

					$submit_markup = '<div class="sc-wordform-built-form-submit-button-wrapper ' . esc_attr( self::$sc_wordform_submit_button_align ) . '">' . $submit_button . '</div>';

					if ( isset( self::$wordform_file_input_element_built ) && self::$wordform_file_input_element_built === true ) {
						$upload_progress_markup = '<div class="progress"><div class="progress-bar" style="background-color: #0693e3;"></div></div>';
					}
				}
			}

			if ( self::wordform_has_pagebreaks() ) {
				self::wordform_wrap_built_elements_into_steps( $submit_markup, $upload_progress_markup );
			} elseif ( '' !== $submit_markup ) {
				self::$built_html_form_elements[] = $submit_markup . $upload_progress_markup;
			}

			if ( '' !== $form_name_markup ) {
				array_unshift( self::$built_html_form_elements, $form_name_markup );
			}

			$payment_settings        = self::wordform_get_payment_settings();
			$payment_currency_code   = isset( $payment_settings['payment_currency'] ) ? $payment_settings['payment_currency'] : 'USD';
			$payment_symbol_position = isset( $payment_settings['payment_currency_symbol_position'] ) ? $payment_settings['payment_currency_symbol_position'] : 'before';
			$payment_currency_symbol = self::wordform_get_payment_currency_symbol( $payment_currency_code );

			$formtag_start = sprintf(
				'<div class="sc-wordform-built-form-frontend-outermost-div-wrapper">
					<div class="sc-wordform-submit-progress-overlay"><span class="sc-wordform-submit-progress-overlay-text">%8$s</span></div>
					<form enctype="multipart/form-data" method="post" novalidate
						class="sc-wordform-built-created-form-frontend-display-form %1$s %2$s"
						id="%3$s"
						data-scwordform-form-name="%4$s"
						data-wordform-payment-currency="%5$s"
						data-wordform-payment-currency-symbol="%6$s"
						data-wordform-payment-symbol-position="%7$s"
						data-wordform-hide-on-success="%9$s"
						data-wordform-show-submit-spinner="%10$s"
						data-wordform-show-submit-overlay="%11$s"
						data-wordform-success-card="%12$s"
						data-wordform-redirect-on-success="%13$s"
						data-wordform-redirect-url="%14$s"
						data-wordform-submit-loading-text="%15$s">',
				esc_attr( self::$sc_wordform_size ),
				esc_attr( $styles['form_class'] ),
				esc_attr( self::$wordform_form_id ),
				esc_attr( $sc_wordform_form_name ),
				esc_attr( $payment_currency_code ),
				esc_attr( $payment_currency_symbol ),
				esc_attr( $payment_symbol_position ),
				esc_html( $styles['loading_text'] ),
				esc_attr( $styles['hide_on_success'] ),
				esc_attr( $styles['show_submit_spinner'] ),
				esc_attr( $styles['show_submit_overlay'] ),
				esc_attr( $styles['success_card'] ),
				esc_attr( $styles['redirect_on_success'] ),
				esc_url( $styles['redirect_url'] ),
				esc_attr( $styles['loading_text'] )
			);

			$formtag_end = '</form></div>';

			array_unshift( self::$built_html_form_elements, $formtag_start );
			self::$built_html_form_elements[] = $formtag_end;
		}

		/**
		 * Setting : General Tab submit button customized settings info
		 * Check & Process data
		 * Build style attributes
		 * Build and enqueue per-form submit button & form width CSS.
		 */
		public static function sc_wordform_submit_button_customize() {
			$form_id = isset( self::$wordform_form_id ) ? sanitize_text_field( self::$wordform_form_id ) : 'all_form';
			$opts     = SftcyWordformBase::sc_wordform_get_settings_general_tab_info( $form_id );

			// Unique classes for this form and button
			$form_class  = 'wordform-form-wrapper-' . esc_attr( $form_id );
			$button_class = 'wordform-submit-btn-' . esc_attr( $form_id );

			// ✅ Form width
			$form_width = isset( $opts['wordform_form_width'] ) ? intval( $opts['wordform_form_width'] ) : 100;
			$form_css = sprintf(
				'.%1$s {
					width: %2$d%% !important;
					max-width: 100%% !important;
					margin: 0 auto !important;
					display: block !important;
					padding: %3$dpx !important;
					border-radius: %4$dpx !important;
					--wf-field-gap: %5$dpx;
				}',
				$form_class,
				$form_width,
				intval( $opts['form_container_padding'] ),
				intval( $opts['form_container_border_radius'] ),
				intval( $opts['form_field_gap'] )
			);

			// ✅ Button normal styles
			$normal_css = sprintf(
				'button.%1$s,
				.%1$s.button,
				.%1$s.button-primary {
					background: %2$s !important;
					border-color: %2$s !important;
					font-size: %3$dpx !important;
					font-weight: %4$s !important;
					color: %5$s !important;
					padding: %6$dpx %7$dpx !important;
					cursor: pointer !important;
					transition: all 0.25s ease !important;
					border-radius: 5px !important;
					line-height: 1.4 !important;
					box-shadow: none !important;
				}',
				$button_class,
				sanitize_hex_color( $opts['submit_button_background_color'] ),
				intval( $opts['submit_button_font_size'] ),
				esc_attr( $opts['submit_button_font_weight'] ),
				sanitize_hex_color( $opts['submit_button_font_color'] ),
				intval( $opts['submit_button_padding_top_bottom'] ),
				intval( $opts['submit_button_padding_left_right'] )
			);

			// ✅ Button hover styles
			$hover_css = sprintf(
				'button.%1$s:hover,
				.%1$s.button:hover,
				.%1$s.button-primary:hover {
					background: %2$s !important;
					border-color: %2$s !important;
					color: %3$s !important;
				}',
				$button_class,
				sanitize_hex_color( $opts['submit_button_background_hover_color'] ),
				sanitize_hex_color( $opts['submit_button_font_color'] )
			);

			// ✅ Combine all dynamic CSS
			$inline_css = $form_css . "\n" . $normal_css . "\n" . $hover_css;

			// ✅ Enqueue dynamic CSS safely
			add_action( 'wp_enqueue_scripts', function() use ( $inline_css ) {
				$handle = 'sc-wordform-frontend-misc-style';
				if ( ! wp_style_is( $handle, 'enqueued' ) ) {
					wp_enqueue_style(
						$handle,
						plugins_url( '../assets/css/wordform-frontend-custom-styles.css', __FILE__ ),
						array(),
						SFTCY_WORDFORM_VERSION,
						'all'
					);
				}
				wp_add_inline_style( $handle, $inline_css );
			});

			// ✅ Return both class names for use in render
			return array(
				'form_class'            => $form_class,
				'button_class'          => $button_class,
				'loading_text'          => isset( $opts['submit_button_loading_text'] ) ? sanitize_text_field( $opts['submit_button_loading_text'] ) : '',
				'success_message'       => isset( $opts['form_submission_success_message'] ) ? sanitize_text_field( $opts['form_submission_success_message'] ) : '',
				'hide_on_success'       => isset( $opts['hide_form_on_form_submission'] ) ? sanitize_text_field( $opts['hide_form_on_form_submission'] ) : 'yes',
				'show_submit_spinner'   => isset( $opts['show_submit_button_spinner'] ) ? sanitize_text_field( $opts['show_submit_button_spinner'] ) : 'yes',
				'show_submit_overlay'   => isset( $opts['show_submit_progress_text'] ) ? sanitize_text_field( $opts['show_submit_progress_text'] ) : 'no',
				'success_card'          => isset( $opts['show_success_message_as_card'] ) ? sanitize_text_field( $opts['show_success_message_as_card'] ) : 'yes',
				'redirect_on_success'   => isset( $opts['redirect_on_form_submission'] ) ? sanitize_text_field( $opts['redirect_on_form_submission'] ) : 'no',
				'redirect_url'          => isset( $opts['redirect_url_on_form_submission'] ) ? esc_url_raw( $opts['redirect_url_on_form_submission'] ) : '',
			);
		}



		/**
		 * Include validation messages based on building form ID
		 * Include them as json format to use at front-end if needed
		 */
		public static function wordform_validation_messages() {
			$validation_messages = SftcyWordformBase::sc_wordform_get_validation_messages_data_by_formid( self::$wordform_form_id );			
			// convert key names with underscored - like text-msg -> text_msg, captcha-msg -> captcha_msg etc.
			foreach( $validation_messages as $key => $msg ) {
				$key = str_replace( '-', '_', $key );
				$validation_messages[ $key ] = $msg;
			}
			// print_r( $validation_messages );
			$validation_messages_input_element = "<input type='hidden' id='" . self::$wordform_form_id . "-validationMsg' class='validation-messages' value='". wp_json_encode( $validation_messages) ."' />";
			self::$built_html_form_elements[] = $validation_messages_input_element;
		}

		/**
		 * Built wordform elements to display
		 * param - $wordformid - string
		 * return - string - html contents - built form to display
		 *
		 * @since 1.0.0
		 */
		public static function wordform_built_to_display( $wordformid = null ) {
			if ( is_null( $wordformid ) || empty( $wordformid ) ) {
				return null;
			}
			$formdata            = '';
			$results             = SftcyWordformBase::sc_wordform_db_query( $wordformid );
			self::$form_elements = isset( $results[0]['form'] ) ? json_decode( $results[0]['form'], true ) : array();
			// echo '<pre>';
			// print_r( self::$form_elements );
			// echo '</pre>';
			// exit;
			$created_form        = self::sc_wordform_build_form_from_elements( $wordformid );
			foreach ( $created_form as $form ) {
				$formdata .= $form;
			}
			return $formdata;
		}

		/**
		 * Get only label names of the created Form
		 * label names are considered as field names when connecting Form with third-part Applications
		 * Skip gcaptcha, captcha type fields
		 * @return array - label names
		 */
		public static function wordform_get_field_names( $wordformid = null ) {
			$fields = [];
			if ( is_null( $wordformid ) || empty( $wordformid ) ) {
				return $fields;
			}						
			$results   = SftcyWordformBase::sc_wordform_db_query( $wordformid );
			$form_data = isset( $results[0]['form'] ) ? json_decode( $results[0]['form'], true ) : [];				
			if ( $form_data && array_filter( $form_data ) ) {
				foreach( $form_data as $form ) {
					$field_type  = isset( $form['type'] ) ? sanitize_key( $form['type'] ) : '';
					$field_label = isset( $form['label'] ) ? sanitize_text_field( $form['label'] ) : '';

					switch ( $form['type'] ) {
						case 'text':
						case 'number':
						case 'checkbox':
						case 'radio':
						case 'textarea':
						case 'richeditor':
						case 'select':
						case 'email':
						case 'range':
                        case 'date':
						case 'time':
						case 'datetime':
						case 'tel':
						case 'address':
						case 'maskinput':
						case 'rating':
						case 'likert':
						case 'hidden':
						case 'url':	
						case 'upload':		
						case 'signature':
						case 'terms':
						case 'gdpr':
						case 'payment_item':
						case 'payment_coupon':
						case 'payment_method':
						case 'payment_custom_amount':
						case 'payment_quantity':
						case 'payment_summary':
						case 'stripe':
						case 'paypal':
						case 'square':
						case 'authorizenet':
							if ( '' !== $field_label ) {
								$fields[] = $field_label;
							} else {
								$fields[] = ucwords( str_replace( array( '_', '-' ), ' ', $field_type ) );
							}
							break;							
						case 'firstlastname':
							$first_label = isset( $form['labelFirst'] ) ? sanitize_text_field( $form['labelFirst'] ) : '';
							$last_label  = isset( $form['labelLast'] ) ? sanitize_text_field( $form['labelLast'] ) : '';
							$fields[]    = '' !== $first_label ? $first_label : __( 'First Name', 'wordform-pro' );
							$fields[]    = '' !== $last_label ? $last_label : __( 'Last Name', 'wordform-pro' );
							break;
						default:							
						break;	
					}
				}
			}
			return array_values( array_unique( array_filter( $fields ) ) );
		}

		/**
		 * Find element Google reCAPTCHA exist in form elements 
		 * based on Google reCAPTCHA element exist in form elements load reCAPTCHA JS library
		 * If not exist not required to load with form page
		 * @return boolean true | false
		 */
		public static function is_google_recaptcha_element_exist_in_built_form() {
			$searchValue = 'gcaptcha';
			$form_data = self::$form_elements;
			foreach ($form_data as $subArray) {
					if (is_array($subArray)) {
						if (in_array($searchValue, $subArray, true)) {
							return true; // Found in sub-array
						}
					}
				}
				return false; // Not found in any sub-array			
		}

		/**
		 * Check if hCaptcha element exists in built form.
		 *
		 * @return bool
		 */
		public static function is_hcaptcha_element_exist_in_built_form() {
			$searchValue = 'hcaptcha';
			$form_data = self::$form_elements;
			foreach ( $form_data as $subArray ) {
				if ( is_array( $subArray ) && in_array( $searchValue, $subArray, true ) ) {
					return true;
				}
			}
			return false;
		}

		/**
		 * Clean regex pattern fetched from database
		 * 
		 * @param string $pattern The raw pattern from MySQL
		 * @return string Cleaned regex pattern
		 */
		public static function cleanRegexPattern($pattern) {
			if (!$pattern) {
				return '';
			}
			// Remove added slashes (from addslashes or magic quotes)
			$pattern = stripslashes($pattern);

			// Remove any non-regex characters (optional, keeps common regex symbols)
			// $pattern = preg_replace('/[^\\^+?()\[\]{}0-9.\-\\s]/', '', $pattern);

			return $pattern;
		}


	} // End class
}
