<section>
	<h1>Characters <span class="badge"><?= count($chars) . '/' . user()->char_slots ?></span></h1>
	<?php
		if (($f = flash('alert_character_list_1')) !== false) echo c_alert($f[0], $f[1]);

		if (count($chars) > 0):
	?>
		<form action="/characters" method="post">
			<input type="hidden" name="csrf" value="<?= csrf() ?>">

			<div class="my-2 character-select">
				<?php foreach ($chars as $i => $c) echo c_char_select_box($i, $c); ?>

				<div class="mt-4 buttons">
					<button type="submit" class="ui button primary" name="action" value="select">Select</button>
					<button type="submit" class="ui button danger" name="action" value="delete">Delete</button>
				</div>
			</div>
		</form>
	<?php else: ?>
		<!-- Should never see this particular message. If you have, there's a bug. -->
		<p>You have no characters.</p>
	<?php endif; ?>
</section>

<?php if (user()->char_slots > count($chars)): ?>
<section>
		<h2>Create a new character</h2>
		<?php $num_slots_left = user()->char_slots - count($chars); ?>
		<p>You have <b><?= $num_slots_left ?> <?= $num_slots_left === 1 ? 'slot' : 'slots' ?></b> left.</p>
		<form action="/character/create" method="post">
			<input type="hidden" name="csrf" value="<?= csrf() ?>">

			<div class="my-4">
				<?= c_form_errors('create-character') ?>
				<?= c_form_field('text', 'n', 'Character Name', formId: 'create-character') ?>
			</div>

			<button type="submit" class="ui button secondary">Create</button>
		</form>
</section>
<?php endif; ?>
