<?php
declare(strict_types=1);

namespace AuxCF\Entities\Field;

use AuxCF\Entities\Field\Enum\FieldTypeEnum;
use AuxCF\Entities\Field\Enum\TextareaNewLinesEnum;
use AuxCF\Entities\Field\Traits\PlaceholderTraits;
use AuxCF\Entities\Field\Traits\ReadonlyDisabledTraits;
use AuxCF\Entities\FieldEntity;

class TextareaFieldEntity extends FieldEntity
{
  use PlaceholderTraits, ReadonlyDisabledTraits;

  protected static array $arrayPropertiesMethods = [
    'getPlaceholderArray',
    'getReadonlyDisabledArray',
  ];

  protected FieldTypeEnum $type = FieldTypeEnum::Textarea;

  protected ?int $maxLength = null;
  protected ?int $rows = null;
  protected TextareaNewLinesEnum $newLines = TextareaNewLinesEnum::DEFAULT;

  public function getFieldArray(): array
  {
    $array = [
      'new_lines' => $this->newLines->value,
      'rows' => is_null($this->rows) ? '' : $this->rows,
      'maxlength' => is_null($this->maxLength) ? '' : $this->maxLength,
    ];

    return $array;
  }
}
