<?php

declare(strict_types=1);

use Builder\Core\Foundation\Definition\FieldBuilder;
use Builder\Core\Foundation\Definition\Section;

it('adds items with add()', function (): void {
    $builder = FieldBuilder::make()->add(
        Section::make('general')->label('General')->fields([]),
    );

    expect($builder->toSections())->toHaveCount(1);
});

it('whenModule adds items when module is bound', function (): void {
    app()->bind('builder.test_module', fn (): bool => true);

    $builder = FieldBuilder::make()
        ->add(Section::make('general')->label('General')->fields([]))
        ->whenModule('test_module', fn (FieldBuilder $b) => $b->add(
            Section::make('extra')->label('Extra')->fields([]),
        ));

    expect($builder->toSections())->toHaveCount(2);
});

it('whenModule skips items when module is not bound', function (): void {
    $builder = FieldBuilder::make()
        ->add(Section::make('general')->label('General')->fields([]))
        ->whenModule('nonexistent_module', fn (FieldBuilder $b) => $b->add(
            Section::make('extra')->label('Extra')->fields([]),
        ));

    expect($builder->toSections())->toHaveCount(1);
});
