<?php
namespace Cool_FormKit_Pro\Widgets\HelloPlusAddons;

use HelloPlus\Modules\Forms\Fields\Field_Base;
use HelloPlus\Includes\Utils;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Elementor Form Field - Signature
 *
 * Add a new "Signature" field to Elementor form widget.
 *
 * @since 1.0.0
 */
if(!class_exists('HelloPlus_Signature_Field')) { 
class HelloPlus_Signature_Field extends Field_Base {

	public $depended_scripts = array( 'helloplus-sf-js-library', 'helloplus-sf-custom-js' );
	public $depended_styles = array( 'helloplus-sf-css-style' );

	/**
	 * Get field type.
	 *
	 * Retrieve Signature Field  unique ID.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return string Field type.
	 */
	public function get_type() {
		return 'signature';
	}

	/**
	 * Get field name.
	 *
	 * Retrieve Signature Field field label.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return string Field name.
	 */
	public function get_name() {
		return esc_html__( 'Signature', 'cool-formkit' );
	}

	public function get_script_depends(): array {
		return $this->depended_scripts;
	}

	public function get_style_depends(): array {
		return $this->depended_styles;
	}
	/**
	 * Render field output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.0
	 * @access public
	 * @param mixed $item
	 * @param mixed $item_index
	 * @param mixed $form
	 * @return void
	 */
	public function render( $item, $item_index, $form ) {
		$form->add_render_attribute(
			'wrapper' . $item_index,
			array(
				'class' => 'elementor-repeater-item-' . $item['_id'] . ' wrapper',
			)
		);
		$form->add_render_attribute(
			'canvas' . $item_index,
			array(
				'class'          => 'signature-pad',
				'id'             => 'signature-pad-' . $item_index,
				'data-bg-color'  => esc_attr( $item['canvas_bg_color'] ),
				'data-color'     => esc_attr( $item['canvas_pen_color'] ),
				'data-pen-width' => esc_attr( $item['pen_width']['size'] ),
			)
		);

		$form->add_render_attribute(
			'input' . $item_index,
			array(
				'class' => 'input_field_canvas_value',
				'style' => 'display: none',
			)
		);
        // phpcs:ignore -- Skip get_render_attribute_string from phpcs security because this is already filtered content
		echo '<div class="signature-pad-wrapper">';
		echo '<div ' . $form->get_render_attribute_string( 'wrapper' . esc_attr($item_index )) . '><canvas ' . $form->get_render_attribute_string( 'canvas' . esc_attr($item_index ) ) . '></canvas>';

		echo '<div class="signature-placeholder">
			<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 200 43"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M1 38.602c11.246 3.197 22.182-.99 31.508-7.172 4.932-3.27 9.826-7.183 12.825-12.341 1.195-2.057 2.656-5.626-1.106-5.658-4.093-.034-7.14 3.662-8.668 7.022-2.19 4.819-2.268 10.526.407 15.17 2.531 4.395 6.778 6.474 11.845 5.62 5.293-.893 9.92-4.508 13.765-7.986a41 41 0 0 0 3.966-4.093c.142-.17.642-1.006.966-1.064.12-.021.298 3.643.33 3.843.288 1.79 1.191 3.806 3.305 3.867 2.69.078 4.94-2.172 6.75-3.83.61-.559 2.55-3.241 3.583-3.241.425 0 1.249 2.143 1.437 2.428 2.484 3.764 6.132 2.401 8.96-.238.52-.485 3.305-4.367 4.436-3.667.911.563 1.313 1.893 1.78 2.778.76 1.441 1.722 2.468 3.33 3.004 3.493 1.166 7.261-2.102 10.803-2.102 1.033 0 1.561.568 2.11 1.351.749 1.068 1.521 1.813 2.873 2.103 4.188.898 7.617-3.077 11.667-2.728 1.181.101 2.063 1.292 2.949 1.927 1.788 1.28 3.938 2.167 6.127 2.478 3.509.499 7.027-.162 10.447-.9 5.905-1.277 11.752-2.799 17.667-4.031"></path><g fill="currentColor" clip-path="url(#a)"><path d="M196.514 17.657 184.491 3.13a.665.665 0 0 0-.938-.089l-2.905 2.405a.666.666 0 0 0-.089.938l12.023 14.526a.66.66 0 0 0 .451.239.67.67 0 0 0 .488-.15l2.905-2.405a.666.666 0 0 0 .088-.938zm-15.077-8.121-10.582 2.869a.67.67 0 0 0-.472.48l-4.228 16.795 7.82-6.472a3.34 3.34 0 0 1 .815-4.137 3.337 3.337 0 0 1 4.693.442 3.34 3.34 0 0 1-.442 4.694 3.32 3.32 0 0 1-2.438.75 3.34 3.34 0 0 1-1.778-.721l-7.82 6.471 17.289-1.014a.67.67 0 0 0 .561-.374l4.796-9.859z"></path></g><defs><clipPath id="a"><path fill="#fff" d="m167.573 0 31.859 3.004-3.004 31.858-31.859-3.003z"></path></clipPath></defs></svg>
		</div>';

		echo '<div class="color-buttons">';
			if($item['allow_color_selection_frontend'] === 'yes'){
				echo '<input type="color" class="signature-color-picker" id="pen-color-' . esc_attr($item_index) . '" value="' . esc_attr($item['canvas_pen_color']) . '">';
			}
		echo '</div>';

		echo '<div class="action-buttons">';
			echo '<a class="coolform-signature-redo action-button">
					<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 8h5V3m-.29 13.357a8 8 0 1 1-.19-8.991"/></svg>
				</a>';
			echo '<a class="coolform-signature-undo action-button">
					<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 8H5V3m.291 13.357a8 8 0 1 0 .188-8.991"/></svg>
				</a>';
			echo '<a class="coolform-signature-clear action-button">
					<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M12 20c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8m0-18C6.47 2 2 6.47 2 12s4.47 10 10 10s10-4.47 10-10S17.53 2 12 2m2.59 6L12 10.59L9.41 8L8 9.41L10.59 12L8 14.59L9.41 16L12 13.41L14.59 16L16 14.59L13.41 12L16 9.41z"/></svg>
				</a>';
		echo '</div>';

		echo '</div>';

		echo '</div>';
		// phpcs:ignore -- Skip get_render_attribute_string from phpcs security because this is already filtered content
		echo '<input ' . $form->get_render_attribute_string( 'input' . esc_attr($item_index ) ) . '>';


	}

		/**
		 * Field validation.
		 *
		 * Validate range slider field value to ensure it complies to certain rules.
		 *
		 * @since 1.0.0
		 * @access public
		 * @param \ElementorPro\Modules\Forms\Classes\Field_Base   $field
		 * @param \ElementorPro\Modules\Forms\Classes\Form_Record  $record
		 * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler
		 * @return void
		 */

	public function validation( $field, $record, $ajax_handler ) {

		$form_settings = $record->get( 'form_settings')['form_fields'];
		$field_id      = $field['id'];
		$field_type    = $field['type'];
		$field_value   = empty( $field['value'] ) ? '' : $field['value'];
		$field_require = $field['required'];

		if ( ! $field_require && empty( $field_value ) ) {
			return;
		}

		if ( $field_require && empty( $field_value ) ) {
			$ajax_handler->add_error(
				$field['id'],
				esc_html__( 'This field is required and cannot be left blank.', 'cool-formkit' )
			);
			return;
		}

		if ( empty( $field_value ) ) {
			$ajax_handler->add_error(
				$field['id'],
				esc_html__( 'This field is empty', 'cool-formkit' )
			);
			return;
		}

		$encoded_image = explode( ',', $field_value )[1];
		if ( ! preg_match( '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $encoded_image ) ) {
			$ajax_handler->add_error(
				$field['id'],
				esc_html__( 'The provided signature is invalid. Please provide a valid signature.', 'cool-formkit' )
			);
		}

		$decoded_image = base64_decode( $encoded_image );
		if ( $decoded_image === false ) {
			$ajax_handler->add_error(
				$field['id'],
				esc_html__( 'The provided data is not a valid base64-encoded string. Please provide a valid base64-encoded string.', 'cool-formkit' )
			);
		}

		// Generate a unique file name
		$timestamp = current_time( 'timestamp' );
		$file_name = "image-{$timestamp}-" . uniqid() . '.png';
		// Save the image in the WordPress uploads directory
		$upload_dir = wp_upload_dir();
		$file_path  = $upload_dir['path'] . '/' . $file_name;
		global $wp_filesystem;
		if ( ! is_object( $wp_filesystem ) ) {
			require_once ABSPATH . 'wp-admin/includes/file.php';
			WP_Filesystem();
		}
		$wp_filesystem->put_contents( $file_path, $decoded_image );
		// Generate the attachment metadata
		$attachment = array(
			'post_mime_type' => 'image/png',
			'post_title'     => sanitize_file_name( $file_name ),
			'post_content'   => '',
			'post_status'    => 'inherit',
		);
		// Insert the attachment into the WordPress media library
		$attachment_id = wp_insert_attachment( $attachment, $file_path );
		// Generate the attachment metadata
		$attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_path );
		// Update the attachment metadata
		wp_update_attachment_metadata( $attachment_id, $attachment_data );
		// Set the attachment ID as the field value
		$field['value'] = $attachment_id;
		// Save the updated field value to the record
		// Get the full URL of the attachment
		$attachment_url = wp_get_attachment_url( $attachment_id );
		$image_html = '<a href="' . esc_url( $attachment_url ) . '" target="_blank"><img src="' . esc_url( $attachment_url ) . '" alt="' . esc_attr__( 'Signature Image', 'cool-formkit' ) . '" style="max-width: 150px; height: auto; display:block;" /></a>';

		foreach ($form_settings as $form_field) {
			if (isset($form_field['custom_id']) && $form_field['custom_id'] === $field['id']) {


				if (!empty($form_field['show_signature_as_image']) && $form_field['show_signature_as_image'] === 'yes') {
					$record->update_field($field['id'], 'value', $image_html);
				} else {
					$record->update_field($field['id'], 'value', $attachment_url);
				}
				break;
			}
		}

	}



	/**
	 * Update form widget controls.
	 *
	 * Add input fields to allow the user to customize the Signature field.
	 *
	 * @since 1.0.0
	 * @access public
	 * @param \Elementor\Widget_Base $widget The form widget instance.
	 * @return void
	 */
	public function update_controls( $widget ) {
		$widget_name = $widget->get_name();
        
        if($widget_name !== 'ehp-form'){
            return;
        }
		
		$elementor = Utils::elementor();

		$control_data = $elementor->controls_manager->get_control_from_stack( $widget->get_unique_name(), 'form_fields' );

		if ( is_wp_error( $control_data ) ) {
			return;
		}

		$cfkef_signature_description = sprintf(
			'%s',
			esc_html__( 'Save Signature as Image in Submissions', 'cool-formkit' ),
		);

		$field_controls = array(
			'canvas_bg_color'  => array(
				'name'         => 'canvas_bg_color',
				'label'        => esc_html__( 'Background Color', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::COLOR,
				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'default'      => '#000000',
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',
			),

			'canvas_pen_color' => array(
				'name'         => 'canvas_pen_color',
				'label'        => esc_html__( 'Pen Color', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::COLOR,
				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'default'      => '#ffffff',
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',
			),

			'allow_color_selection_frontend'    => array(
				'name'         => 'allow_color_selection_frontend',
				'label'        => esc_html__( 'Allow Pen Color Picker', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Yes', 'cool-formkit' ),
				'label_off'    => esc_html__( 'No', 'cool-formkit' ),
				'return_value' => 'yes',
				'default'      => 'no',
				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',
			),

			'pen_width'        => array(
				'name'         => 'pen_width',
				'label'        => esc_html__( 'Pen Width', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::SLIDER,
				'size_units'   => array( 'px' ),
				'range'        => array(
					'px' => array(
						'min' => 0,
						'max' => 20,
					),

				),

				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',

			),

			'canvas_width'     => array(
				'name'         => 'canvas_width',
				'label'        => esc_html__( 'Canvas Width', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::SLIDER,
				'size_units'   => array( 'px', '%', 'rem' ),
				'range'        => array(
					'px' => array(
						'min' => 100,
						'max' => 500,
					),
				),
				'default'      => array(
					'unit' => '%',
					'size' => 50,
				),
				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'responsive' => array(true),
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',
				'selectors'    => array(
					'{{WRAPPER}} .is-field-type-signature.ehp-form__field-group .wrapper{{CURRENT_ITEM}}, {{WRAPPER}} .is-field-type-signature.ehp-form__field-group .signature-pad-wrapper .wrapper{{CURRENT_ITEM}} + .button-wrapper' => 'width: {{SIZE}}{{UNIT}};',
				),

			),

			'canvas_height'    => array(
				'name'         => 'canvas_height',
				'label'        => esc_html__( 'Canvas Height', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::SLIDER,
				'size_units'   => array( 'px', '%', 'rem' ),
				'range'        => array(
					'px' => array(
						'min' => 100,
						'max' => 500,
					),

				),
				'default'      => array(
					'unit' => 'px',
					'size' => 300,
				),
				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'responsive' => array(true),
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',
				'selectors'    => array(
					'{{WRAPPER}} .is-field-type-signature.ehp-form__field-group .wrapper{{CURRENT_ITEM}}' => 'height: {{SIZE}}{{UNIT}};',
				),
			),

			'show_signature_as_image'    => array(
				'name'         => 'show_signature_as_image',
				'label'        => esc_html__( 'Signature as Image', 'cool-formkit' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'description'  => $cfkef_signature_description,
				'label_on'     => esc_html__( 'Yes', 'cool-formkit' ),
				'label_off'    => esc_html__( 'No', 'cool-formkit' ),
				'return_value' => 'yes',
				'default'      => 'no',
				'condition'    => array(
					'field_type' => $this->get_type(),
				),
				'tab'          => 'content',
				'inner_tab'    => 'form_fields_content_tab',
				'tabs_wrapper' => 'form_fields_tabs',
			)
		);

		$control_data['fields'] = $this->inject_field_controls( $control_data['fields'], $field_controls );

		$widget->update_control( 'form_fields', $control_data );
	}




	/**
	 * Field constructor.
	 *
	 * Used to add a script to the Elementor editor preview.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return void
	 */
	public function __construct() {
		parent::__construct();
		add_action( 'wp_enqueue_scripts', array( $this, 'add_assets_files' ) );
		add_action( 'elementor/preview/init', array( $this, 'editor_preview_footer' ) );
		add_action( 'elementor/element/ehp-form/section_field_style/before_section_end', array($this,'sffef_extend_widget_field_styles'), 10, 1 );

		add_action( 'elementor/element/ehp-form/section_form_fields/before_section_end', [ $this, 'update_controls' ] );

	}

	public function sffef_extend_widget_field_styles( $element ) {
		$controls = $element->get_controls();

		// 2. Check and extend `field_border_width`
		if ( isset( $controls['field_border_width']['selectors'] ) ) {
			$controls['field_border_width']['selectors']['{{WRAPPER}} .is-field-type-signature'] =
				'--e-form-field-border-width: {{SIZE}}{{UNIT}};';
			$element->update_control( 'field_border_width', $controls['field_border_width'] );
		}

		// 3. Border Radius
		if ( isset( $controls['field_border_radius']['selectors'] ) ) {			
			$controls['field_border_radius']['selectors']['{{WRAPPER}} .is-field-type-signature'] =
				'--e-form-field-border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};';
			$element->update_control( 'field_border_radius', $controls['field_border_radius'] );
		}

		// 4. Border Color
		if ( isset( $controls['field_border_color']['selectors'] ) ) {
			$controls['field_border_color']['selectors']['{{WRAPPER}} .is-field-type-signature'] =
				'--e-form-field-border-color: {{VALUE}};';
			$element->update_control( 'field_border_color', $controls['field_border_color'] );
		}
	}

	public function add_assets_files(){
		$js_common_dep = array( 'jquery', 'helloplus-sf-js-library', 'elementor-frontend' );
        if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() && is_user_logged_in() ) {
            $js_common_dep = array_merge(array( 'elementor-common' ), $js_common_dep);
        }
	    wp_register_script( 'helloplus-sf-js-library', CFKEF_PLUGIN_URL . 'assets/js/sf-include-js-library.js', array( 'jquery' ), CFKEF_PLUGIN_VERSION, true );
		// Enqueue Ion.RangeSlider CSS file
		wp_register_style( 'helloplus-sf-css-style', CFKEF_PLUGIN_URL . 'assets/addons/css/coolform-sf-signature-field-style.css', array(), CFKEF_PLUGIN_VERSION );

		wp_register_script( 'helloplus-sf-custom-js', CFKEF_PLUGIN_URL . 'assets/helloplus-addons/js/helloplus-signature.js', $js_common_dep, CFKEF_PLUGIN_VERSION, true );

	}

	/**
	 * Elementor editor preview.
	 *
	 * Add a script to the footer of the editor preview screen.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return void
	 */
	public function editor_preview_footer() {
		add_action( 'wp_footer', array( $this, 'content_template_script' ) );
	}

	/**
	 * Content template script.
	 *
	 * Add content template alternative, to display the field in Elemntor editor.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return void
	 */
	public function content_template_script() {
		?>
		<script>
		jQuery(document).ready(() => {
			elementor.hooks.addFilter(
				'elementor_pro/forms/content_template/field/<?php echo esc_html($this->get_type()); ?>',
				function (inputField, item, i) {
					const fieldType = 'signature';
					const fieldId = `signature-pad-${i}`;
					const bgColor = item['canvas_bg_color'] || '#ffffff';
					const penColor = item['canvas_pen_color'] || '#000000';
					const penWidth = item['pen_width']?.size || 1;
					const allowColorPicker = item['allow_color_selection_frontend'] === 'yes';

					const canvasHeight = `${item.canvas_height?.size || 150}${item.canvas_height?.unit || 'px'}`;
					const canvasWidth = `${item.canvas_width?.size || 300}${item.canvas_width?.unit || 'px'}`;

					return `
					<div class="signature-pad-wrapper">
						<div class="elementor-repeater-item-${item['_id']} wrapper">
							<canvas 
								type="${fieldType}"
								id="${fieldId}" 
								class="signature-pad"
								data-bg-color="${bgColor}"
								data-color="${penColor}"
								data-pen-width="${penWidth}"
								data-canvas-height="${canvasHeight}"
								data-canvas-width="${canvasWidth}"
							></canvas>

							<div class="signature-placeholder">
								<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 200 43"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M1 38.602c11.246 3.197 22.182-.99 31.508-7.172 4.932-3.27 9.826-7.183 12.825-12.341 1.195-2.057 2.656-5.626-1.106-5.658-4.093-.034-7.14 3.662-8.668 7.022-2.19 4.819-2.268 10.526.407 15.17 2.531 4.395 6.778 6.474 11.845 5.62 5.293-.893 9.92-4.508 13.765-7.986a41 41 0 0 0 3.966-4.093c.142-.17.642-1.006.966-1.064.12-.021.298 3.643.33 3.843.288 1.79 1.191 3.806 3.305 3.867 2.69.078 4.94-2.172 6.75-3.83.61-.559 2.55-3.241 3.583-3.241.425 0 1.249 2.143 1.437 2.428 2.484 3.764 6.132 2.401 8.96-.238.52-.485 3.305-4.367 4.436-3.667.911.563 1.313 1.893 1.78 2.778.76 1.441 1.722 2.468 3.33 3.004 3.493 1.166 7.261-2.102 10.803-2.102 1.033 0 1.561.568 2.11 1.351.749 1.068 1.521 1.813 2.873 2.103 4.188.898 7.617-3.077 11.667-2.728 1.181.101 2.063 1.292 2.949 1.927 1.788 1.28 3.938 2.167 6.127 2.478 3.509.499 7.027-.162 10.447-.9 5.905-1.277 11.752-2.799 17.667-4.031"></path><g fill="currentColor" clip-path="url(#a)"><path d="M196.514 17.657 184.491 3.13a.665.665 0 0 0-.938-.089l-2.905 2.405a.666.666 0 0 0-.089.938l12.023 14.526a.66.66 0 0 0 .451.239.67.67 0 0 0 .488-.15l2.905-2.405a.666.666 0 0 0 .088-.938zm-15.077-8.121-10.582 2.869a.67.67 0 0 0-.472.48l-4.228 16.795 7.82-6.472a3.34 3.34 0 0 1 .815-4.137 3.337 3.337 0 0 1 4.693.442 3.34 3.34 0 0 1-.442 4.694 3.32 3.32 0 0 1-2.438.75 3.34 3.34 0 0 1-1.778-.721l-7.82 6.471 17.289-1.014a.67.67 0 0 0 .561-.374l4.796-9.859z"></path></g><defs><clipPath id="a"><path fill="#fff" d="m167.573 0 31.859 3.004-3.004 31.858-31.859-3.003z"></path></clipPath></defs></svg>
							</div>

							<div class="color-buttons">
								${allowColorPicker ? `
									<input type="color" class="signature-color-picker" id="pen-color-${i}" value="${penColor}">
									` : ''}
							</div>
							<div class="action-buttons">
								<a class="coolform-signature-redo action-button">
									<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" 		stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 8h5V3m-.29 13.357a8 8 0 1 1-.19-8.991"/></svg>
								</a>
								<a class="coolform-signature-undo action-button">
									<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 8H5V3m.291 13.357a8 8 0 1 0 .188-8.991"/></svg>
								</a>
								<a class="coolform-signature-clear action-button">
									<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M12 20c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8m0-18C6.47 2 2 6.47 2 12s4.47 10 10 10s10-4.47 10-10S17.53 2 12 2m2.59 6L12 10.59L9.41 8L8 9.41L10.59 12L8 14.59L9.41 16L12 13.41L14.59 16L16 14.59L13.41 12L16 9.41z"/></svg>
								</a>
							</div>
						</div>
					</div>
					<input type="${fieldType}" style="display: none;" class="input_field_canvas_value elementor-field">`;
				}, 10, 3
			);
		});
		</script>
		<?php
	}

}
}



