<?php
/**
 * Zeen block social icons
 *
 * @since 1.0.0
 */

class ZeenBlockSocialIcons extends ZeenBlocks {

	/**
	 * Constructor
	 *
	 * @since 1.0.0
	 *
	*/
	public function __construct( $args ) {
		$this->type = 'social';
		parent::__construct( $args );
	}

	/**
	 * Block output
	 *
	 * @since 1.0.0
	 *
	*/
	public function output( $echo = true ) {

		if ( $this->enabled() != true ) {
			return;
		}

		if ( empty( $echo ) ) {
			ob_start();
		}
		$fs = $this->args['fs'];
		if ( empty( $this->args['only_inner'] ) ) {
			$this->opening_wrap();
			$this->block_title();
		}
		$icons = array();
		$use_to = empty( $this->args['use_to'] ) ? 'on' : $this->args['use_to'];
		if ( 'on' == $this->args['facebook'] ) {
			$icons['fb'] = array(
				'icon' => 'facebook',
				'title' => 'Facebook',
			);
			$icons['fb']['url'] = 'on' == $use_to || empty( $this->args['facebook_url'] ) ? get_theme_mod( 'icons_facebook' ) : $this->args['facebook_url'];
		}
		if ( 'on' == $this->args['twitter'] ) {
			$icons['tw'] = array(
				'icon' => 'twitter',
				'title' => 'Twitter',
			);
			$icons['tw']['url'] = 'on' == $use_to || empty( $this->args['twitter_url'] ) ? get_theme_mod( 'icons_twitter' ) : $this->args['twitter_url'];
		}
		if ( 'on' == $this->args['instagram'] ) {
			$icons['in'] = array(
				'icon' => 'instagram',
				'title' => 'Instagram',
			);
			$icons['in']['url'] = 'on' == $use_to || empty( $this->args['instagram_url'] ) ? get_theme_mod( 'icons_instagram' ) : $this->args['instagram_url'];

		}
		if ( 'on' == $this->args['youtube'] ) {
			$icons['yo'] = array(
				'icon' => 'youtube-play',
				'title' => 'YouTube',
			);
			$icons['yo']['url'] = 'on' == $use_to || empty( $this->args['youtube_url'] ) ? get_theme_mod( 'icons_youtube' ) : $this->args['youtube_url'];
		}
		if ( 'on' == $this->args['twitch'] ) {
			$icons['tw'] = array(
				'icon' => 'twitch',
				'title' => 'Twitch',
			);
			$icons['tw']['url'] = 'on' == $use_to || empty( $this->args['twitch_url'] ) ? get_theme_mod( 'icons_twitch' ) : $this->args['twitch_url'];
		}
		if ( 'on' == $this->args['linkedin'] ) {
			$icons['li'] = array(
				'icon' => 'linkedin',
				'title' => 'LinkedIn',
			);
			$icons['li']['url'] = 'on' == $use_to || empty( $this->args['linkedin_url'] ) ? get_theme_mod( 'icons_linkedin' ) : $this->args['linkedin_url'];
		}
		if ( 'on' == $this->args['soundcloud'] ) {
			$icons['so'] = array(
				'icon' => 'soundcloud',
				'title' => 'Soundcloud',
			);
			$icons['so']['url'] = 'on' == $use_to || empty( $this->args['soundcloud_url'] ) ? get_theme_mod( 'icons_soundcloud' ) : $this->args['soundcloud_url'];
		}
		if ( 'on' == $this->args['pinterest'] ) {
			$icons['pi'] = array(
				'icon' => 'pinterest',
				'title' => 'Pinterest',
			);
			$icons['pi']['url'] = 'on' == $use_to || empty( $this->args['pinterest_url'] ) ? get_theme_mod( 'icons_pinterest' ) : $this->args['pinterest_url'];
		}
		if ( 'on' == $this->args['vk'] ) {
			$icons['vk'] = array(
				'icon' => 'vk',
				'title' => 'VK',
			);
			$icons['vk']['url'] = 'on' == $use_to || empty( $this->args['vk_url'] ) ? get_theme_mod( 'icons_vk' ) : $this->args['vk_url'];
		}
		$classes = 'on' == $this->args['centered'] ? ' centered' : '';
		?>
		<span class="social-icons clearfix<?php echo esc_attr( $classes ); ?>">
			<ul class="horizontal-menu menu-icons">
				<?php foreach ( $icons as $key ) { ?>
					<?php $url = $key['url']; ?>
					<li class="menu-icon menu-icon-<?php echo esc_attr( $key['icon'] ); ?>">
						<a href="<?php echo esc_url( $url ); ?>" data-title="<?php echo esc_attr( $key['title'] ); ?>" class="tipi-i-<?php echo esc_attr( $key['icon'] ); ?> tipi-tip tipi-tip-move" rel="noopener"></a>
					</li>
				<?php } ?>
			</ul>
		</span>
		<?php

		if ( empty( $this->args['only_inner'] ) ) {
			$this->closing_wrap();
		}
		if ( empty( $echo ) ) {
			return ob_get_clean();
		}

	}
}
