<?php

namespace Reach\App\Fields\Groups;

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

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

    /**
     * FieldGroupFaqs constructor.
     *
     * @param $group_key
     * @param int $order
     */
    public function __construct( $group_key, $order = 0 ) {
        $this->group_key    = $group_key;
        $this->group_title  = __( 'FAQs', 'reach' )  . ' - ' . substr($group_key, -4);
        $this->group_slug   = 'faqs-' . $this->group_key;
        $this->group_prefix = $this->group_key . '_faqs_';

        // 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_7502316435156',
                'label'     => __( 'Content', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'   => 'field_7502316435157',
                'label' => __( 'Content', 'reach' ),
                'name'  => $this->group_prefix . 'content',
                'type'  => 'wysiwyg'
            ],
            [
                'key'           => 'field_7502316435150',
                'label'         => __( 'Featured FAQs', 'reach' ),
                'name'          => $this->group_prefix . 'faqs',
                'type'          => 'post_object',
                'post_type'     => 'faqs',
                'multiple'      => 1,
                'return_format' => 'object'
            ],
            [
                'key'   => 'field_7502316435176',
                'label' => __( 'Button', 'reach' ),
                'name'  => $this->group_prefix . 'button',
                'type'  => 'smart_button'
            ],
            [
                'key'       => 'field_7502316435162',
                'label'     => __( 'Attributes', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'      => 'field_4258385486075',
                '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_7502316435163',
                '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' )
            ],
            [
                'key'               => 'field_7204786969285',
                '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',
                ],
                'instructions'  => __( 'FAQs will render in the number of colums indicated below on wider screens', 'reach' )
            ],
            [
              'key'           => 'field_6760848292315',
              'label'         => __( 'Center Single Column', 'reach' ),
              'name'          => $this->group_prefix . 'center_single_column',
              'type'          => 'true_false',
              'wrapper'       => [
                  'width' => '100'
              ],
              'default_value'     => 0,
              'ui'                => 1,
              'ui_on_text'        => __( 'On', 'reach' ),
              'ui_off_text'       => __( 'Off', 'reach' ),
              'conditional_logic' => [
                  [
                      [
                          'field'    => $this->group_key . '_field_7204786969285',
                          'operator' => '==',
                          'value'    => '1'
                      ]
                  ]
              ]
            ],
            [
                'key'     => 'field_8591648772922',
                'label'   => __( 'Button Alignment', 'reach' ),
                'name'    => $this->group_prefix . 'button_alignment',
                'type'    => 'select',
                'choices' => Modules::getButtonAlignmentOptions( $this->group_prefix ),
                'required'      => 0,
                'return_format' => 'value',
                'default_value' => [
                    0 => ''
                ]
            ],
            [
                'key'               => 'field_3096067336495',
                'label'             => __( 'Headline Size', 'reach' ),
                'name'              => $this->group_prefix . 'headline_size',
                'type'              => 'select',
                'choices'           => [
                    'default' => __( 'Default', 'reach' ),
                    'medium'  => __( 'Medium', 'reach' ),
                    'small'   => __( 'Small', 'reach' ),
                ],
                'default_value'     => [
                    0 => '2',
                ],
                'instructions'  => __( 'Determines the size of h3 FAQ headlines', 'reach' )
            ],
            AnimationAttributes::registerFields( $this->group_prefix, self::animationDefaults() )
        ];

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