<?php

use Silvanus\includes\blocks\AcfBlockFields;

try {
    $fields = new AcfBlockFields('Image Slider', __FILE__);

    $fields->addContainerSettings();

    $fields->addText('title', [
        'default_value' => '',
        'required' => 0,
    ]);

    $fields->addNumber('slides_per_view', [
        'label' => 'Slides shown (default)',
        'default_value' => 3,
        'min' => 1,
        'max' => 5,
        'step' => 1,
        'required' => 0,
        'instructions' => 'Default number of slides visible if no breakpoint column settings are provided.',
    ]);

    // Optional breakpoint override using bootstrapColumnSettings()
    $fields->bootstrapColumnSettings();

    $fields->addNumber('slides_to_scroll', [
        'label' => 'Slides scrolled per click',
        'default_value' => 1,
        'min' => 1,
        'max' => 6,
        'step' => 1,
        'required' => 0,
        'instructions' => 'How many slides move when clicking an arrow.',
    ]);

    $fields->addRepeater('images', [
        'key' => 'field_image_slider_slides',
        'layout' => 'block',
        'button_label' => 'Add slide',
        'min' => 1,
        'instructions' => 'Each slide must have either an image OR a video (not both).',
    ])
        ->addImage('image', [
            'key' => 'field_image_slider_image',
            'return_format' => 'id',
            'preview_size' => 'medium',
            'library' => 'all',
            'mime_types' => 'png,jpg,jpeg,webp,svg',
            'required' => 0,
        ])
        ->addFile('video', [
            'key' => 'field_image_slider_video',
            'return_format' => 'array',
            'library' => 'all',
            'mime_types' => 'mp4,webm,ogg',
            'required' => 0,
            'instructions' => 'Optional. Upload an MP4/WebM/Ogg.',
        ])
        ->endRepeater();

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