<?php

/**
 * The header for our theme
 *
 * This is the template that displays the `head` element and everything up
 * until the `#content` element.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package WowPress
 */

use WoWPress\Frontend\Icon;

global $user;
?>
<!doctype html>
<html <?php language_attributes(); ?>>

<head>
	<meta charset="<?php bloginfo('charset'); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="profile" href="https://gmpg.org/xfn/11">
	<?php wp_head(); ?>
	<style>
		:root {
			--color-background: var(--color-deepblue);
		}
	</style>
</head>

<body <?php body_class('dark'); ?>>
	<?php if (get_sidebar_status('left')) : ?>
		<template x-data x-teleport="#sidebar_left">
			<div class="bg-glass shadow p-auto order-1 flex flex-col gap-2">
				<div class="flex flex-row justify-between">
					<div>Hallo <?= $user->username ?></div>
					<?php if (!$user->ID) : ?>
						<div>Bitte <a href="/wp-login.php" class="text-alliance underline">einloggen</a> :)</div>
					<?php else : ?>
						<div><a href="<?=wp_logout_url('/')?>" class="text-alliance underline"><?= Icon::get('o-power') ?></a></div>

					<?php endif; ?>
				</div>
				<?php if ($user->ID) : ?>
					<?php if(current_user_can('wowpress_edit_raids')): ?>
						<a href="/wp-admin" class="btn btn-red"><?=Icon::get('o-shield-exclamation')?> Admin-Bereich</a>
					<?php endif; ?>
					<div>
						<h5 class="text-center text-lg font-bold">Charakter-Liste</h5>
						<div class="flex flex-col gap-2">
							<?php
							$chars = $user->characters;
							if (!empty($chars)) {
								foreach ($chars as $character) : ?>
									<button class="btn btn-outline btn-<?= $character->color ?> w-full cursor-default">
										<img src="<?= $character->classIcon ?>" class="h-8"><?= $character->name ?></button>
								<?php endforeach;
							} else {
								?>
								Keine Chataktere zugewiesen.
							<?php
							}
							?>
						</div>
					</div>
				<?php endif; ?>

			</div>
		</template>
	<?php endif; ?>

	<?php wp_body_open(); ?>



	<?php get_template_part('template-parts/layout/header', 'content'); ?>

	<div class="content-wrapper">
		<?php if (is_active_sidebar('top-widgets') && get_sidebar_status('top')) : ?>
			<div class="widget-wrapper top-widgets" id="sidebar_top">
				<?php dynamic_sidebar('top-widgets'); ?>
			</div>
		<?php endif; ?>
		<?php if (is_active_sidebar('left-widgets') && get_sidebar_status('left')) : ?>
			<div class="widget-wrapper left-widgets" id="sidebar_left">
				<?php dynamic_sidebar('left-widgets'); ?>
			</div>
		<?php endif; ?>
		<div id="content" class="content">