<?php get_header(); ?>
<div class="content-middle articles-wrapper">
    <?php get_template_part('partials/rubrics-mobile'); ?>

    <div class="section-title-author">
        <?php
        // Получаем ID текущего автора
        //$author_id = get_queried_object_id();
        $author_id = get_the_author_meta('ID');
        $avatar_id = get_user_meta($author_id, 'avatar_attachment_id', true);

        if ($avatar_id) {
            echo wp_get_attachment_image($avatar_id, 'medium', false, array('class' => 'author-avatar'));
        } else {
            // Fallback: Gravatar или дефолтное изображение
            echo '<div class="author-avatar">' . get_avatar($author_id, 100, '', '', array('class' => 'avatar-round')) . '</div>';
        }?>
        <h1 class="section-title__title"><?= get_the_author(); ?></h1>
    </div>

    <?php if (!is_paged()) {
        $author_description = get_the_author_meta('description');
        if (!empty($author_description)) {
            echo '<div class="author-desc">';
            echo nl2br(esc_html($author_description));
            echo '</div>';
        }
    }?>

    <div class="articles-preview">
        <?php
        $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
        $args = array(
            'post_type'      => 'post',
            'posts_per_page' => 11,
            'paged'          => $paged,
            'author'         => $author_id
        );
        $query = new WP_Query($args);
        ?>
        <?php get_template_part('partials/post-list', null, ['query' => $query]); ?>
    </div>

    <?php custom_pagination(); ?>
</div>
<?php get_footer(); ?>