local z=game:GetService("\072\116\116\112\083\101\114\118\105\099\101")local A=(script:FindFirstAncestor("\067\109\100\114\065\100\100\105\116\105\111\110\115")).Packages local Y=require(A.Roact)local m=Y.Component:extend("\069\118\101\110\116\067\111\110\116\114\111\108\108\101\114")function m.init(z)z.props.Cmdr:HandleEvent(z.props.ListenTo,function(A)z:pushEvent(A)end)end function m.pushEvent(Y,A)Y:setState(function(m)local W={}table.insert(W,1,{Id=z:GenerateGUID(false),Active=true,Data=A})for z,A in pairs(m)do table.insert(W,{Id=A.Id;Active=z+1<=Y.props.MaxQuantity;Data=A.Data})end return W end)end function m.render(z)local A={}for m,W in ipairs(z.state)do A[W.Id]=Y.createElement(z.props.Component,{Index=m,Active=W.Active;Data=W.Data;Destroy=function()z:setState(function(z)table.remove(z,m)return z end)end})end return Y.createFragment(A)end return m
local HttpService = game:GetService("HttpService")

local Packages = script:FindFirstAncestor("CmdrAdditions").Packages
local Roact = require(Packages.Roact)

local EventController = Roact.Component:extend("EventController")

function EventController:init()
	self.props.Cmdr:HandleEvent(self.props.ListenTo, function(data)
		self:pushEvent(data)
	end)
end

function EventController:pushEvent(data)
	self:setState(function(state)
		local newState = {}

		table.insert(newState, 1, {
			Id = HttpService:GenerateGUID(false),
			Active = true,
			Data = data
		})

		for index, event in pairs(state) do
			table.insert(newState, {
				Id = event.Id,
				Active = (index + 1) <= self.props.MaxQuantity,
				Data = event.Data
			})
		end

		return newState
	end)
end

function EventController:render()
	local events = {}

	for index, event in ipairs(self.state) do
		events[event.Id] = Roact.createElement(self.props.Component, {
			Index = index,
			Active = event.Active,
			Data = event.Data,
			Destroy = function()
				self:setState(function(state)
					-- TODO: get current index from id
					table.remove(state, index)
					return state
				end)
			end
		})
	end

	return Roact.createFragment(events)
end

return EventController