<?php

namespace Reach\App\Fields;

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

/**
 * Class PageOptions
 *
 * addHooks()
 * addLocalFieldGroupPageOptions()
 * addPageOptionsFields()
 *
 * @package Reach\App\Fields\Groups
 */
class PageOptions extends AbstractFieldGroup implements WordPressHooks {

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

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

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

    /**
     * Add a local field group containing site options to the Site Options location
     *
     * @since 1.0.0
     */
    public function addLocalFieldGroupPageOptions() {
        acf_add_local_field_group( [
            'key'      => $this->group_key,
            'title'    => $this->field_group_title,
            'fields'   => [],
            'location' => [
                [
                    [
                        'param'    => 'post_type',
                        'operator' => '==',
                        'value'    => 'page',
                    ],
                    [

                        'param'    => 'page_type',
                        'operator' => '!=',
                        'value'    => 'front_page',
                    ]
                ],
            ],
            'position' => 'side',
            'active'   => 1,
        ] );

        // get the fields for this group
        $fields = $this->addPageOptionsFields();

        // register our branding fields with the parent group
        $this->registerLocalFieldsToGroup( $fields, $this->group_key, false );
    }

    /**
     * Register Branding Tab fields into our Site Options parent group
     *
     * @return array
     *
     * @since 1.0.0
     */
    private function addPageOptionsFields() {
        $fields = [
            [
                'key'   => 'field_5976417756400',
                'label' => __( 'Sub-heading', 'reach' ),
                'name'  => 'subheading',
                'type'  => 'textarea'
            ]
        ];

        return $fields;
    }
}
