<?php

use StoutLogic\AcfBuilder\FieldsBuilder;

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

/**
 * Header Logo Routing (by path)
 */

$generalSettings
    ->addGroup('header_logo_routing', [
        'label' => 'Header Logo Routing',
        'layout' => 'block',
        'instructions' => 'Override the header/menubar logo by URL path. Longest matching rule wins.',
    ])
    ->addRepeater('routes', [
        'layout' => 'table',
        'button_label' => 'Add logo route',
        'min' => 0,
    ])
    ->addText('path', [
        'label' => 'Path',
        'instructions' => 'Example: /development or /. Use leading slash.',
        'required' => 1,
    ])
    ->addSelect('match_type', [
        'label' => 'Match',
        'choices' => [
            'exact' => 'Exact',
            'prefix' => 'Prefix (this path + subpaths)',
        ],
        'default_value' => 'prefix',
        'ui' => 1,
        'required' => 1,
    ])
    ->addImage('logo', [
        'label' => 'Logo override',
        'return_format' => 'id',
        'preview_size' => 'medium',
        'library' => 'all',
        'required' => 0,
        'instructions' => 'If set, this logo is used for matching paths.',
    ])
    ->addTrueFalse('hide_logo', [
        'label' => 'Hide logo (override)',
        'default_value' => 0,
        'ui' => 1,
        'instructions' => 'If enabled, hide the logo for matching paths.',
    ])
    ->endRepeater()
    ->addRepeater('hidden_paths', [
        'label' => 'Hidden paths (exact)',
        'layout' => 'table',
        'button_label' => 'Add hidden path',
        'min' => 0,
        'instructions' => 'If the current path matches one of these exactly, the logo is hidden.',
    ])
    ->addText('path', [
        'label' => 'Path',
        'instructions' => 'Example: /landing/special-page (exact match). Use leading slash.',
        'required' => 1,
    ])
    ->endRepeater()
    ->endGroup();

/**
 * Top Menu Routing (by path)
 */
$generalSettings
    ->addGroup('top_menu_routing', [
        'label' => 'Top Menu Routing',
        'layout' => 'block',
        'instructions' => 'Choose which “top menu” to show based on the URL path. Longest matching rule wins.',
    ])
    ->addRepeater('routes', [
        'layout' => 'table',
        'button_label' => 'Add route',
        'min' => 0,
    ])
    ->addText('path', [
        'label' => 'Path',
        'instructions' => 'Example: /development or /. Use leading slash.',
        'required' => 1,
    ])
    ->addSelect('match_type', [
        'label' => 'Match',
        'choices' => [
            'exact' => 'Exact',
            'prefix' => 'Prefix (this path + subpaths)',
        ],
        'default_value' => 'prefix',
        'ui' => 1,
        'required' => 1,
    ])
    ->addSelect('menu', [
        'key' => 'field_top_menu_route_menu',
        'label' => 'Menu to show',
        'choices' => [],
        'ui' => 1,
        'allow_null' => 1,
        'instructions' => 'Select which WP Menu to show. Leave blank for “no menu”.',
    ])
    ->addTrueFalse('hide_menu', [
        'label' => 'Hide menu (override)',
        'default_value' => 0,
        'ui' => 1,
        'instructions' => 'If enabled, this route hides the menu regardless of selected menu.',
    ])
    ->endRepeater()
    ->addRepeater('hidden_paths', [
        'label' => 'Hidden paths (exact)',
        'layout' => 'table',
        'button_label' => 'Add hidden path',
        'min' => 0,
        'instructions' => 'If the current path matches one of these exactly, the top menu is hidden.',
    ])
    ->addText('path', [
        'label' => 'Path',
        'instructions' => 'Example: /landing/special-page (exact match). Use leading slash.',
        'required' => 1,
    ])
    ->endRepeater()
    ->endGroup();

// enable or disable container class globally
$generalSettings
    ->addGroup('General Settings')
    ->addChoiceField("container", "radio", [
        'choices' => [
            'container' => 'Enable',
            '' => 'Disable',
        ],
        'description' => 'enable or disable container class globally',
    ]);

$generalSettings
    ->addGroup('global_ctas', [
        'instructions' => 'Manage reusable CTAs. Blocks can select which CTA to display.',
        'layout' => 'block',
    ])
    ->addRepeater('ctas', [
        'layout' => 'row',
        'button_label' => 'Add CTA',
        'min' => 0,
    ])
    ->addImage('background_image', [
        'label' => 'Background image',
        'return_format' => 'id',
        'preview_size' => 'medium',
        'required' => 0,
    ])
    ->addText('title', [
        'label' => 'Title',
        'required' => 0,
    ])
    ->addWysiwyg('tagline', [
        'label' => 'Tagline',
        'required' => 0,
        'rows' => 3,
    ])
    ->addLink('button', [
        'label' => 'Link button',
        'return_format' => 'array',
        'required' => 0,
    ])
    ->addSelect('layout', [
        'label' => 'Layout',
        'choices' => [
            'inline' => 'Inline',
            'stacked' => 'Stacked',
        ],
        'default_value' => 'inline',
        'ui' => 1,
        'required' => 0,
    ])
    ->addText('custom identifier class')
    ->endRepeater()
    ->endGroup();

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

return $generalSettings->build();