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={openScriptsExternally=false,twoWaySync=false}local C={}C.__index=C function C.fromPlugin(Z)local I={}for S,C in pairs(S)do local f=Z:GetSetting("\082\111\111\116\095"..S)if f==nil then Z:SetSetting("\082\111\111\116\095"..S,C)I[S]=C else I[S]=f end end return setmetatable({__values=I,__plugin=Z;__updateListeners={}},C)end function C.get(I,Z)if S[Z]==nil then error("\073\110\118\097\108\105\100 \115\101\116\105\110\103\115 \110\097\109\101 "..tostring(Z),2)end return I.__values[Z]end function C.set(S,Z,I)S.__plugin:SetSetting("\082\111\111\116\095"..Z,I)S.__values[Z]=I for S in pairs(S.__updateListeners)do S(Z,I)end end function C.onUpdate(I,Z)local S={}for Z in pairs(I.__updateListeners)do S[Z]=true end S[Z]=true I.__updateListeners=S return function()local S={}for I in pairs(I.__updateListeners)do if I~=Z then S[I]=true end end I.__updateListeners=S end end local f=I.createContext(nil)local L=I.Component:extend("\083\116\117\100\105\111\080\114\111\118\105\100\101\114")function L.init(Z)Z.settings=C.fromPlugin(Z.props.plugin)end function L.render(Z)return I.createElement(f.Provider,{value=Z.settings},Z.props[I.Children])end local n=I.Component:extend("\073\110\116\101\114\110\097\108\067\111\110\115\117\109\101\114")function n.render(Z)return Z.props.render(Z.props.settings)end function n.didMount(Z)Z.disconnect=Z.props.settings:onUpdate(function()Z:setState({})end)end function n.willUnmount(Z)Z.disconnect()end local function y(Z)return I.createElement(f.Consumer,{render=function(S)return I.createElement(n,{settings=S;render=Z})end})end return{StudioProvider=L;with=y}
--[[
	Persistent plugin settings that can be accessed via Roact context.
]]

local Root = script:FindFirstAncestor('MazeGeneratorPlugin')

local Roact = require(Root:WaitForChild('Roact'))

local defaultSettings = {
	openScriptsExternally = false,
	twoWaySync = false,
}

local Settings = {}
Settings.__index = Settings

function Settings.fromPlugin(plugin)
	local values = {}

	for name, defaultValue in pairs(defaultSettings) do
		local savedValue = plugin:GetSetting('Root_' .. name)

		if savedValue == nil then
			plugin:SetSetting('Root_' .. name, defaultValue)
			values[name] = defaultValue
		else
			values[name] = savedValue
		end
	end

	return setmetatable(
		{
			__values = values,
			__plugin = plugin,
			__updateListeners = {},
		},
		Settings
	)
end

function Settings:get(name)
	if defaultSettings[name] == nil then
		error('Invalid setings name ' .. tostring(name), 2)
	end

	return self.__values[name]
end

function Settings:set(name, value)
	self.__plugin:SetSetting('Root_' .. name, value)
	self.__values[name] = value

	for callback in pairs(self.__updateListeners) do
		callback(name, value)
	end
end

function Settings:onUpdate(newCallback)
	local newListeners = {}
	for callback in pairs(self.__updateListeners) do
		newListeners[callback] = true
	end

	newListeners[newCallback] = true
	self.__updateListeners = newListeners

	return function()
		local newListeners = {}
		for callback in pairs(self.__updateListeners) do
			if callback ~= newCallback then
				newListeners[callback] = true
			end
		end

		self.__updateListeners = newListeners
	end
end

local Context = Roact.createContext(nil)

local StudioProvider = Roact.Component:extend('StudioProvider')

function StudioProvider:init()
	self.settings = Settings.fromPlugin(self.props.plugin)
end

function StudioProvider:render()
	return Roact.createElement(
		Context.Provider,
		{ value = self.settings },
		self.props[Roact.Children]
	)
end

local InternalConsumer = Roact.Component:extend('InternalConsumer')

function InternalConsumer:render()
	return self.props.render(self.props.settings)
end

function InternalConsumer:didMount()
	self.disconnect = self.props.settings:onUpdate(function()
	-- Trigger a dummy state update to update the settings consumer.
		self:setState({})
	end)
end

function InternalConsumer:willUnmount()
	self.disconnect()
end

local function with(callback)
	return Roact.createElement(Context.Consumer, { render = function(settings)
		return Roact.createElement(InternalConsumer, {
			settings = settings,
			render = callback,
		})
	end })
end

return {
	StudioProvider = StudioProvider,
	with = with,
}