<?php

if ( ! function_exists( 'ginevra_core_cf7_add_submit_form_tag' ) ) {
	/**
	 * Function that override default submit buttom html tag
	 */
	function ginevra_core_cf7_add_submit_form_tag() {
		wpcf7_add_form_tag( 'submit', 'ginevra_core_cf7_submit_form_tag_handler' );
	}
}

if ( ! function_exists( 'ginevra_core_cf7_submit_form_tag_handler' ) ) {
	/**
	 * Function that override default submit buttom html tag
	 *
	 * @param array $tag
	 *
	 * @return string
	 */
	function ginevra_core_cf7_submit_form_tag_handler( $tag ) {
		$tag   = new WPCF7_FormTag( $tag );
		$class = wpcf7_form_controls_class( $tag->type );

		$atts             = array();
		$atts['class']    = $tag->get_class_option( $class );
		$atts['class']    .= ' qodef-button qodef-size--normal qodef-layout--textual qodef-m';
		$atts['id']       = $tag->get_id_option();
		$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );

		$value = isset( $tag->values[0] ) ? $tag->values[0] : '';
		if ( empty( $value ) ) {
			$value = esc_html__( 'Send', 'ginevra-core' );
		}

		$atts['type'] = 'submit';
		$atts         = wpcf7_format_atts( $atts );
		$svg          = ginevra_get_svg_icon( 'button-underline' );

		$html = sprintf( '<button %1$s><span class="qodef-m-text">%2$s</span><span class="qodef-m-wave">%3$s</span><span class="qodef-m-wave-fake">%3$s</span></button>', $atts, $value, $svg );

		return $html;
	}
}
