<?php /** @var array $artist; @var array $weekly; @var array $exceptions */
$byWeekday = [];
foreach ($weekly as $w) { $byWeekday[(int)$w['weekday']] = $w; }
$days = [0 => 'sun', 1 => 'mon', 2 => 'tue', 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat'];
?>
<div class="p-8 max-w-3xl">
  <a href="<?= url('/admin/artists') ?>" class="text-xs text-bone/50 hover:text-bone">← <?= e(t('admin.artists.back')) ?></a>
  <h1 class="mt-2 text-3xl font-display"><?= e($artist['display_name'] ?? '') ?> · <?= e(t('admin.schedule.title')) ?></h1>

  <form method="POST" action="<?= url('/admin/artists/' . e($artist['id']) . '/schedule') ?>" class="mt-8 space-y-5">
    <?= csrf_field() ?>
    <h2 class="text-sm uppercase tracking-widest text-gold"><?= e(t('admin.schedule.weekly')) ?></h2>
    <div class="space-y-2">
      <?php foreach ($days as $wd => $name): $row = $byWeekday[$wd] ?? null; ?>
        <div class="flex items-center gap-3 bg-ink/40 border border-white/10 rounded-md p-3">
          <label class="flex items-center gap-2 w-24">
            <input type="checkbox" name="enabled[<?= $wd ?>]" value="1" <?= $row ? 'checked' : '' ?>>
            <span class="text-sm uppercase tracking-widest"><?= e(t('day.' . $name)) ?></span>
          </label>
          <input type="time" name="start[<?= $wd ?>]" value="<?= e($row['start_time'] ?? '11:00') ?>" class="input w-32">
          <span class="text-bone/40">–</span>
          <input type="time" name="end[<?= $wd ?>]" value="<?= e($row['end_time'] ?? '19:00') ?>" class="input w-32">
        </div>
      <?php endforeach; ?>
    </div>

    <h2 class="text-sm uppercase tracking-widest text-gold pt-4"><?= e(t('admin.schedule.add_exception')) ?></h2>
    <div class="grid grid-cols-2 md:grid-cols-4 gap-3 bg-ink/40 border border-white/10 rounded-md p-4">
      <div><label class="label"><?= e(t('admin.schedule.date')) ?></label><input type="date" name="exception_date" class="input"></div>
      <div><label class="label"><?= e(t('admin.schedule.start')) ?></label><input type="time" name="exception_start" class="input"></div>
      <div><label class="label"><?= e(t('admin.schedule.end')) ?></label><input type="time" name="exception_end" class="input"></div>
      <div>
        <label class="label"><?= e(t('admin.schedule.day_off')) ?></label>
        <label class="flex items-center gap-2 pt-2"><input type="checkbox" name="is_day_off" value="1"> <?= e(t('common.yes')) ?></label>
      </div>
      <div class="col-span-2 md:col-span-4"><label class="label"><?= e(t('admin.schedule.reason')) ?></label><input name="exception_reason" class="input"></div>
    </div>

    <button class="btn-gold"><?= e(t('common.save')) ?></button>
  </form>

  <?php if (!empty($exceptions)): ?>
    <h3 class="mt-10 text-sm uppercase tracking-widest text-gold mb-3"><?= e(t('admin.schedule.upcoming_exceptions')) ?></h3>
    <ul class="bg-ink/40 border border-white/10 rounded-md divide-y divide-white/5">
      <?php foreach ($exceptions as $ex): ?>
        <li class="p-3 text-sm flex items-center justify-between">
          <span><?= e($ex['date'] ?? '') ?><?= !empty($ex['is_day_off']) ? ' · ' . e(t('admin.schedule.day_off')) : ' · ' . e($ex['start_time'] ?? '') . '–' . e($ex['end_time'] ?? '') ?></span>
          <span class="text-bone/50 text-xs"><?= e($ex['reason'] ?? '') ?></span>
        </li>
      <?php endforeach; ?>
    </ul>
  <?php endif; ?>
</div>
