// /AIWK_COMMON/group/aiwk_group.js
// AIWK EXT4 v003
(function () {
    "use strict";

    const AIWK = window.AIWK;
    const groups = {};

    AIWK.group = {
        registry: groups,
        create: function (id, cfg) {
            groups[id] = Object.assign({ id: id, wins: [] }, cfg || {});
            AIWK.events.emit("group:create", groups[id]);
            return groups[id];
        },
        addWin: function (groupId, winId) {
            if (!groups[groupId]) {
                AIWK.group.create(groupId, {});
            }
            if (groups[groupId].wins.indexOf(winId) < 0) {
                groups[groupId].wins.push(winId);
            }
            AIWK.events.emit("group:addWin", { groupId: groupId, winId: winId });
        }
    };
}());
