<?php

if ( in_array( $field->type, $this->input_fields ) ) {
    $textarea_classes_types = array( 'ginput_container_textarea' );
    
	$all_divs = $dom->getElementsByTagName( 'div' );
	
	foreach ( $all_divs as $div ) {
		
		$div_classes = $div->getAttribute( 'class' );
		$div_classes_array = explode( ' ', $div_classes );

		//to check for complex fields like email (user can make it complex by enabling confirm email)
		$is_complex_field = false;
		$is_valid_input_field = false;

		foreach ( $div_classes_array as $div_class_value ) {
			if ( in_array( $div_class_value, $textarea_classes_types ) ) {
				$is_valid_input_field = true;
			}
			if ( strpos( $div_class_value, 'ginput_complex' ) !== false ) {
				$is_complex_field = true;
				
			}
		}
		// var_dump($is_valid_input_field);
		if ( $is_valid_input_field  && !$is_complex_field ) {
			//add class to input
			$textareas = $dom->getElementsByTagName( 'textarea' );
			foreach ( $textareas as $textarea ) {
				$id = $textarea->getAttribute( 'id' );


				if ( preg_match( '/^input_/', $id ) ) {
					$icon_element = $dom->createElement( 'i' );
					$fontawesome_icon = str_replace( '_', ' ', $fontawesome_icon );
					$fontawesome_icon .= ' stla-fontawesome-icon';
					$icon_element->setAttribute( 'class', $fontawesome_icon );
					$div->setAttribute( 'style', 'position:relative' );
					$div->setAttribute( 'class', $div_classes . ' stla-fontawesome' );
					$div->insertBefore( $icon_element, $textarea );
					// $div->appendChild( $icon_element );
				}
			}
		}
		$content = utf8_decode($dom->saveHTML($dom->documentElement));;
	}
}
