PLUGIN.name = "Whitelist Menu"
PLUGIN.author = "Refosel"
PLUGIN.description = "Меню для выдачи фракции, подразделения, специализации и звания."

-- Регистрация CAMI-привилегии при загрузке
function PLUGIN:Load()
    CAMI.RegisterPrivilege({
        Name = "WhitelistMenu - Open",
        Description = "Может открывать меню назначения роли (фракция, подразделение, специализация, звание).",
        MinAccess = "user"
    })
end

PLUGIN.AllowedGroups = {
    ["superadmin"] = true,
    ["super admin"] = true,
    ["projectteam"] = true,
    ["teh.admin"] = true,
    ["curator"] = true,
    ["sudo-curator"] = true,
    ["asist-sudo"] = true,
    ["admin"] = true,
    ["st.admin"] = true,
    ["ivent"] = true,
    ["st.event"] = true,
    ["event"] = true,
    ["disp"] = true,
    ["assistant"] = true,
    ["specadmin"] = true,
    ["sponsor"] = true,
    ["prem"] = true,
    ["cmd"] = true,
    ["inst"] = true
}

function PLUGIN:HasAccess(client)
    local character = client:GetCharacter()
    if (character and (character:HasFlags("W") or character:HasFlags("w"))) then
        return true
    end

    local userGroup = string.lower(client:GetUserGroup() or "user")
    return self.AllowedGroups[userGroup] or client:IsAdmin() or client:IsSuperAdmin()
end

ix.util.Include("cl_plugin.lua")
ix.util.Include("sv_plugin.lua")

-- Команда без аргументов
ix.command.Add("wl", {
    description = "Открыть меню назначения роли",
    arguments = {},
    CanRun = function(self, client)
        return PLUGIN:HasAccess(client)
    end,
    OnRun = function(self, client)
        if not client:Alive() then
            return "@notAlive"
        end
        net.Start("ixWhitelistMenuOpen")
        net.Send(client)
    end
})
