local Z=script:FindFirstAncestor("\077\097\122\101\071\101\110\101\114\097\116\111\114\080\108\117\103\105\110")local I=require(Z:WaitForChild("\082\111\097\099\116"))local S=Z.Plugin local C=require(script.Parent.OptionEntry)local f=require(S.Shortcuts)local L=I.PureComponent:extend("\079\112\116\105\111\110\115\076\105\115\116")function L.init(Z)Z.state={selectedItemIndex=1}end function L.changeSelection(I,Z)I:setState(function(I,S)local C=I.selectedItemIndex+Z if C>#S.items then C=1 elseif C<1 then C=#S.items end return{selectedItemIndex=C}end)end function L.render(Z)local S=Z.props.entrySize local f={}f.Layout=I.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{Padding=UDim.new(0,1),SortOrder=Enum.SortOrder.LayoutOrder})for L,n in pairs(Z.props.items)do f[n]=I.createElement(C,{size=S;layoutOrder=L;text=n;isSelected=Z.state.selectedItemIndex==L})end return I.createElement("\070\114\097\109\101",{BackgroundTransparency=1,Size=Z.props.frameSize;LayoutOrder=Z.props.layoutOrder},f)end function L.didMount(Z)f.bind(f.SELECT_UP,function()Z:changeSelection(-1)end)f.bind(f.SELECT_DOWN,function()Z:changeSelection(1)end)end function L.willUnmount(Z)f.unbind(f.SELEC_UP)f.unbind(f.SELEC_DOWN)end return L
local Root = script:FindFirstAncestor('MazeGeneratorPlugin')
local Roact = require(Root:WaitForChild('Roact'))
local Plugin = Root.Plugin
local OptionEntry = require(script.Parent.OptionEntry)
local Shortcuts = require(Plugin.Shortcuts)

local OptionsList = Roact.PureComponent:extend('OptionsList')

function OptionsList:init()
	self.state = { selectedItemIndex = 1 } -- first item in the array
end

function OptionsList:changeSelection(increment)
	self:setState(function(prevState, props)
		local nextIndex = prevState.selectedItemIndex + increment

		if nextIndex > #props.items then
			nextIndex = 1
		elseif nextIndex < 1 then
			nextIndex = #props.items
		end

		return { selectedItemIndex = nextIndex }
	end)
end

function OptionsList:render()
	local entrySize = self.props.entrySize
	local children = {}

	children.Layout = Roact.createElement('UIListLayout', {
		Padding = UDim.new(0, 1),
		SortOrder = Enum.SortOrder.LayoutOrder,
	})

	for index, item in pairs(self.props.items) do
		children[item] = Roact.createElement(OptionEntry, {
			size = entrySize,
			layoutOrder = index,
			text = item,
			isSelected = self.state.selectedItemIndex == index,
		})
	end

	return Roact.createElement(
		'Frame',
		{
			BackgroundTransparency = 1,
			Size = self.props.frameSize,
			LayoutOrder = self.props.layoutOrder,
		},
		children
	)
end

function OptionsList:didMount()
	Shortcuts.bind(Shortcuts.SELECT_UP, function()
		self:changeSelection(-1)
	end)

	Shortcuts.bind(Shortcuts.SELECT_DOWN, function()
		self:changeSelection(1)
	end)
end

function OptionsList:willUnmount()
	Shortcuts.unbind(Shortcuts.SELEC_UP)
	Shortcuts.unbind(Shortcuts.SELEC_DOWN)
end

return OptionsList