<?php
// Admins
use Database\Users;
use inc\fileStorage;
if ($text == patternAdmin('admins')) {
    $Telegram->sendMessage($chatid, msg('def'), 'html', false, $button_admins);
} //Add Admin
elseif ($text == patternAdmin('add_admin')) {
    Users::updateCommand($chatid, 'addAdmin');
    $Telegram->sendMessage($chatid, msg('sendud'), 'html', false, $button_backhome);
} elseif ($command == 'addAdmin' && $text != patternAdmin('back')) {
    if (Users::check($text) == false) {
        $Telegram->sendMessage($chatid, msg('NotFoundUser'), 'html', false, $button_backhome);
        die();
    }
    Users::updateRank($text, 'admin');
    Users::updateCommand($chatid, null);
    fileStorage::removeFile('bot');
    $Telegram->sendMessage($chatid, msg('doneadmin'), 'html', false, $button_admins);
} elseif ($text == patternAdmin('listAdmin')) {
    $list = getStore('adminChatid');
    $btn = [];
    $btn[] = [["text" => msg('item'), "callback_data" => "none"]];
    foreach ($list as $user) {
        $name = $Telegram->getChat($user['chatid'])->getResult()->getFirstName();

        $btn[] = [["text" => $name, "callback_data" => "removeAdmin_" . $user['chatid']]];
    }
    $Telegram->SendMessage($chatid, msg('txtListAdmins'), 'html', false, [
        'inline_keyboard' =>
            $btn
        ,
        'resize_keyboard' => true
    ]);
} elseif (preg_match('/^([Rr]emoveAdmin_)(.*)/', $data)) {
    $dta = str_replace(['removeAdmin_'], '', $data);
    $btn = [["text" => msg('yes'), "callback_data" => "yesRemoveAdmin_{$dta}"], ["text" => msg('no'), "callback_data" => "noRemoveAdmin_{$dta}"]];
    $Telegram->editMessageText($chatid, $MessageID, str_replace('#ch', $Telegram->getChat($dta)->getResult()->getFirstName(), msg('realyDeleteAdmin')), 'html', '', true, [
        'inline_keyboard' =>
            [$btn]
        ,
        'resize_keyboard' => true
    ]);
} elseif (preg_match('/^([Nn]oRemoveAdmin_)(.*)/', $data)) {
    $Telegram->editMessageText($chatid, $MessageID, msg('done'), 'html', '', true);
} elseif (preg_match('/^([Yy]esRemoveAdmin_)(.*)/', $data)) {
    $dta = str_replace(['yesRemoveAdmin_'], '', $data);
    Users::updateRank($dta, 'user');
    fileStorage::removeFile('bot');
    $Telegram->editMessageText($chatid, $MessageID, msg('done'), 'html', '', true);
}
