<?php
/**
 * Template part for displaying entry thumbnail (featured image).
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package     Business Interface
 * @author      WPInterface Team
 * @since       1.0.0
 */

/**
 * Do not allow direct script access.
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Get default post media.
$business_interface_media = business_interface_get_post_media( '' );

if ( ! $business_interface_media || post_password_required() ) {
	return;
}

$business_interface_post_format = get_post_format();

// Wrap with link for non-singular pages.
if ( 'link' === $business_interface_post_format || ! is_single( get_the_ID() ) ) {

	$business_interface_icon = '';

	if ( is_sticky() ) {
		$business_interface_icon = sprintf(
			'<span class="entry-media-icon" title="%1$s" aria-hidden="true"><span class="entry-media-icon-wrapper">%2$s%3$s</span></span>',
			esc_attr__( 'Featured', 'business-interface' ),
			business_interface()->icons->get_svg(
				'star',
				array(
					'class'       => 'top-icon',
					'aria-hidden' => 'true',
				)
			),
			business_interface()->icons->get_svg( 'star', array( 'aria-hidden' => 'true' ) )
		);
	} elseif ( 'video' === $business_interface_post_format ) {
		$business_interface_icon = sprintf(
			'<span class="entry-media-icon" aria-hidden="true"><span class="entry-media-icon-wrapper">%1$s%2$s</span></span>',
			business_interface()->icons->get_svg(
				'play',
				array(
					'class'       => 'top-icon',
					'aria-hidden' => 'true',
				)
			),
			business_interface()->icons->get_svg( 'play', array( 'aria-hidden' => 'true' ) )
		);
	} elseif ( 'link' === $business_interface_post_format ) {
		$business_interface_icon = sprintf(
			'<span class="entry-media-icon" title="%1$s" aria-hidden="true"><span class="entry-media-icon-wrapper">%2$s%3$s</span></span>',
			esc_url( business_interface_entry_get_permalink() ),
			business_interface()->icons->get_svg(
				'external-link',
				array(
					'class'       => 'top-icon',
					'aria-hidden' => 'true',
				)
			),
			business_interface()->icons->get_svg( 'external-link', array( 'aria-hidden' => 'true' ) )
		);
	}

	$business_interface_icon = apply_filters( 'business_interface_post_format_media_icon', $business_interface_icon, $business_interface_post_format );

	$business_interface_media = sprintf(
		'<a href="%1$s" class="entry-image-link">%2$s%3$s</a>',
		esc_url( business_interface_entry_get_permalink() ),
		$business_interface_media,
		$business_interface_icon
	);
}

$business_interface_media = apply_filters( 'business_interface_post_thumbnail', $business_interface_media );

// Print the post thumbnail.
echo wp_kses(
	sprintf(
		'<div class="post-thumb entry-media thumbnail">%1$s</div>',
		$business_interface_media
	),
	business_interface_get_allowed_html_tags()
);
