<?php

namespace Reach\App\Fields\Groups;

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

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

    /**
     * FieldGroupStaff constructor.
     *
     * @param $group_key
     * @param int $order
     */
    public function __construct( $group_key, $order = 0 ) {
        $this->group_key    = $group_key;
        $this->group_title  = __( 'Staff', 'reach' ) . ' - ' . substr($group_key, -4);
        $this->group_slug   = 'staff-' . $this->group_key;
        $this->group_prefix = $this->group_key . '_staff_';

        // 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 array
     *
     * @since 1.0.0
     */
    public function getFields() {
        $fields = [
            [
                'key'       => 'field_qk79by4ws7s01',
                'label'     => __( 'Content', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'   => 'field_qk79by4ws7s02',
                'label' => __( 'Content', 'reach' ),
                'name'  => $this->group_prefix . 'content',
                'type'  => 'wysiwyg'
            ],
            [
                'key'          => 'field_qk79by4ws7s05',
                'label'        => __( 'Staff', 'reach' ),
                'name'         => $this->group_prefix . 'staff',
                'type'         => 'repeater',
                'layout'       => 'block',
                'required'     => 0,
                'collapsed'    => 'field_qk79by4ws7s06',
                'button_label' => __( 'Add Staff', 'reach' ),
                'sub_fields'   => [
                    [
                        'key'      => 'field_qk79by4ws7s06',
                        'label'    => __( 'Name', 'reach' ),
                        'name'     => 'name',
                        '_name'    => 'name',
                        'type'     => 'text',
                        'wrapper'  => [
                            'width' => '50%',
                            'class' => ''
                        ],
                        'required' => 0
                    ],
                    [
                        'key'      => 'field_qk79by4ws7s07',
                        'label'    => __( 'Title', 'reach' ),
                        'name'     => 'title',
                        '_name'    => 'title',
                        'type'     => 'text',
                        'wrapper'  => [
                            'width' => '50%',
                            'class' => ''
                        ],
                        'required' => 0
                    ],
                    [
                        'key'       => 'field_qk79by4ws7s09',
                        'label'     => __( 'Bio', 'reach' ),
                        'name'      => 'bio',
                        '_name'     => 'bio',
                        'type'      => 'textarea',
                        'rows'      => 6,
                        'wrapper'   => [
                            'width' => '',
                            'class' => ''
                        ],
                        'new_lines' => '',
                        'required'  => 0
                    ],
                    [
                        'key'           => 'field_qk79by4ws7s08',
                        'label'         => __( 'Image', 'reach' ),
                        'name'          => 'image',
                        '_name'         => 'image',
                        'type'          => 'image',
                        'return_format' => 'array',
                        'required'      => 0,
                        'instructions'  => __( 'Recommended minimum dimensions 480x480px. Width cropped at 480px. Accepted file formats: .png .jpg', 'reach' )
                    ],
                ]
            ],
            [
                'key'       => 'field_qk79by4ws7s03',
                'label'     => __( 'Attributes', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'      => 'field_1405271482676',
                '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_2254787382185',
                'label'   => __( 'Column Count', 'reach' ),
                'name'    => $this->group_prefix . 'column_count',
                'type'    => 'select',
                'wrapper' => [
                    'width' => '100',
                    'class' => ( ! current_user_can( 'administrator' ) ? ' acf-field--hidden' : '' )
                ],
                'choices' => [
                    '' => __( 'Theme Default', 'reach' ),
                    'two-columns'   => __( '2 Columns', 'reach' ),
                    'three-columns' => __( '3 Columns', 'reach' ),
                    'four-columns'  => __( '4 Columns', 'reach' ),
                    'five-columns'  => __( '5 Columns', 'reach' )
                ],
                'instructions'  => __( 'Maximum number of columns on desktop screen size.', 'reach' ),
                'default_value' => ''
            ],
            [
                'key'           => 'field_qk79by4ws7s091',
                'label'         => __( 'Padding', 'reach' ),
                'name'          => $this->group_prefix . 'enable_padding',
                'type'          => 'true_false',
                'wrapper'       => [
                    'width' => '20',
                    'class' => ( ! current_user_can( 'administrator' ) ? ' acf-field--hidden' : '' )
                ],
                'default_value' => 0,
                'ui'            => 1,
                'ui_on_text'    => __( 'On', 'reach' ),
                'ui_off_text'   => __( 'Off', 'reach' ),
            ],
            [
                'key'     => 'field_qk79by4ws7s092',
                'label'   => __( 'Padding Top', 'reach' ),
                'name'    => $this->group_prefix . 'padding_top',
                'type'    => 'range',
                'wrapper' => [
                    'width' => '40',
                    'class' => ( ! current_user_can( 'administrator' ) ? ' acf-field--hidden' : '' )
                ],
                'min'     => 0,
                'max'     => 300,
                'step'    => 5,
                'append'  => 'px',
            ],
            [
                'key'     => 'field_qk79by4ws7s093',
                'label'   => __( 'Padding Bottom', 'reach' ),
                'name'    => $this->group_prefix . 'padding_bottom',
                'type'    => 'range',
                'wrapper' => [
                    'width' => '40',
                    'class' => ( ! current_user_can( 'administrator' ) ? ' acf-field--hidden' : '' )
                ],
                'min'     => 0,
                'max'     => 300,
                'step'    => 5,
                'append'  => 'px',
            ],
            [
                'key'     => 'field_qk79by4ws7s04',
                '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/staff', $fields, $this->group_prefix );
    }
}
