<?php

namespace AcyMailing\Types;

use AcyMailing\Core\AcymObject;

class AclType extends AcymObject
{
    private array $groups;

    public function __construct()
    {
        parent::__construct();

        $this->groups = acym_getGroups();

        $allGroups = new \stdClass();
        $allGroups->value = 'all';
        $allGroups->text = acym_translation('ACYM_ALL');

        $seprator = new \stdClass();
        $seprator->value = '';
        $seprator->text = '-----------------------------';
        $seprator->disable = true;
        array_unshift($this->groups, $seprator);
        array_unshift($this->groups, $allGroups);
    }

    public function display(string $page): string
    {
        $name = 'acl_'.$page;

        $selected = explode(',', $this->config->get($name, ACYM_ADMIN_GROUP));

        return acym_selectMultiple($this->groups, 'config['.$name.']', $selected, ['class' => 'acym__select']);
    }
}
