<?php

namespace Reach\App\Fields;

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

/**
 * Class MenuOptions
 *
 * addHooks()
 * addLocalFieldGroupMenuOptions()
 * addMenuOptionsFields()
 *
 * @package Reach\App\Fields\Groups
 */
class MenuOptions extends AbstractFieldGroup implements WordPressHooks {

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

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

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

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

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

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

    /**
     * Register fields into our Menu Options parent group
     *
     * @return array
     *
     * @since 1.0.0
     */
    private function addMenuOptionsFields() {
        $fields = [
            [
                'key'           => 'field_59bae7a5bec93',
                'label'         => __( 'Text Align', 'reach' ),
                'name'          => 'text_align',
                'type'          => 'select',
                'choices'       => [
                    'left'   => __( 'Left', 'reach' ),
                    'center' => __( 'Center', 'reach' ),
                    'right'  => __( 'Right', 'reach' ),
                ],
                'return_format' => 'value',
            ],
            [
                'key'           => 'field_59bae7d9e0d20',
                'label'         => __( 'Position', 'reach' ),
                'name'          => 'position',
                'type'          => 'select',
                'choices'       => [
                    'left'   => __( 'Left', 'reach' ),
                    'center' => __( 'Center', 'reach' ),
                    'right'  => __( 'Right', 'reach' ),
                ],
                'return_format' => 'value'
            ],
            [
                'key'           => 'field_59bae841bda68',
                'label'         => __( 'Sub-Menu Width', 'reach' ),
                'name'          => 'sub-menu_width',
                'type'          => 'range',
                'default_value' => 175,
                'min'           => 100,
                'max'           => 450,
                'step'          => 5,
                'append'        => 'px',
            ],
            [
                'key'           => 'field_59bae841bda69',
                'label'         => __( 'Text Highlight Color', 'reach' ),
                'name'          => 'menu_text_highlight_color',
                'type'          => 'color_picker',
                'default_value' => '#252525',
            ],
            [
                'key'           => 'field_59bae841bda65',
                'label'         => __( 'Sub-Menu Text Color', 'reach' ),
                'name'          => 'sub-menu_text_color',
                'type'          => 'color_picker',
                'default_value' => '#252525',
            ],
            [
                'key'           => 'field_59bae82abda64',
                'label'         => __( 'Sub-Menu Background Color', 'reach' ),
                'name'          => 'sub-menu_background_color',
                'type'          => 'color_picker',
                'default_value' => '#FFFFFF',
            ],
            [
                'key'           => 'field_59bbfbf7c4f3d',
                'label'         => __( 'Sub-Menu Border Color', 'reach' ),
                'name'          => 'sub-menu_border_color',
                'type'          => 'color_picker',
                'default_value' => '#E4E4E4',
            ]
        ];

        return $fields;
    }
}