<?php

namespace Reach\App\Fields\Groups;

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

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

    /**
     * FieldGroupImageContainer constructor.
     *
     * @param $group_key
     * @param int $order
     */
    public function __construct( $group_key, $order = 0 ) {
        $this->group_key    = $group_key;
        $this->group_title  = __( 'Image Container', 'reach' ) . ' - ' . substr($group_key, -4);
        $this->group_slug   = 'image-' . $this->group_key;
        $this->group_prefix = $this->group_key . '_image_';

        // 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_591c98c174726',
                'label'     => __( 'Content', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'          => 'field_591c98c174727',
                'label'        => __( 'Image', 'reach' ),
                'name'         => $this->group_prefix . 'image',
                'type'         => 'image',
                'preview_size' => 'full',
                'instructions'  => __( 'Recommended minimum image dimensions 1440x500px. Width cropped at 1440px. Accepted file formats: .png .jpg', 'reach' )
            ],
            [
                'key'       => 'field_591c98c174728',
                'label'     => __( 'Attributes', 'reach' ),
                'type'      => 'tab',
                'placement' => 'left'
            ],
            [
                'key'      => 'field_9861894755816',
                '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_591c98c1747171',
                '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_591c98c1747172',
                '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_591c98c1747173',
                '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_591c98c1747174',
                '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/image-container', $fields );
    }
}
