<?php
/**
 * File input partial.
 *
 * Variables consumed:
 *   string      $name      — input name attribute (used for id too unless $id set)
 *   string      $label     — visible label text
 *   string      $accept    — MIME types / extensions for the accept attribute (e.g. 'image/jpeg,image/png')
 *   string|null $hint      — optional hint shown in <small> below the input
 *   bool        $required  — whether the field is required; default false
 *   bool        $multiple  — whether to allow multiple file selection; default false
 *   string|null $id        — override the id attribute (defaults to $name)
 */

$accept   = $accept   ?? '';
$hint     = $hint     ?? null;
$hintRaw  = $hintRaw  ?? false; // when true, $hint is emitted as raw HTML
$required = $required ?? false;
$multiple = $multiple ?? false;
$id       = $id       ?? $name;
$previewId = 'fp-' . htmlspecialchars($id);
?>
<div>
    <label for="<?= htmlspecialchars($id) ?>"><?= htmlspecialchars($label) ?><?= $required ? ' <span class="asterisk">*</span>' : '' ?></label>
    <div class="admin-file-input">
        <input type="file"
               id="<?= htmlspecialchars($id) ?>"
               name="<?= htmlspecialchars($name) ?><?= $multiple ? '[]' : '' ?>"
               <?= $accept   ? 'accept="'   . htmlspecialchars($accept)  . '"' : '' ?>
               <?= $multiple ? 'multiple' : '' ?>
               <?= $required ? 'required' : '' ?>
               data-preview="<?= $previewId ?>">
        <div id="<?= $previewId ?>" class="file-preview-list" aria-live="polite"></div>
        <?php if ($hint): ?>
        <small><?= $hintRaw ? $hint : htmlspecialchars($hint) ?></small>
        <?php endif; ?>
    </div>
</div>
<?php
unset($accept, $hint, $hintRaw, $required, $multiple, $id, $previewId);
