<?php
$panelItems = is_array($statusPanelList ?? null) ? $statusPanelList : [];
$panelTitle = trim((string) ($statusPanelTitle ?? 'Statusy'));
?>

<aside class="card order-statuses-side">
  <div class="order-statuses-side__title"><?= $e($panelTitle) ?></div>
  <?php foreach ($panelItems as $group): ?>
    <?php $groupItems = is_array($group['items'] ?? null) ? $group['items'] : []; ?>
    <div class="order-status-group">
      <?php if ((string) ($group['name'] ?? '') !== ''): ?>
        <div class="order-status-group__name"><?= $e((string) ($group['name'] ?? '')) ?></div>
      <?php endif; ?>
      <?php foreach ($groupItems as $item): ?>
        <?php
        $tone = (string) ($item['tone'] ?? 'neutral');
        $color = (string) ($item['color_hex'] ?? '#64748b');
        $rowClass = 'order-status-row tone-' . $tone . (!empty($item['is_active']) ? ' is-active' : '');
        $url = trim((string) ($item['url'] ?? ''));
        ?>
        <?php if ($url !== ''): ?>
          <a href="<?= $e($url) ?>" class="<?= $e($rowClass) ?>" style="--status-color: <?= $e($color) ?>;">
            <span class="order-status-row__label"><?= $e((string) ($item['label'] ?? '')) ?></span>
            <span class="order-status-row__count"><?= $e((string) ((int) ($item['count'] ?? 0))) ?></span>
          </a>
        <?php else: ?>
          <div class="<?= $e($rowClass) ?>" style="--status-color: <?= $e($color) ?>;">
            <span class="order-status-row__label"><?= $e((string) ($item['label'] ?? '')) ?></span>
            <span class="order-status-row__count"><?= $e((string) ((int) ($item['count'] ?? 0))) ?></span>
          </div>
        <?php endif; ?>
      <?php endforeach; ?>
    </div>
  <?php endforeach; ?>
</aside>

