drink-it-cold/views/availability.php

122 lines
5.4 KiB
PHP
Raw Normal View History

<?php
/** @var string $from */
/** @var string $to */
/** @var bool $checked */
/** @var array $errors */
/** @var array $groups */
/** @var int $freeCount */
/** @var int $total */
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
$bookingUrl = static fn (array $trailer): string => '/bookings/new?trailer=' . (int) $trailer['id']
. '&start=' . rawurlencode($from) . '&end=' . rawurlencode($to);
$groupMeta = [
'trailer' => [
'title' => 'Anhänger',
'empty' => 'Keine Anhänger hinterlegt.',
'none_free' => 'Im Zeitraum ist kein Anhänger frei.',
],
'chest' => [
'title' => 'Truhen',
'empty' => 'Keine Truhen hinterlegt.',
'none_free' => 'Im Zeitraum ist keine Truhe frei.',
],
];
?>
<div class="page-head page-head--compact">
<div>
<p class="eyebrow">Übersicht</p>
<h1>Verfügbarkeit</h1>
<p class="page-head__lede">Zeitraum wählen – die App zeigt, welche Anhänger und Truhen in dieser Zeit frei sind.</p>
</div>
<div class="page-head__actions">
<a class="btn" href="<?= e(url('/calendar?view=month&date=' . $from)) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Im Kalender
</a>
<a class="btn" href="<?= e(url('/')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-grid"/></svg> Zur Übersicht
</a>
</div>
</div>
<section class="card">
<div class="card__head">
<h2>Zeitraum</h2>
<p>Ein Wechseltag ist erlaubt: Endet eine Buchung am Tag des neuen Beginns, gilt das Fahrzeug als frei.</p>
</div>
<form method="get" action="<?= e(url('/availability')) ?>" class="form-grid">
<label class="field<?= $fieldError('from') !== '' ? ' has-error' : '' ?>">
<span>Von</span>
<input type="date" name="from" value="<?= e($from) ?>" required>
<?php if ($fieldError('from')): ?><em class="field-error"><?= e($fieldError('from')) ?></em><?php endif; ?>
</label>
<label class="field<?= $fieldError('to') !== '' ? ' has-error' : '' ?>">
<span>Bis</span>
<input type="date" name="to" value="<?= e($to) ?>" required>
<?php if ($fieldError('to')): ?><em class="field-error"><?= e($fieldError('to')) ?></em><?php endif; ?>
</label>
<div class="field field--wide">
<button class="btn primary" type="submit">
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg> Verfügbarkeit prüfen
</button>
</div>
</form>
</section>
<?php if ($checked && !$errors): ?>
<section class="card">
<div class="card__head card__head--row">
<div>
<h2>Ergebnis</h2>
<p><?= e(fmt_date_range($from, $to)) ?> · <?= (int) $freeCount ?> von <?= (int) $total ?> frei</p>
</div>
<a class="btn small" href="<?= e(url('/bookings/new?start=' . rawurlencode($from) . '&end=' . rawurlencode($to))) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
</div>
<div class="availability-grid">
<?php foreach ($groupMeta as $key => $meta): ?>
<?php
$rows = $groups[$key];
$groupTotal = (int) ($totals[$key] ?? 0);
?>
<div class="availability-group">
<h3>
<?= e($meta['title']) ?>
<span class="muted small"><?= count($rows) ?> von <?= $groupTotal ?> frei</span>
</h3>
<?php if (!$rows): ?>
<p class="muted small"><?= e($groupTotal === 0 ? $meta['empty'] : $meta['none_free']) ?></p>
<?php else: ?>
<ul class="availability-list">
<?php foreach ($rows as $row): ?>
<?php $trailer = $row['trailer']; ?>
<li class="availability-row is-free">
<span class="availability-row__name">
<span class="trailer-chip" style="--trailer: <?= e($trailer['color_hex']) ?>; --trailer-text: <?= e(contrast_color($trailer['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($trailer['color_hex']) ?>"></span>
<?= e($trailer['label']) ?>
</span>
</span>
<a class="btn small primary" href="<?= e(url($bookingUrl($trailer))) ?>">Buchen</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</section>
<?php elseif ($checked): ?>
<div class="alert alert--error" role="alert">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte den Zeitraum prüfen.</strong>
<?php foreach ($errors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
</div>
</div>
<?php else: ?>
<div class="empty-state small">
<p>Zeitraum wählen und „Verfügbarkeit prüfen" – danach kannst du direkt buchen.</p>
</div>
<?php endif; ?>