<?php

namespace Reach\App\Fields\Groups;

use Reach\App\Fields\Abstracts\AbstractFieldGroup;
use Reach\App\Fields\Types\AnimationAttributes;

/**
 * Class FieldGroupMenu
 *
 * addHooks()
 * getFields()
 *
 * @package Reach\App\Fields\Groups
 */
class FieldGroupMenu extends AbstractFieldGroup {

    /**
     * FieldGroupMenu constructor.
     *
     * @param $group_key
     * @param int $order
     */
    public function __construct( $group_key, $order = 0 ) {
        $this->group_key    = $group_key;
        $this->group_title  = __( 'Menu', 'reach' ) . ' - ' . substr($group_key, -4);
        $this->group_slug   = 'menu-' . $this->group_key;
        $this->group_prefix = $this->group_key . '_menu_';

        // register our parent group for this module
        $this->addLocalFieldGroupToPage( $this->group_key, $this->group_title, $this->group_slug, $order );
    }

    /**
     * Get animation defaults
     *
     * @return array
     *
     * @since 1.0.0
     */
    public static function animationDefaults() {
        return [
            'type'  => 'fade',
            'speed' => '1200'
        ];
    }

    /**
     * Register fields into our parent group
     *
     * @return mixed
     */
    public function getFields() {
        $fields = [
            [
                'key'       => 'field_2628132392',
                'label'     => __( 'Content', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'   => 'field_2628132395',
                'label' => __( 'Content', 'reach' ),
                'name'  => $this->group_prefix . 'content',
                'type'  => 'wysiwyg'
            ],
            [
                'key'           => 'field_2628132341',
                'label'         => __( 'Number of Columns', 'reach' ),
                'name'          => $this->group_prefix . 'columns_count',
                'type'          => 'select',
                'choices'       => [
                    '1' => __( '1 Column', 'reach' ),
                    '2' => __( '2 Columns', 'reach' ),
                ],
                'default_value' => [
                    0 => '2',
                ]
            ],
            [
                'key'          => 'field_6011856146',
                'label'        => __( 'Menu Sections', 'reach' ),
                'name'         => $this->group_prefix . 'menu_sections',
                'type'         => 'repeater',
                'layout'       => 'block',
                'required'     => 0,
                'collapsed'    => 'field_8627734910',
                'button_label' => __( 'Add Menu Section', 'reach' ),
                'sub_fields'   => [
                    [
                        'key'      => 'field_8627734910',
                        'label'    => __( 'Menu Section Title', 'reach' ),
                        'name'     => 'title',
                        '_name'    => 'title',
                        'type'     => 'text',
                        'wrapper'  => [
                            'width' => '',
                            'class' => ''
                        ],
                        'required' => 0
                    ],
                    [
                        'key'      => 'field_8627734915',
                        'label'    => __( 'Menu Section Content', 'reach' ),
                        'name'     => 'content',
                        '_name'    => 'content',
                        'type'     => 'wysiwyg',
                        'wrapper'  => [
                            'width' => '',
                            'class' => ''
                        ],
                        'required' => 0
                    ]
                ]
            ],
            [
                'key'   => 'field_2628132345',
                'label' => __( 'Button', 'reach' ),
                'name'  => $this->group_prefix . 'button',
                'type'  => 'smart_button'
            ],
            [
                'key'       => 'field_2628132347',
                'label'     => __( 'Attributes', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'      => 'field_0372141699621',
                'label'    => __( 'CSS Classes', 'reach' ),
                'name'     => $this->group_prefix . 'css_classes',
                'type'     => 'text',
                'wrapper'  => [
                    'width' => '100%',
                    'class' => ''
                ],
                'instructions'  => __( 'CSS classes entered here will be prefixed with &#34;rl-&#34; to avoid conflicts and added to this module’s wrapping element. ', 'reach' )
            ],
            [
                'key'     => 'field_2628132350',
                'label'   => __( 'Background', 'reach' ),
                'name'    => $this->group_prefix . 'background',
                'type'    => 'background_attributes',
                'wrapper' => [
                    'class' => ( ! current_user_can( 'administrator' ) ? ' acf-field--hidden' : '' )
                ],
                'instructions'  => __( 'Recommended minimum image dimensions 1440x500px. Width cropped at 1440px. Accepted file formats: .png .jpg', 'reach' )
            ],
            AnimationAttributes::registerFields( $this->group_prefix, self::animationDefaults() )
        ];

        return apply_filters( 'reach/fields/group/menu', $fields, $this->group_prefix );
    }
}
