<?php
/**
 * @package MatrixAddons
 * @subpackage trainifyframework
 * @since trainifyframework 1.0.0
 * @version 1.0.0
 * @description this file for accordion field
 */
$trainify_framework_widget_field_options = isset($widget_field['trainify_framework_widget_field_options']) ? $widget_field['trainify_framework_widget_field_options'] : array();
$all_values = get_option('widget_' . $trainifyframeworkwidget->id_base);
$this_widget_instance = isset($all_values[$trainifyframeworkwidget->number]) ? $all_values[$trainifyframeworkwidget->number] : array();
$trainify_framework_widget_field_value = (array)$trainify_framework_widget_field_value;
?>
<div class="tff-widget-field-wrapper tff-widget-accordion-wrapper <?php echo esc_attr($trainify_framework_widget_field_wraper); ?>">
	<?php
	if( count( $trainify_framework_widget_field_options ) > 0 && is_array( $trainify_framework_widget_field_options ) ){ 
		foreach ($trainify_framework_widget_field_options as $accordion_key=>$accordion_details){
			$is_dropdown = in_array($accordion_key, $trainify_framework_widget_field_value);
			$trainify_framework_widget_field_title = isset($accordion_details['trainify_framework_widget_field_title']) ? esc_html($accordion_details['trainify_framework_widget_field_title']) : '';
			$trainify_framework_widget_field_options = isset($accordion_details['trainify_framework_widget_field_options']) ? $accordion_details['trainify_framework_widget_field_options'] : array();
			$accordion_wraper_class = ($is_dropdown) ? 'open' : 'closed';
			$accordion_icon_class = ($is_dropdown) ? 'fa-angle-up' : 'fa-angle-down';
			?>
			<div class="trainify-framework-accordion-wrapper <?php echo esc_attr($accordion_wraper_class); ?>">
				<label for="<?php echo esc_attr( $trainifyframeworkwidget->get_field_id( $trainify_framework_widget_field_name.$accordion_key ) ); ?>" class="trainify-framework-accordion-title"><?php esc_html($trainify_framework_widget_field_title); ?>
					<?php echo esc_html($trainify_framework_widget_field_title); ?><i class="trainify-framework-accordion-arrow fa <?php echo esc_attr($accordion_icon_class); ?>"></i>
					<input id="<?php echo esc_attr( $trainifyframeworkwidget->get_field_id( $trainify_framework_widget_field_name.$accordion_key ) ); ?>" name="<?php echo esc_attr( $trainifyframeworkwidget->get_field_name( $trainify_framework_widget_field_name ) ); ?>[]" value="<?php echo esc_attr($accordion_key); ?>" <?php checked( 1, $is_dropdown ) ?> class="tff-hidden" type="checkbox">
				</label>
				<div class="trainify-framework-accordion-content">
					<?php
					if(count($trainify_framework_widget_field_options)):
						foreach($trainify_framework_widget_field_options as $field_key=>$accordion_field):
							$current_widgets_field_default = isset($accordion_field['trainify_framework_widget_field_default']) ? $accordion_field['trainify_framework_widget_field_default'] : '';
							$current_field_widget_name = isset($accordion_field['trainify_framework_widget_field_name']) ? $accordion_field['trainify_framework_widget_field_name'] : '';

							if(!$current_field_widget_name){
								return;
							}
							$current_widgets_field_value = isset($this_widget_instance[$current_field_widget_name]) ? $this_widget_instance[$current_field_widget_name] : $current_widgets_field_default;
							trainify_framework_widgets_show_widget_field( $trainifyframeworkwidget, $accordion_field, $current_widgets_field_value );
						endforeach;
					else:
						?>
						<p><?php esc_html_e('Sorry no field are added on accordion.', 'trainify'); ?></p>
						<?php
					endif;
					?>
				</div>
			</div>
			<?php
		}

	}else{
		?>
			<p><?php esc_html_e('There is no accordion on this accordion group', 'trainify'); ?></p>
		<?php
	}
	?>
	<?php if ( isset( $trainify_framework_widget_field_description ) ) { ?>
		<br/>
		<small><?php echo wp_kses_post( $trainify_framework_widget_field_description ); ?></small>
	<?php } ?>
</div>