<?php
/**
 * Settings | WPML
 *
 * @package Dotspice
 * @version 1.3.0
 */

/**
 * WPML | Get Languages List
 */
function dotspice_languages_list( $type = 'full' ) {
	if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
		$languages = icl_get_languages( 'skip_missing=0' );

		if ( is_array( $languages ) && count( $languages ) > 1 ) {

			if ( $type == 'lang_text' ) {
				?><span class="lang current"><?php echo ICL_LANGUAGE_CODE; ?></span><?php
			}

			else if ( $type == 'lang_image' ) {
				?><span class="lang current"><img src="<?php echo get_template_directory_uri() . '/images/lang/' . ICL_LANGUAGE_CODE . '.png'; ?>" alt="<?php echo ICL_LANGUAGE_CODE; ?>" /></span><?php
			}

			else {
				?><ul class="languages"><?php
					foreach( $languages as $language ) {
						$lang_img  = get_template_directory_uri() . '/images/lang/' . $language['code'] . '.png';
						$lang_name = ucfirst( $language['native_name'] );
						$lang_url  = $language['url'];

						if ( isset( $language['active'] ) && $language['active'] ) {
							?><li class="lang current"><span class="lang__box"><img src="<?php echo esc_url( $lang_img ); ?>" alt="<?php echo esc_attr( $lang_name ); ?>" /><?php echo esc_html( $lang_name ); ?></span></li><?php
						}

						else {
							?><li class="lang"><a class="lang__box" href="<?php echo esc_url( $lang_url ); ?>"><img src="<?php echo esc_url( $lang_img ); ?>" alt="<?php echo esc_attr( $lang_name ); ?>" /><?php echo esc_html( $lang_name ); ?></a></li><?php
						}
					}
				?></ul><?php
			}
		}
	}
}