<?php

/**
 * Shared empty-state component.
 *
 * @var array<string, mixed> $emptyState
 */

$emptyState = is_array($emptyState ?? null) ? $emptyState : [];
$emptyMessage = trim((string) ($emptyState['message'] ?? ''));
if ($emptyMessage === '') {
    return;
}

$emptyHint = trim((string) ($emptyState['hint'] ?? ''));
$emptySize = strtolower(trim((string) ($emptyState['size'] ?? 'default')));
if (!in_array($emptySize, ['default', 'compact', 'small'], true)) {
    $emptySize = 'default';
}

$emptyAlign = strtolower(trim((string) ($emptyState['align'] ?? 'center')));
if (!in_array($emptyAlign, ['center', 'left'], true)) {
    $emptyAlign = 'center';
}

$emptyShowIcon = (bool) ($emptyState['icon'] ?? true);

$emptyAction = is_array($emptyState['action'] ?? null) ? $emptyState['action'] : [];
$emptyActionLabel = trim((string) ($emptyAction['label'] ?? ''));
$emptyActionHref = trim((string) ($emptyAction['href'] ?? ''));
$emptyActionForm = trim((string) ($emptyAction['form'] ?? ''));
$emptyActionClass = trim((string) ($emptyAction['class'] ?? 'secondary outline small'));
$emptyActionTarget = trim((string) ($emptyAction['target'] ?? ''));
$emptyActionRel = trim((string) ($emptyAction['rel'] ?? ''));
$showAction = $emptyActionLabel !== '' && ($emptyActionHref !== '' || $emptyActionForm !== '');

?>
<div class="app-empty-state" data-size="<?php e($emptySize); ?>" data-align="<?php e($emptyAlign); ?>">
  <?php if ($emptyShowIcon): ?>
    <svg class="app-empty-state-icon" xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
      <polyline points="22 12 16 12 14 15 10 15 8 12 2 12"></polyline>
      <path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"></path>
    </svg>
  <?php endif; ?>
  <p class="app-empty-state-message"><?php e($emptyMessage); ?></p>
  <?php if ($emptyHint !== ''): ?>
    <small class="app-empty-state-hint"><?php e($emptyHint); ?></small>
  <?php endif; ?>
  <?php if ($showAction): ?>
    <?php if ($emptyActionHref !== ''): ?>
      <a
        role="button"
        class="<?php e($emptyActionClass); ?> app-empty-state-action"
        href="<?php e($emptyActionHref); ?>"
        <?php if ($emptyActionTarget !== ''): ?>target="<?php e($emptyActionTarget); ?>"<?php endif; ?>
        <?php if ($emptyActionRel !== ''): ?>rel="<?php e($emptyActionRel); ?>"<?php endif; ?>
      >
        <?php e($emptyActionLabel); ?>
      </a>
    <?php else: ?>
      <button type="submit" class="<?php e($emptyActionClass); ?> app-empty-state-action" form="<?php e($emptyActionForm); ?>">
        <?php e($emptyActionLabel); ?>
      </button>
    <?php endif; ?>
  <?php endif; ?>
</div>
