<?php
$filters = mb_get_block_field("filters");
$context = mb_get_block_field("context");
$component_id = uniqid("inoby-block-filter-");

$count = count($filters);
if (!$count) {
  return;
}

$cols_lg = $count <= 4 ? floor(12 / $count) : 3;
$cols_md = $cols_lg <= 6 ? 6 : 12;
$cols_sm = 12;
?>

<div <?= inoby_block_attrs($attributes, ["class" => "inoby-block-filter", "id" => $component_id, "data-context" => esc_attr($context)]) ?>>
    <div class="container">
      <div class="row">
        <?php foreach ($filters as $filter): ?>
          <div class="<?= "col-$cols_lg col-md-$cols_md col-sm-$cols_sm" ?>">
            <a href="#0" class="filter-item" data-target="<?= $filter["id"] ?? "" ?>">
              <span><?= $filter["label"] ?></span>
            </a>
          </div>
        <?php endforeach; ?>
      </div>
      <div class="inner-blocks">
        <InnerBlocks />
      </div>
    </div>
</div>