<?php

namespace GriffinForms\Admin\App\Html\Elements;

use \GriffinForms\Traits\Singleton;

class BsTabs
{
    use Singleton;

    public function navTabs(array $tabs)
    {
        echo '<ul class="nav nav-underline nav-fill border-bottom justify-content-center" role="tablist" style="--bs-nav-underline-gap: 0;">';

        foreach ($tabs as $pos => $data) {
            $this->navTab($pos, $data);
        }

        echo '</ul>';
    }

    private function navTab(int $pos, array $data)
    {
        if (!is_array($data) or empty($data['id']) or empty($data['label'])) {return;}

        $active = '';

        if ($pos === 0) {
            $active = ' active';
        }

        echo '<li class="nav-item" role="presentation" style="margin-bottom:-1px;">';
        echo '<button class="nav-link py-2' . esc_attr($active) . '" id="' . esc_attr($data['id']) . '" data-bs-toggle="tab" data-bs-target="#' . esc_attr($data['id'] . '-pane') . '" type="button" role="tab">';
        echo esc_html($data['label']);
        echo '</button>';
        echo '</li>';
    }
}