<?php

use StoutLogic\AcfBuilder\FieldsBuilder;

$generalSettings = new FieldsBuilder('Options Footer Settings');

$generalSettings
    ->addRepeater('columns', [
        'label' => 'Columns',
        'layout' => 'row',
        'button_label' => 'Add column',
        'min' => 0,
    ])
    ->addSelect('column_type', [
        'label' => 'Column type',
        'choices' => [
            'logo_tagline' => 'Logo & tagline',
            'menu' => 'Menu',
            'contact' => 'Contact',
            'social' => 'Social',
            'text' => 'Text',
        ],
        'ui' => 1,
        'required' => 1,
    ])

    // Menu
    ->addText('title', [
        'label' => 'Title',
    ])
        ->conditional('column_type', '==', 'social')
            ->or('column_type', '==', 'menu')
            ->or('column_type', '==', 'contact')
            ->or('column_type', '==', 'text')

    ->addSelect('menu', [
        'key' => 'field_footer_settings_column_menu_term_id',
        'label' => 'Menu',
        'choices' => [],
        'ui' => 1,
        'allow_null' => 1,
        'instructions' => 'Select a WP Menu to render in this column.',
        'conditional_logic' => [
            [
                [
                    'field' => 'column_type',
                    'operator' => '==',
                    'value' => 'menu',
                ],
            ],
        ],
    ])

    ->addNumber('menu_items_per_column', [
        'label' => 'Menu items per column',
        'instructions' => 'Footer menus will flow into multiple columns on desktop. Default is 5.',
        'default_value' => 5,
        'min' => 1,
        'max' => 20,
        'step' => 1,
        'conditional_logic' => [
            [
                [
                    'field' => 'column_type',
                    'operator' => '==',
                    'value' => 'menu',
                ],
            ],
        ],
    ])

    // Contact
    ->addCheckbox('show_address', [
        'label' => 'Show address?',
        'choices' => ['Yes'],
        'layout' => 'horizontal',
        'conditional_logic' => [
            [
                [
                    'field' => 'column_type',
                    'operator' => '==',
                    'value' => 'contact',
                ],
            ],
        ],
    ])

    // Text
    ->addWysiwyg('text', [
        'label' => 'Text',
        'tabs' => 'visual',
        'toolbar' => 'basic',
        'media_upload' => 0,
        'rows' => 4,
        'conditional_logic' => [
            [
                [
                    'field' => 'column_type',
                    'operator' => '==',
                    'value' => 'text',
                ],
            ],
        ],
    ])

    // Logo & Tagline
    ->addImage('logo_override', [
        'label' => 'Logo override (optional)',
        'instructions' => 'If set, this image will be used instead of the site logo for this footer column.',
        'return_format' => 'id',
        'preview_size' => 'medium',
        'library' => 'all',
        'required' => 0,
        'conditional_logic' => [
            [
                [
                    'field' => 'column_type',
                    'operator' => '==',
                    'value' => 'logo_tagline',
                ],
            ],
        ],
    ])
    ->addCheckbox('include_social_links', [
        'label' => 'Include social links?',
        'choices' => ['Yes'],
        'layout' => 'horizontal',
    ])
    ->conditional('column_type', '==', 'logo_tagline')
    ->or('column_type', '==', 'menu')
    ->or('column_type', '==', 'contact')
    ->or('column_type', '==', 'text')


    ->endRepeater();

$generalSettings->setLocation('options_page', '==', 'acf-options-footer-settings');

return $generalSettings->build();