<?php

namespace Reach\App\Fields;

use Reach\App\Interfaces\WordPressHooks;
use Reach\App\Fields\Abstracts\AbstractFieldGroup;

/**
 * Class MenuItemsOptions
 *
 * addHooks()
 * addLocalFieldGroupMenuItemsOptions()
 * addMenuItemsOptionsFields()
 *
 * @package Reach\App\Fields\Groups
 */
class MenuItemsOptions extends AbstractFieldGroup implements WordPressHooks {

    /**
     * Field group title
     *
     * @var
     */
    public $field_group_title;

    /**
     * MenuItemsOptions constructor.
     */
    public function __construct() {
        $this->group_key         = 'group_61183010081';
        $this->field_group_title = __( 'Menu Item Options', 'reach' );
    }

    /**
     * Add class hooks.
     */
    public function addHooks() {
        add_action( 'acf/init', [ $this, 'addLocalFieldGroupMenuItemsOptions' ] );
    }

    /**
     * Add a local field group containing site options to the Menu Options location
     *
     * @since 1.0.0
     */
    public function addLocalFieldGroupMenuItemsOptions() {
        acf_add_local_field_group( [
            'key'      => $this->group_key,
            'title'    => $this->field_group_title,
            'fields'   => [],
            'location' => [
                [
                    [
                        'param'    => 'nav_menu_item',
                        'operator' => '==',
                        'value'    => 'location/primary',
                    ]
                ],
            ],
            'position' => 'normal',
            'active'   => 1,
        ] );

        // get the fields for this group
        $fields = $this->addMenuItemsOptionsFields();

        // register our branding fields with the parent group
        $this->registerLocalFieldsToGroup( $fields, $this->group_key, false );
    }

    /**
     * Register fields into our Menu Item Options parent group
     *
     * @return array
     *
     * @since 1.0.0
     */
    private function addMenuItemsOptionsFields() {
        $fields = [
            [
                'key'           => 'field_59d2a067badfc',
                'label'         => __( 'Button Style', 'reach' ),
                'name'          => 'button_style',
                'type'          => 'select',
                'choices'       => [
                    'none'    => 'None',
                    'primary' => 'Primary',
                    'outline' => 'Outline',
                ],
                'default_value' => [
                    0 => 'none',
                ],
                'return_format' => 'value',
            ],
        ];

        return $fields;
    }
}