<?php

/***************************************** for list field **************************************/

if ( $field->type == 'list' ) {

	// Add class to input
	$get_tds = $dom->getElementsByTagName( 'td' );

	foreach ( $get_tds as $td ) {
		$td_classes = $td->getAttribute( 'class' );

		// Gravity Forms recent version doesn't have 'gfield_list_icons' class instead its empty
		if ( $td_classes !== '' && strpos( $td_classes, 'gfield_list_icons' ) === false ) {
			$container_div = $dom->createElement( 'div' );
			$container_div_classes = $type === 'outlined' ? 'mdc-text-field mdc-text-field--outlined mdc-text-field--no-label': 'mdc-text-field';
			$container_div->setAttribute( 'class', $container_div_classes );
			$container_div->setAttribute( 'data-mdc-auto-init', 'MDCTextField' );
			$td->appendChild( $container_div );
			$div = $td->getElementsByTagName( 'div' )->item( 0 );
			$div_classes = $div->getAttribute( 'class' );

			if ( strpos( $div_classes, 'mdc-text-field' ) !== false ) {
				$inputs = $td->getElementsByTagName( 'input' );
				foreach ( $inputs as $input ) {
					$input->setAttribute( 'class',
						$input->getAttribute( 'class' ) . ' mdc-text-field__input' );
					$div->appendChild( $input );
					if( $type === 'outlined' ) {
						$notched_outline = $dom->createElement('div');
						$notched_outline->setAttribute( 'class', 'mdc-notched-outline' );

						$notched_outline_leading = $dom->createElement( 'div' );
						$notched_outline_leading->setAttribute( 'class', 'mdc-notched-outline__leading' );
						
						$notched_outline_notch = $dom->createElement( 'div' );
						$notched_outline_notch->setAttribute( 'class', 'mdc-notched-outline__notch' );

						$notched_outline_trailing = $dom->createElement( 'div' );
						$notched_outline_trailing->setAttribute( 'class', 'mdc-notched-outline__trailing' );
						
						// if ($contains_placeholder) {
						// 	$notched_outline->setAttribute( 'class', 'mdc-notched-outline mdc-notched-outline--notched' );
						// }
						$container_div->appendChild( $notched_outline );

						$notched_outline->appendChild( $notched_outline_leading );
						$notched_outline->appendChild( $notched_outline_notch );
						$notched_outline->appendChild( $notched_outline_trailing );

						// $label->setAttribute('class', $label->getAttribute( 'class' ) . $add_label_classes );
						// $notched_outline_notch->appendChild( $label );
					}

					//create a new div
                    if ($type === 'filled') {
                        $bottom_line_div = $dom->createElement('div');
                        $bottom_line_div->setAttribute('class', 'mdc-line-ripple');
                        $div->appendChild($bottom_line_div);
                    }
				}
			}
		}
	}
	$content = utf8_decode($dom->saveHTML($dom->documentElement));

}
