<?php
/**
 * @package MatrixAddons
 * @subpackage trainifyframework
 * @since trainifyframework 1.0.0
 * @version 1.0.0
 * @description show widget fueld field for widget
 */
function trainify_framework_widgets_show_widget_field( $trainifyframeworkwidget = '', $widget_field = '', $trainify_framework_widget_field_value = '' ){

	extract( $widget_field );

	$trainify_framework_widget_field_wraper = isset($trainify_framework_widget_field_wraper) ? $trainify_framework_widget_field_wraper : '';
	$trainify_framework_widget_field_relation = isset($trainify_framework_widget_field_relation) ? $trainify_framework_widget_field_relation : array();
	$trainify_framework_widget_relation_json = wp_json_encode( $trainify_framework_widget_field_relation);
	$trainify_framework_widget_relation_class = ($trainify_framework_widget_field_relation) ? 'trainify_framework_widget_field_relation' : '';

	$widget_fild_path = trainify_framework_file_directory('widgets/fields/tff-'.$trainify_framework_widget_field_type.'-field.php');
	if( file_exists($widget_fild_path) ){
		require $widget_fild_path;
	}else{
		?>
		<p><?php echo esc_html__('Field type', 'trainify').' '.esc_attr($trainify_framework_widget_field_type).' '.esc_html__('Not found.', 'trainify'); ?></p>
		<?php
	}

}

function trainify_framework_widgets_updated_field_value( $widget_field, $new_field_value ){

	$trainify_framework_widget_field_type = '';

	extract( $widget_field );

	switch ( $trainify_framework_widget_field_type ) {
		// Allow only integers in number fields
		case 'number':
			return trainify_framework_sanitize_number( $new_field_value, $widget_field );
			break;
		// Allow some tags in textareas
		case 'textarea':
			return trainify_framework_sanitize_textarea($new_field_value);
			break;
		// No allowed tags for all other fields
		case 'url':
			return esc_url_raw( $new_field_value );
			break;
		case 'multitermlist':
			return trainify_framework_sanitize_multitermlist($new_field_value);
			break;
		case 'multiselect':
			return trainify_framework_sanitize_multiselect($new_field_value);
			break;
		case 'accordion':
			return trainify_framework_sanitize_accordion($new_field_value);
			break;
		case 'repeater':
			return trainify_framework_sanitize_repeater($widget_field, $new_field_value );
			break;
		default:
			return wp_kses_post( sanitize_text_field( $new_field_value ) );

	}
}