<?php
declare(strict_types=1);

namespace AuxCF\Entities\FieldGroup\Traits;

/**
 * Traits for FieldGroupEntity to create ACF registration array
 * @since 1.0.0
 */
trait FieldGroupArrayTraits
{
  /**
   * Common array properties for all field groups
   * @since 1.0.0
   */
  protected final function getBaseArray(): array
  {
    return [
      'key' => $this->getEffectiveKey(),
      'title' => $this->title,
      'fields' => $this->fieldsSet->getSetArray(),
      'location' => $this->locationsSet->getSetArray(),
      'menu_order' => $this->menuOrder,
      'position' => $this->position->value,
      'style' => $this->style->value,
      'label_placement' => $this->labelPlacement->value,
      'instruction_placement' => $this->instructionPlacement->value,
      'hide_on_screen' => $this->hideOnScreen ? $this->hideOnScreen : '',
      'active' => $this->active,
      'description' => $this->description,
      'show_in_rest' => $this->showInRest,
    ];
  }

  /**
   * Default additional array properties for field groups
   *
   * To provide or override additional array properties, override this method in the
   * inheriting class.
   *
   * @since 1.0.0
   */
  protected function getGroupArray(): array
  {
    return [];
  }

  /**
   * Get the complete ACF registration array, combining the base array with any
   * additional array properties specific to the field group
   *
   * @since 1.0.0
   * @see acf_register_field_group()
   */
  public final function getArray(): array
  {
    return array_replace_recursive($this->getBaseArray(), $this->getGroupArray());
  }
}
