<?php
/**
 * Custom Control for Icons Controls
 * @package MatrixAddons
 * @subpackage TrainifyFramework
 * @since 1.0.0
 *
 */
if ( !class_exists( 'TrainifyFramework_Customize_Icons_Control' )):

	class TrainifyFramework_Customize_Icons_Control extends WP_Customize_Control {

		public $type = 'icons';
		
		public function enqueue(){

			wp_enqueue_style( 'font-awesome', trainify_framework_directory_uri('assets/library/font-awesome/css/font-awesome.min.css'), array(), '4.7.0' );
			wp_enqueue_style( 'tff-customizer-icons-control-css',  trainify_framework_directory_uri('assets/parts/controls/css/tff-customizer-icons-control.min.css'), array(), '1.0.0' );
			wp_enqueue_script('tff-customizer-icons-control-js', trainify_framework_directory_uri('assets/parts/controls/js/tff-customizer-icons-control.min.js'), array('jquery'), '1.0.0', false );

		}

		public function render_content() {
			$value = $this->value();
			?>
            <label>
                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
                <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
                <span class="tff-customize-icons">
                    <span class="trainify-framework-icon-preview">
                        <?php if( !empty( $value ) ) { echo '<i class="fa '. esc_attr( $value ) .'"></i>'; } ?>
                    </span>
                    <span class="tff-icon-toggle">
                        <?php echo ( empty( $value ) ? esc_html__('Add Icon','trainify'): esc_html__('Change Icon','trainify') ); ?>
                        <span class="dashicons dashicons-arrow-down"></span>
                    </span>
                    <span class="tff-icons-list-wrapper hidden">
                        <input class="icon-search" type="text" placeholder="<?php esc_attr_e('Search Icon','trainify'); ?>">
	                    <?php
	                    $fa_icon_list_array = trainify_framework_fa_iconslist();
	                    foreach ( $fa_icon_list_array as $single_icon ) {
		                    if( $value === $single_icon ) {
			                    echo '<span class="tff-single-icon selected"><i class="fa '. esc_attr( $single_icon ) .'"></i></span>';
		                    }else{
			                    echo '<span class="tff-single-icon"><i class="fa '. esc_attr( $single_icon ) .'"></i></span>';
		                    }
	                    }
	                    ?>
                    </span>
                    <input type="hidden" class="tff-icon-value" value="" <?php $this->link(); ?>>
                </span>
            </label>
			<?php
		}

	}

endif;