<?php

/**
 * Gruppe aktivieren
 *
 * @param Int $gid - Gruppen-ID
 * @return Bool
 */

QUI::getAjax()->registerFunction(
    'ajax_groups_activate',
    static function ($gid): array {
        $gid = json_decode($gid, true);

        if (!is_array($gid)) {
            $gid = [$gid];
        }

        $Groups = QUI::getGroups();
        $result = [];

        foreach ($gid as $_gid) {
            try {
                $Group = $Groups->get($_gid);
                $Group->activate();

                $result[$_gid] = $Group->isActive() ? 1 : 0;
            } catch (QUI\Exception $Exception) {
                QUI::getMessagesHandler()->addError(
                    $Exception->getMessage()
                );

                continue;
            }
        }

        return $result;
    },
    ['gid'],
    'Permission::checkSU'
);
