<?php
/**
 * Post author content
 *
 * @package wpstream-theme
 */

$author_id   = $post->post_author;
$author_image_url   = wpstream_get_author_profile_image_url_by_author_id( $author_id, 48 );
$author_url  = get_author_posts_url( $author_id );
$author_name = get_the_author_meta( 'display_name', $author_id );
$post_type   = wpstream_get_current_post_type();//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

?>
	<div class="wpstream_author_wrapper flex-wrap">

		<a class="wpstream_author" href="<?php echo esc_url( $author_url ); ?>">
			<img class="w-100 h-100" src="<?php echo esc_url( $author_image_url ); ?>" alt="<?php echo esc_attr( $author_name ); ?>">
		</a>

		<div class="wpstream_author_wrapper_name">

			<a class="" href="<?php echo esc_url( $author_url ); ?>">
				<?php echo esc_html( $author_name ); ?>
			</a>

			<span>

			<?php
			if ( is_single() ) {
				if ( 'post' === $post_type ) {
					echo esc_html__( 'Published in ', 'hello-wpstream' );
					the_category( ', ' );
					echo ' · ' . wpstream_get_post_read_count_by_id( $post->ID ) . ' · ';//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				} else {
					echo apply_filters( 'wpstream_author_content_post_type_message', '', $post_type );
				}
			}

			echo wpstream_get_post_published_duration_by_id( $post->ID );//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			?>
			
		</span>
		</div>
		<?php
		$post_type_list = apply_filters( 'wpstream_post_author_content_post_type_list', array( 'product' ) );
		if ( is_singular( $post_type_list ) ) {
			?>

			<a href="#" class="btn-pill"><?php esc_html_e( 'Subscribe', 'hello-wpstream' ); ?></a>

		<?php } ?>

	</div>

<?php

if ( is_singular( 'product' ) ) {
	global $product;
	if ( function_exists( 'wc_customer_bought_product' ) && ! wc_customer_bought_product( wp_get_current_user()->user_email, wp_get_current_user()->ID, $post->ID ) ) {
		?>

		<div class="wpstream-author-buttons">
			<?php
			$wp_stream_product_price   = $product->get_price_html();
			$wp_stream_add_to_cart_url = wc_get_cart_url() . '?add-to-cart=' . $post->ID . '&quantity=1';
			?>

			<a href="<?php echo esc_url( $wp_stream_add_to_cart_url ); ?>" class="wp-stream-playbtn">

				<?php
				// translators: %s product price.
				echo esc_html( sprintf( __( '%s&nbsp;- Add to Cart', 'hello-wpstream' ), $wp_stream_product_price ) );
				?>

			</a>
		</div>
		<?php
	} 
}
?>