<div>
	<!-- Nav tabs -->
<ul id="abas" class="nav nav-tabs" role="tablist">
	<?php $cont = 0; foreach($fields_abas as $abas) { $name = str_replace(' ', '', trim($abas[0])); ?>
		<li role="presentation" class="nav-item"><a href="#<?php echo $name ?>" class="nav-link <?php if ($cont == 0) echo "active"; ?>" aria-controls="<?php echo $name ?>" role="tab" data-toggle="tab"><?php echo $abas[0]?></a></li>
	<?php $cont++; } ?>
</ul>

<!-- Tab panes -->
<div class="tab-content">
			
<?php 		
	$primeria = $fields_abas[0];
	$meio = $fields_abas;
	$ultima = $fields_abas[count($fields_abas)-1];
	$key_ultima = count($fields_abas)-1;
		
	unset($meio[0]);
	unset($meio[$key_ultima]);
	
	
	
//==================== primeira    
    
	$name = str_replace(' ', '', trim($primeria[0])); 
?>
			    											
	<div role="tabpanel" class="tab-pane active" id="<?php echo $name?>">
		
		<br>
		
		<?php if ($primeria[2] != NULL){?>
		
			<?php foreach($primeria[1] as $titulo=>$sub) { ?>
					<div class="card card-accent-info">
						<div class="card-header"><h5 class="mb-0"><?php echo $titulo ?></h5></div>
							<div class="card-body">
							<?php foreach($fields as $field) { 	if (in_array($field->field_name, $sub)) {  ?>
						    	
						    	<div class="form-group <?php echo $field->field_name; ?>_form_group">
                                    <label class="col-sm-2 control-label">
                                        <?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?>
                                    </label>
                                    <div class="col-sm-12">
                                        <?php echo $input_fields[$field->field_name]->input?>
                                    </div>
                                </div>
                                
                        	<?php }}?>
                        </div>
					</div>
			<?php } ?>
		
		<?php } else {	foreach($fields as $field) { 	if (in_array($field->field_name, $primeria[1])) {  ?>
			<div class="form-group <?php echo $field->field_name; ?>_form_group">
				<label class="col-sm-2 control-label">
					<?php echo $input_fields[$field->field_name]->display_as; ?> <?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?>
				</label>
				<div class="col-sm-9">
					<?php echo $input_fields[$field->field_name]->input?>
				</div>
			</div>
		<?php }}}?>
		
		<div class="form-group">	
			<div class="col-sm-offset-3 col-sm-9">
				<a class="btn btn-default b10" disabled="disabled">
					<i class="fa fa-arrow-left"></i>
				</a>
				<a class="btn btn-default b10 btnNext"  href="#<?php echo str_replace(' ', '', trim($fields_abas[1][0]))?>" aria-controls="<?php echo str_replace(' ', '', trim($fields_abas[1][0]))?>" role="tab" data-toggle="tab">
					<i class="fa fa-arrow-right"></i>
				</a>
			</div>
		</div>
			
	</div>
		
<?php 	 

//================== meio

	

	foreach($meio as $key=>$abas) { $name = str_replace(' ', '', trim($abas[0])); ?>
											
		<div role="tabpanel" class="tab-pane" id="<?php echo $name?>">
			
			<br>
		
		<?php if ($abas[2] != NULL){?>
		
			<?php foreach($abas[1] as $titulo=>$sub) { ?>
					<div class="card card-accent-info">
						<div class="card-header"><h5 class="mb-0"><?php echo $titulo ?></h5></div>
							<div class="card-body">
							<?php foreach($fields as $field) { 	if (in_array($field->field_name, $sub)) {  ?>
						    	
						    	<div class="form-group <?php echo $field->field_name; ?>_form_group">
                                    <label class="col-sm-2 control-label">
                                        <?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?>
                                    </label>
                                    <div class="col-sm-12">
                                        <?php echo $input_fields[$field->field_name]->input?>
                                    </div>
                                </div>
                                
                        	<?php }}?>
                        </div>
					</div>
			<?php } ?>
		
		<?php } else {	foreach($fields as $field) { 	if (in_array($field->field_name, $abas[1])) {  ?>
									    	
				<div class="form-group <?php echo $field->field_name; ?>_form_group">
					<label class="col-sm-2 control-label">
					      <?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?>
					</label>
					<div class="col-sm-9">
						<?php echo $input_fields[$field->field_name]->input?>
					</div>
				</div>
					                                
			<?php }}}?>
	             <div class="form-group">	
					<div class="col-sm-offset-3 col-sm-9">
						<a class="btn btn-default b10 btnPrevious" href="#<?php echo str_replace(' ', '', trim($fields_abas[$key-1][0]))?>" aria-controls="<?php echo str_replace(' ', '', trim($fields_abas[$key-1][0]))?>" role="tab" data-toggle="tab">
                             <i class="fa fa-arrow-left"></i>
                        </a>
                        <a class="btn btn-default b10 btnNext"  href="#<?php echo str_replace(' ', '', trim($fields_abas[$key+1][0]))?>" aria-controls="<?php echo str_replace(' ', '', trim($fields_abas[$key+1][0]))?>" role="tab" data-toggle="tab">
                             <i class="fa fa-arrow-right"></i>
                        </a>
					</div>
				</div>
											
		</div>

		<?php } 
		
//================== ultima		
		
		
		
$name = str_replace(' ', '', trim($ultima[0])); 
?>
	<div role="tabpanel" class="tab-pane" id="<?php echo $name?>">
		<br>
		
		<?php if ($ultima[2] != NULL){?>
		
			<?php foreach($ultima[1] as $titulo=>$sub) { ?>
					<div class="card card-accent-info">
						<div class="card-header"><h5 class="mb-0"><?php echo $titulo ?></h5></div>
							<div class="card-body">
							<?php foreach($fields as $field) { 	if (in_array($field->field_name, $sub)) {  ?>
						    	
						    	<div class="form-group <?php echo $field->field_name; ?>_form_group">
                                    <label class="col-sm-2 control-label">
                                        <?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?>
                                    </label>
                                    <div class="col-sm-12">
                                        <?php echo $input_fields[$field->field_name]->input?>
                                    </div>
                                </div>
                                
                        	<?php }}?>
                        </div>
					</div>
			<?php } ?>
		
		<?php } else {	foreach($fields as $field) { 	if (in_array($field->field_name, $ultima[1])) {  ?>
		    	
			<div class="form-group <?php echo $field->field_name; ?>_form_group">
				<label class="col-sm-2 control-label">
					<?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?>
				</label>
				<div class="col-sm-9">
				<?php echo $input_fields[$field->field_name]->input?>
				</div>	
			</div>
					                                
		<?php }}}?>

		<div class="form-group">
			<div class="col-sm-offset-3 col-sm-9">
				<a class="btn btn-default b10 btnPrevious" href="#<?php echo str_replace(' ', '', trim($fields_abas[$key_ultima-1][0]))?>" aria-controls="<?php echo str_replace(' ', '', trim($fields_abas[$key_ultima-1][0]))?>" role="tab" data-toggle="tab">
			        <i class="fa fa-arrow-left"></i>
				</a>
	        	<a class="btn btn-default b10 btnNext" disabled="disabled">
	            	<i class="fa fa-arrow-right"></i>
	       		</a>
			</div>
		</div>                     
										   
	</div>
							
</div>