<?php

use Silvanus\includes\blocks\AcfBlockFields;

try {
    $block = new AcfBlockFields('Gravity Form Block', __FILE__);

    $block->addContainerSettings();

    $forms = [];

    if (class_exists('GFAPI')) {
        $gf_forms = \GFAPI::get_forms();

        if (is_array($gf_forms)) {
            foreach ($gf_forms as $form) {
                if (!empty($form['id']) && !empty($form['title'])) {
                    $forms[(string) $form['id']] = $form['title'];
                }
            }
        }
    }

    $block->addText('title', [
        'instructions' => 'Optional title displayed above the form.',
    ]);

    $block->addTextarea('description', [
        'rows' => 3,
        'instructions' => 'Optional description displayed above the form.',
    ]);

    $block->addChoiceField('form_id', 'select', [
        'choices' => $forms,
        'required' => 1,
        'instructions' => 'Select a Gravity Forms form to render.',
    ]);

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