<?php

namespace common\components;

use yii\helpers\Html;

class PageSizer
{
    const DEFAULT_PAGE_SIZE = 25;
    public static array $pageSizeOptions = [25, 50, 75, 100];

    public function getForm(string $entity, string $labelEntity, int $pageSize, array $action = ['producer/pagesize'])
    {
        return '<form class="form-inline gridview-pagesize" method="post" action="'.\Yii::$app->urlManager->createUrl($action).'"><div class="form-group"><label class="control-label">'.$labelEntity.' par page : </label> '.
            Html::hiddenInput('entity', $entity).
            Html::dropDownList(
                'pagesize',
                $pageSize,
                $this->getPageSizeOptions(),
                array('class'=>'form-control')).'</div></form></div>';
    }

    public function getPageSizeOptions(): array
    {
        $pageSizeOptionsArray = [];

        foreach(self::$pageSizeOptions as $pageSize) {
            $pageSizeOptionsArray[$pageSize] = $pageSize;
        }

        return $pageSizeOptionsArray;
    }

    public function isPageSizeExist(int $pageSize): bool
    {
        return in_array($pageSize, self::$pageSizeOptions);
    }

}