<?php
/**
 * Filter toolbar partial
 *
 * Inputs:
 * $action (string)         - form action url
 * $q (string)              - search query
 * $placeholder (string)    - placeholder text
 * $filters (array)         - list of filters:
 *   [
 *     ['name'=>'conference_id','label'=>'Conference','options'=>[['v'=>0,'t'=>'--'],...], 'value'=> (int)],
 *     ['name'=>'status','label'=>'Status','options'=>[['v'=>'','t'=>'All'],...], 'value'=> (string)]
 *   ]
 * $actions (array)         - buttons on right:
 *   [['label'=>'Add','href'=>'...','class'=>'btn btn-primary ec-btn','icon'=>'fa-solid fa-plus']]
 */
?>
<form method="get" action="<?= e((string)($action ?? '')) ?>" class="ec-card mb-3">
  <div class="ec-card-bd">
    <div class="ec-toolbar">
      <div class="left" style="flex:1; min-width:280px;">
        <div style="flex:1; min-width:240px;">
          <input name="q" value="<?= e((string)($q ?? '')) ?>" class="form-control" placeholder="<?= e((string)($placeholder ?? trans('search'))) ?>">
        </div>

        <?php if (!empty($filters) && is_array($filters)): ?>
          <?php foreach ($filters as $f): ?>
            <div style="min-width:180px;">
              <select name="<?= e((string)$f['name']) ?>" class="form-select">
                <?php foreach (($f['options'] ?? []) as $opt): ?>
                  <?php
                    $ov = (string)($opt['v'] ?? '');
                    $sv = (string)($f['value'] ?? '');
                  ?>
                  <option value="<?= e($ov) ?>" <?= ($ov === $sv) ? 'selected' : '' ?>>
                    <?= e((string)($opt['t'] ?? $ov)) ?>
                  </option>
                <?php endforeach; ?>
              </select>
            </div>
          <?php endforeach; ?>
        <?php endif; ?>

        <button class="btn btn-primary ec-btn">
          <i class="fa-solid fa-magnifying-glass me-2"></i><?= e(trans('search')) ?>
        </button>
      </div>

      <div class="right">
        <?php if (!empty($actions) && is_array($actions)): ?>
          <?php foreach ($actions as $a): ?>
            <a class="<?= e((string)($a['class'] ?? 'btn btn-outline-primary ec-btn')) ?>" href="<?= e((string)($a['href'] ?? '#')) ?>">
              <?php if (!empty($a['icon'])): ?><i class="<?= e((string)$a['icon']) ?> me-2"></i><?php endif; ?>
              <?= e((string)($a['label'] ?? '')) ?>
            </a>
          <?php endforeach; ?>
        <?php endif; ?>
      </div>
    </div>
  </div>
</form>
