"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const msg_1 = __importDefault(require("../../models/msg"));
const msg_2 = require("../../../shared/types/msg");
const chan_1 = require("../../../shared/types/chan");
exports.default = (function (irc, network) {
    const client = this;
    irc.on("kick", function (data) {
        const chan = network.getChannel(data.channel);
        if (typeof chan === "undefined") {
            return;
        }
        const user = chan.getUser(data.kicked);
        const msg = new msg_1.default({
            type: msg_2.MessageType.KICK,
            time: data.time,
            from: chan.getUser(data.nick),
            target: user,
            text: data.message || "",
            highlight: data.kicked === irc.user.nick,
            self: data.nick === irc.user.nick,
        });
        chan.pushMessage(client, msg);
        if (data.kicked === irc.user.nick) {
            chan.users = new Map();
            chan.state = chan_1.ChanState.PARTED;
            client.emit("channel:state", {
                chan: chan.id,
                state: chan.state,
            });
        }
        else {
            chan.removeUser(user);
        }
    });
});
