<?php

use  Unakit\Customizer ;
global  $post ;

if ( is_single() && Customizer::get_mod( 'show_author_card' ) && isset( $post->post_author ) ) {
    echo  '<div class="author_card">' ;
    $unakit_author['name'] = esc_html( get_the_author_meta( 'display_name', $post->post_author ) );
    if ( empty($unakit_author['name']) ) {
        $unakit_author['name'] = esc_html( get_the_author_meta( 'nickname', $post->post_author ) );
    }
    $unakit_author['description'] = wp_kses_post( get_the_author_meta( 'user_description', $post->post_author ) );
    $unakit_author['website'] = esc_url( get_the_author_meta( 'url', $post->post_author ) );
    $unakit_author['page'] = esc_url( get_author_posts_url( get_the_author_meta( 'ID', $post->post_author ) ) );
    $unakit_author['avatar'] = esc_url( get_avatar_url( $post->post_author, [
        'size' => 48,
    ] ) );
    
    if ( !empty($unakit_author['avatar']) ) {
        echo  '<img class="author_card__avatar" src="' . $unakit_author['avatar'] . '" alt="" />' ;
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    }
    
    echo  '<div class="author_card__text">' ;
    
    if ( !empty($unakit_author['name']) ) {
        echo  '<p class="author_card__text__name"><a href="' . $unakit_author['page'] . '">' . $unakit_author['name'] . '</a></p>' ;
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    }
    
    
    if ( !empty($unakit_author['website']) ) {
        echo  '<p class="author_card__text__website"><a href="' . $unakit_author['website'] . '" target="_blank" rel="noopener noreferrer">' . str_replace( [ 'https://', 'http://' ], '', $unakit_author['website'] ) . '</a></p>' ;
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    }
    
    
    if ( !empty($unakit_author['description']) ) {
        echo  '<p class="author_card__text__description">' . $unakit_author['description'] . '</p>' ;
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    }
    
    echo  '</div></div>' ;
}
