/**
 * tff-customizer-icons-control.js
 *
 * @package MatrixAddons
 * @subpackage DgLib
 * @version 1.0.0
 * @since 1.0.0
 *
 * Contains handlers to make Theme Customizer icons
 */
 ( function( $, customize ) {
 	'use strict';
 	var tff_document = $(document);
 	var tff_window = $(window);
 	var customizer_icons = {
 		Snipits: {

 			CustomizerIcons: function(){
 				var single_icon = $(this);
 				var tff_custoimzer_icons = single_icon.closest( '.tff-customize-icons' );
 				var icon_display_value = single_icon.children('i').attr('class');
 				var icon_split_value = icon_display_value.split(' ');
 				var icon_value = icon_split_value[1];

 				single_icon.siblings().removeClass('selected');
 				single_icon.addClass('selected');
 				tff_custoimzer_icons.find('.tff-icon-value').val( icon_value );
 				tff_custoimzer_icons.find('.trainify-framework-icon-preview').html('<i class="' + icon_display_value + '"></i>');
 				tff_custoimzer_icons.find('.tff-icon-value').trigger('change');
 			},

 			IconsToggle: function(){
 				var icon_toggle = $(this);
 				var tff_custoimzer_icons = icon_toggle.closest( '.tff-customize-icons' );
 				var icons_list_wrapper = tff_custoimzer_icons.find( '.tff-icons-list-wrapper' );
 				var dashicons = tff_custoimzer_icons.find( '.dashicons' );
 				if( icons_list_wrapper.is(':hidden') ){
 					icons_list_wrapper.slideDown();
 					dashicons.removeClass('dashicons-arrow-down');
 					dashicons.addClass('dashicons-arrow-up');
 				}else{
 					icons_list_wrapper.slideUp();
 					dashicons.addClass('dashicons-arrow-down');
 					dashicons.removeClass('dashicons-arrow-up');
 				}
 			}, 

 			IconsSearch: function(){
 				var text = $(this),
 				value = this.value,
 				tff_custoimzer_icons = text.closest( '.tff-customize-icons' ),
 				icons_list_wrapper = tff_custoimzer_icons.find( '.tff-icons-list-wrapper' );

 				icons_list_wrapper.find('i').each(function () {
 					if ($(this).attr('class').search(value) > -1) {
 						$(this).parent('.tff-single-icon').show();
 					} else {
 						$(this).parent('.tff-single-icon').hide();

 					}
 				});
 			},


 		},

 		Click: function(){

 			var __this = customizer_icons;
 			var snipits = __this.Snipits;

 			var customizericons = snipits.CustomizerIcons;
 			tff_document.on('click', '.tff-customize-icons .tff-single-icon', customizericons);

 			var iconstoggle = snipits.IconsToggle;
 			tff_document.on('click', '.tff-customize-icons .tff-icon-toggle, .tff-customize-icons .trainify-framework-icon-preview', iconstoggle);

 			var iconssearch = snipits.IconsSearch;
 			tff_document.on('keyup', '.tff-customize-icons .icon-search', iconssearch);

 		},

 		Ready: function(){
 			var __this = customizer_icons;
 			var snipits = __this.Snipits;
 			__this.Click();
 		},

 		Load: function(){
 		},

 		Resize: function(){
 		},

 		Scroll: function(){
 		},

 		Init: function(){

 			var __this = customizer_icons;
 			var load, ready, resize, scroll;

 			ready = __this.Ready;
 			load = __this.Load;
 			resize = __this.Resize;
 			scroll = __this.Scroll;
 			tff_document.ready(ready);
 			/*tff_window.load(load);
 			tff_window.resize(resize);
 			tff_window.scroll(scroll);*/

 		},

 	};

 	customizer_icons.Init();

 } )( jQuery, wp.customize );