<?php

namespace Reach\App\Fields\Groups;

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

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

    /**
     * FieldGroupContentArea constructor.
     *
     * @param $group_key
     * @param int $order
     */
    public function __construct( $group_key, $order = 0 ) {
        $this->group_key    = $group_key;
        $this->group_title  = __( 'Content Area', 'reach' ) . ' - ' . substr( $group_key, - 4 );
        $this->group_slug   = 'content-area-' . $this->group_key;
        $this->group_prefix = $this->group_key . '_content_area_';

        // 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_5923225383813',
                'label'     => __( 'Content', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'           => 'field_5923225383814',
                'label'         => __( 'Columns', 'reach' ),
                'name'          => $this->group_prefix . 'columns',
                'type'          => 'select',
                'choices'       => [
                    'single'      => __( 'Single Column', 'reach' ),
                    'two-column'  => __( 'Two Columns', 'reach' ),
                    'image-right' => __( 'Content/Image', 'reach' ),
                    'image-left'  => __( 'Image/Content', 'reach' ),
                ],
                'default_value' => [
                    0 => 'single',
                ]
            ],
            [
                'key'               => 'field_5923225383891',
                'label'             => __( 'Width', 'reach' ),
                'name'              => $this->group_prefix . 'width',
                'type'              => 'select',
                'choices'           => [
                    'small'  => __( 'Small', 'reach' ),
                    'medium' => __( 'Medium', 'reach' ),
                    'large'  => __( 'Large', 'reach' )
                ],
                'default_value'     => [
                    0 => 'medium',
                ],
                'conditional_logic' => [
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'single'
                        ]
                    ]
                ]
            ],
            [
                'key'          => 'field_0079736876206',
                'label'        => __( 'Content Lead', 'reach' ),
                'name'         => $this->group_prefix . 'content_lead',
                'type'         => 'wysiwyg',
                'instructions' => __( 'Optionally use this field to render full width content above any layout option.', 'reach' )
            ],
            [
                'key'   => 'field_5923228483815',
                'label' => __( 'Content', 'reach' ),
                'name'  => $this->group_prefix . 'content',
                'type'  => 'wysiwyg'
            ],
            [
                'key'               => 'field_9871214998600',
                'label'             => __( 'Content Two', 'reach' ),
                'name'              => $this->group_prefix . 'content_two',
                'type'              => 'wysiwyg',
                'conditional_logic' => [
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'two-column'
                        ]
                    ]
                ]
            ],
            [
                'key'               => 'field_5923229983816',
                'label'             => __( 'Image', 'reach' ),
                'name'              => $this->group_prefix . 'image',
                'type'              => 'image',
                'preview_size'      => 'medium',
                'conditional_logic' => [
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'image-left'
                        ]
                    ],
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'image-right'
                        ],
                    ]
                ]
            ],
            [
                'key'   => 'field_5923225383819',
                'label' => __( 'Button', 'reach' ),
                'name'  => $this->group_prefix . 'button',
                'type'  => 'smart_button'
            ],
            [
                'key'       => 'field_5923225383812',
                'label'     => __( 'Attributes', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'          => 'field_4554768684187',
                '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_5923225383899',
                'label'         => __( 'Text Align', 'reach' ),
                'name'          => $this->group_prefix . 'align',
                'type'          => 'select',
                'choices'       => [
                    'left'     => __( 'Left Align', 'reach' ),
                    'centered' => __( 'Centered', 'reach' ),
                    'right'    => __( 'Right Align', 'reach' ),
                ],
                'default_value' => [
                    0 => 'centered',
                ]
            ],
            [
                'key'               => 'field_5923225386557',
                'label'             => __( 'Image Sizing', 'reach' ),
                'description'       => __( 'This option controls the vertical alignment of your image.', 'reach' ),
                'name'              => $this->group_prefix . 'image_sizing',
                'type'              => 'select',
                'choices'           => [
                    'full-bleed' => __( 'Full Bleed', 'reach' ),
                    'stretch'    => __( 'Stretch', 'reach' ),
                    'top'        => __( 'Top', 'reach' ),
                    'center'     => __( 'Centered', 'reach' ),
                    'bottom'     => __( 'Bottom', 'reach' ),
                ],
                'default_value'     => [
                    0 => 'center',
                ],
                'conditional_logic' => [
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'image-left'
                        ]
                    ],
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'image-right'
                        ],
                    ]
                ]
            ],
            [
                'key'               => 'field_5923225381234',
                'label'             => __( 'Image Width', 'reach' ),
                'description'       => __( 'This option controls the width of your image.', 'reach' ),
                'name'              => $this->group_prefix . 'image_width',
                'type'              => 'select',
                'choices'           => [
                    'full-width'      => __( 'Full Width', 'reach' ),
                    'auto-width'      => __( 'Original Width (auto-width)', 'reach' ),
                ],
                'default_value'     => [
                    0 => 'full-width',
                ],
                'conditional_logic' => [
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'image-left'
                        ],
                        [
                            'field'    => $this->group_key . '_field_5923225386557',
                            'operator' => '!=',
                            'value'    => 'stretch'
                        ],
                        [
                            'field'    => $this->group_key . '_field_5923225386557',
                            'operator' => '!=',
                            'value'    => 'full-bleed'
                        ]
                    ],
                    [
                        [
                            'field'    => $this->group_key . '_field_5923225383814',
                            'operator' => '==',
                            'value'    => 'image-right'
                        ],
                        [
                            'field'    => $this->group_key . '_field_5923225386557',
                            'operator' => '!=',
                            'value'    => 'stretch'
                        ],
                        [
                            'field'    => $this->group_key . '_field_5923225386557',
                            'operator' => '!=',
                            'value'    => 'full-bleed'
                        ]
                    ],
                ]
            ],
            [
                'key'           => 'field_5923225383901',
                '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_5923225383902',
                '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_5923225383903',
                '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_5923225383818',
                'label'              => __( 'Background', 'reach' ),
                'name'               => $this->group_prefix . 'background',
                'type'               => 'background_attributes',
                'parallax'           => 1,
                'video'              => 1,
                'mobile'             => 1,
                'wrapper'            => [
                    'class' => ( ! current_user_can( 'administrator' ) ? ' acf-field--hidden' : '' )
                ],
                'image_description'  => __( 'Accepted image file formats: .png .jpg. Recommended minimum image dimensions 1440x500px. Width cropped at 1440px.', 'reach' ),
                'mobile_description' => __( 'Accepted image file formats: .png .jpg. Mobile recommended minimum dimensions 768x260px. Width cropped at 768px.', 'reach' ),
                'instructions'       => __( 'Set your background options below. Video playback is only visible if Background Size is set to `Parallax` and a fallback Background Image is set.', 'reach' )
            ],
            AnimationAttributes::registerFields( $this->group_prefix, self::animationDefaults() )
        ];

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