<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package ismoderna
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function ismoderna_body_classes( $classes ) {
	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}

	// Adds a class of no-sidebar when there is no sidebar present.
	if ( ! is_active_sidebar( 'sidebar-1' ) ) {
		$classes[] = 'no-sidebar';
	}

	return $classes;
}
add_filter( 'body_class', 'ismoderna_body_classes' );

/**
 * Add a pingback url auto-discovery header for single posts, pages, or attachments.
 */
function ismoderna_pingback_header() {
	if ( is_singular() && pings_open() ) {
		printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
	}
}
add_action( 'wp_head', 'ismoderna_pingback_header' );

if( ! function_exists( 'ismoderna_primary_navigation_fallback' ) ) :

    /**
     * Fallback for primary navigation.
     *
     * @since 1.0.0
     */
    function ismoderna_primary_navigation_fallback() {
        
        echo '<a style="color: #000; border:2px solid #000; padding: 7px;  text-decoration: none;" href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '">' . esc_html__( 'Click here to add a menu', 'ismoderna' ) . '</a>';

    }

endif;

/**
 * Comment Form
*/
function ismoderna_comment_field_to_bottom( $fields ) {
    $comment_field = $fields['comment'];
    unset( $fields['comment'] );
    $fields['comment'] = $comment_field;
    return $fields;
}
add_filter( 'comment_form_fields', 'ismoderna_comment_field_to_bottom' );

/**
 * Custom Comment List
*/
function ismoderna_comment_list( $comment, $args, $depth ) {
    if ( 'div' === $args['style'] ) {
        $tag       = 'div';
        $add_below = 'comment';
    } else {
        $tag       = 'li';
        $add_below = 'div-comment';
    }
    ?>
    <<?php echo ''.esc_attr($tag); ?> class="media comment_box" id="comment-<?php comment_ID() ?>">
    <?php $avatar_url = get_avatar_url( $comment, $args['avatar_size'] ); 
    if($avatar_url ):?>
        <div class="pull_left_comment">
            <?php if ($args['avatar_size'] != 0) echo wp_kses_post(get_avatar($comment, $args['avatar_size'])); ?>
        </div>
    <?php endif;?>
    <div class="media-body">
        <div class="comment_detail <?php  if(!$avatar_url ): echo "noprofile"; endif;?>"><h4 class="comment_detail_title"><?php printf('%s', get_comment_author_link()); ?> |</h4><span class="comment_date"><?php esc_html(comment_date()) . ' at ' . esc_html(comment_time()); ?></span>
        <?php comment_reply_link(array_merge($args, array('reply_text' => __('<i class="fas fa-reply-all"></i>', 'ismoderna'),'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
        <?php if ( $comment->comment_approved == '0' ) : ?>
        <p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'ismoderna' ); ?></p>
        
        <?php endif; ?> 
        <?php comment_text(); ?>
    </div>
    </div>
    
<?php 
}