<?php

/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package WowPress
 */

use WoWPress\Models\User;

$author = User::find(get_the_author_meta('ID'));

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<div class="post-wrapper" style="--author-class:var(--color-<?=$author->color?>)">
		<div class="post-title">
			<h1 class="underline"><a href="<?=the_permalink()?>"><?php the_title() ?></a></h1>
		</div>
		<div class="post-content"><?php the_content() ?></div>
		<div class="post-day"><?= get_the_date('d') ?></div>
		<div class="post-month"><?= get_the_date('F') ?></div>
		<?php
		$category = get_the_category();
		$category = array_pop($category);
		$color = get_term_meta($category->term_id, 'color', true);
		?>
		<div class="post-category ribbon" style="--color-ribbon:#<?= ctype_xdigit($color) ? $color : 'fff' ?>"><span><?= $category->name ?></span></div>
		<div class="post-avatar"><img src="<?= $author->avatar ?>"></div>
		<div class="post-author">
			<?php if (current_user_can('edit_post', $post->ID)) : ?>
				<a href="<?= get_edit_post_link($post->ID) ?>">
					<?= $author->username ?>
				</a>
			<?php else : ?>
				<?= $author->username ?>
			<?php endif; ?>
		</div>
</article><!-- #post-${ID} -->