<?php

use ACFComposer\ACFComposer;

add_action('acf/init', function () {
    if (function_exists('acf_add_options_sub_page')) {
        acf_add_options_sub_page([
            'page_title'  => 'Scripts',
            'menu_title'  => 'Scripts',
            'menu_slug'   => 'theme-options-scripts',
            'parent_slug' => 'theme-options',
            'capability'  => 'edit_theme_options',
        ]);
    }

    $code_field = [
        'type'      => 'textarea',
        'rows'      => 12,
        'new_lines' => '',
        'wrapper'   => ['class' => 'codelibry-code-field'],
    ];

    ACFComposer::registerFieldGroup([
        'name'   => 'scripts_options',
        'title'  => 'Scripts',
        'fields' => [
            array_merge($code_field, [
                'label'        => 'Header scripts',
                'name'         => 'scripts-header',
                'instructions' => 'Output inside &lt;head&gt; via wp_head.',
            ]),
            array_merge($code_field, [
                'label'        => 'Body scripts - Top',
                'name'         => 'scripts-body-top',
                'instructions' => 'Output immediately after the opening &lt;body&gt; tag via wp_body_open.',
            ]),
            array_merge($code_field, [
                'label'        => 'Body scripts - Bottom',
                'name'         => 'scripts-body-bottom',
                'instructions' => 'Output right before the closing &lt;/body&gt; tag.',
            ]),
            array_merge($code_field, [
                'label'        => 'Footer scripts',
                'name'         => 'scripts-footer',
                'instructions' => 'Output via wp_footer.',
            ]),
        ],
        'location' => [
            [
                [
                    'param'    => 'options_page',
                    'operator' => '==',
                    'value'    => 'theme-options-scripts',
                ],
            ],
        ],
    ]);
});
