<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Core\Admin\Settings;

defined( 'ABSPATH' ) || exit;

/**
 * Represents a single tab within a settings container
 */
class SettingsTab
{
    private string $id;
    private string $name;
    private array $factories = [];

    public function __construct(string $id, string $name)
    {
        $this->id = $id;
        $this->name = $name;
    }

    public function addFieldsFactory(callable $factory): self
    {
        $this->factories[] = $factory;
        return $this;
    }

    public function getFields(): array
    {
        return array_reduce($this->factories, function ($carry, $factory) {
            if (is_callable($factory)) {
                $carry = array_merge($carry, $factory());
            }
            return $carry;
        }, []);
    }

    public function getId(): string
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }
}