<?php

namespace Reach\App\Fields;

use Reach\App\Interfaces\WordPressHooks;
use Reach\App\Fields\Abstracts\AbstractFieldGroup;

/**
 * Class CtaOptions
 *
 * addHooks()
 * addLocalFieldGroupCtaOptions()
 * addCtaOptionsFields()
 *
 * @package Reach\App\Fields\Groups
 */
class CtaOptions extends AbstractFieldGroup implements WordPressHooks {

    /**
     * Field group title
     *
     * @var
     */
    public $field_group_title;

    /**
     * ImageContainer constructor.
     */
    public function __construct() {
        $this->group_key         = 'group_4502405812590';
        $this->field_group_title = __( 'CTA Options', 'reach' );
    }

    /**
     * Add class hooks.
     */
    public function addHooks() {
        add_action( 'acf/init', [ $this, 'addLocalFieldGroupCtaOptions' ] );
    }

    /**
     * Add a local field group containing site options to the Site Options location
     *
     * @since 1.0.0
     */
    public function addLocalFieldGroupCtaOptions() {

      acf_add_local_field_group([
        'key'      => $this->group_key ,
        'title'    => $this->field_group_title,
        'fields'   => $this->addCtaOptionsFields(),
        'location' => [
            [
                [
                    'param'     => 'post_type',
                    'operator'  => '==',
                    'value'     => 'ctas',
                ],
                [
                    'param'     => 'page_type',
                    'operator'  => '!=',
                    'value'     => 'front_page',
                ]
            ],
        ],
        'menu_order'            => 0,
        'position'              => 'normal',
        'style'                 => 'default',
        'label_placement'       => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen'        => '',
        'active'                => 1,
        'description'           => '',
      ]);



    }

    /**
     * Register Branding Tab fields into our Site Options parent group
     *
     * @return array
     *
     * @since 1.0.0
     */
    private function addCtaOptionsFields() {
      $fields = [
          [
              'key'       => 'field_5075110064143',
              'label'     => __( 'Content', 'reach' ),
              'type'      => 'tab',
              'placement' => 'left'
          ],
          [
              'key'           => 'field_6757303362350',
              'label'         => __( 'Columns', 'reach' ),
              'name'          => '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_5075110064145',
              'label'             => __( 'Width', 'reach' ),
              'name'              => 'width',
              'type'              => 'select',
              'choices'           => [
                  'small'  => __( 'Small', 'reach' ),
                  'medium' => __( 'Medium', 'reach' ),
                  'large'  => __( 'Large', 'reach' )
              ],
              'default_value'     => [
                  0 => 'medium',
              ],
              'conditional_logic' => [
                  [
                      [
                          'field'    => 'field_6757303362350',
                          'operator' => '==',
                          'value'    => 'single'
                      ]
                  ]
              ]
          ],
          [
              'key'   => 'field_8909410827313',
              'label' => __( 'Content', 'reach' ),
              'name'  => 'content',
              'type'  => 'wysiwyg'
          ],
          [
              'key'               => 'field_9871214998600',
              'label'             => __( 'Content Two', 'reach' ),
              'name'              => 'content_two',
              'type'              => 'wysiwyg',
              'conditional_logic' => [
                  [
                      [
                          'field'    => 'field_6757303362350',
                          'operator' => '==',
                          'value'    => 'two-column'
                      ]
                  ]
              ]
          ],
          [
              'key'               => 'field_8909410827315',
              'label'             => __( 'Image', 'reach' ),
              'name'              => 'image',
              'type'              => 'image',
              'preview_size'      => 'medium',
              'conditional_logic' => [
                  [
                      [
                          'field'    => 'field_6757303362350',
                          'operator' => '==',
                          'value'    => 'image-left'
                      ]
                  ],
                  [
                      [
                          'field'    => 'field_6757303362350',
                          'operator' => '==',
                          'value'    => 'image-right'
                      ],
                  ]
              ]
          ],
          [
              'key'   => 'field_4313867179721',
              'label' => __( 'Button', 'reach' ),
              'name'  => 'button',
              'type'  => 'smart_button'
          ],
          [
              'key'       => 'field_4313867179725',
              'label'     => __( 'Attributes', 'reach' ),
              'type'      => 'tab',
              'placement' => 'left'
          ],
          [
              'key'      => 'field_4313867179728',
              'label'    => __( 'CSS Classes', 'reach' ),
              'name'     => '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_5281797724312',
              'label'         => __( 'Text Align', 'reach' ),
              'name'          => 'align',
              'type'          => 'select',
              'choices'       => [
                  'left'     => __( 'Left Align', 'reach' ),
                  'centered' => __( 'Centered', 'reach' ),
                  'right'    => __( 'Right Align', 'reach' ),
              ],
              'default_value' => [
                  0 => 'centered',
              ]
          ],
          [
              'key'               => 'field_5281797724315',
              'label'             => __( 'Image Sizing', 'reach' ),
              'description'       => __( 'This option controls the vertical alignment of your image.', 'reach' ),
              'name'              => 'image_sizing',
              'type'              => 'select',
              'choices'           => [
                  'stretch' => __( 'Stretch', 'reach' ),
                  'top'     => __( 'Top', 'reach' ),
                  'center'  => __( 'Centered', 'reach' ),
                  'bottom'  => __( 'Bottom', 'reach' ),
              ],
              'default_value'     => [
                  0 => 'center',
              ],
              'conditional_logic' => [
                  [
                      [
                          'field'    => 'field_6757303362350',
                          'operator' => '==',
                          'value'    => 'image-left'
                      ]
                  ],
                  [
                      [
                          'field'    => 'field_6757303362350',
                          'operator' => '==',
                          'value'    => 'image-right'
                      ],
                  ]
              ]
          ],
          [
              'key'           => 'field_5605460994520',
              'label'         => __( 'Padding', 'reach' ),
              'name'          => '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_5605460994525',
              'label'   => __( 'Padding Top', 'reach' ),
              'name'    => '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_5605460994528',
              'label'   => __( 'Padding Bottom', 'reach' ),
              'name'    => '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_5605460994530',
              'label'   => __( 'Background', 'reach' ),
              'name'    => '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' )
          ],
      ];

        return $fields;
    }
}
