<?php

use Silvanus\includes\blocks\AcfBlockFields;

try {
    $fields = new AcfBlockFields('Two Column Link Rows', __FILE__);

    $fields->addContainerSettings();

    $fields->addText('Main Header', [
        'required' => 0,
    ]);

    $fields->addGroup('column widths', ['layout' => 'row'])
        ->addRepeater('breakpoints', [
            'layout' => 'table',
            'button_label' => 'Add breakpoint',
            'instructions' => 'Set widths per breakpoint. Example: md = 3/9 (25%/75%).',
        ])
        ->addSelect('breakpoint', [
            'choices' => [
                '' => 'Extra Small (xs)',
                'sm' => 'Small (sm)',
                'md' => 'Medium (md)',
                'lg' => 'Large (lg)',
                'xl' => 'Extra Large (xl)',
                'xxl' => 'Extra extra Large (xxl)',
            ],
            'default_value' => 'md',
            'ui' => 1,
        ])
        ->addNumber('col_one_width', [
            'default_value' => 3,
            'min' => 1,
            'max' => 12,
            'step' => 1,
        ])
        ->addNumber('col_two_width', [
            'default_value' => 9,
            'min' => 1,
            'max' => 12,
            'step' => 1,
        ])
        ->endRepeater()
        ->endGroup();

    $fields->addRepeater('rows', [
        'layout' => 'block',
        'button_label' => 'Add row',
        'min' => 1,
    ])
        ->addText('title', [
            'required' => 0,
        ])
        ->addRepeater('links', [
            'layout' => 'table',
            'button_label' => 'Add link',
            'min' => 0,
        ])
        ->addLink('link', [
            'return_format' => 'array',
        ])
        ->endRepeater()
        ->endRepeater();

    return $fields->build();
} catch (\StoutLogic\AcfBuilder\FieldNameCollisionException $e) {
    // no-op
}