local n=script:FindFirstAncestor("\077\097\122\101\071\101\110\101\114\097\116\111\114\080\108\117\103\105\110")local Z=require(n:WaitForChild("\082\111\097\099\116"))local w=n.Plugin local i=require(n.Rodux)local X=require(n.RoactRodux)local G=require(n.Log)local K=require(w.DevSettings)local V=require(w.Components.App)local F=require(w.Reducer)local y=require(w.Components.Theme)local J=require(w.Assets)local v=require(w.Version)local m=require(w.Config)local s=require(w.Components.PluginSettings)local e=Z.createElement local function g(n,w)local g="\077\097\122\101\071\101\110\101\114\097\116\111\114"local f="\077\097\122\101 \071\101\110\101\114\097\116\111\114"local t="\083\104\111\119 \111\114 \104\105\100\101 \116\104\101 \077\097\122\101 \071\101\110\101\114\097\116\111\114 \112\097\110\101\108"local T=v.display(m.version)if m.isDevBuild then T=T.."-\108\111\099\097\108"g=g..T f=f.." \040\076\079\067\065\076\041"end local h=n:toolbar("\077\097\122\101 \071\101\110\101\114\097\116\111\114 "..T)local Y=DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Right,false,false,360,190,360,190)local S=n:createDockWidgetPluginGui(g,Y)S.Name=f..(" "..T)S.Title=f..(""..T)S.AutoLocalize=false S.ZIndexBehavior=Enum.ZIndexBehavior.Sibling local W=n:button(h,f,t,J.Images.Icon)W.ClickableWhenViewportHidden=true W.Click:Connect(function()S.Enabled=not S.Enabled end)local a=(S:GetPropertyChangedSignal("\069\110\097\098\108\101\100")):Connect(function()W:SetActive(S.Enabled)end)local l l=S.AncestryChanged:Connect(function()print("\078\101\119 \077\097\122\101\071\101\110\101\114\097\116\111\114 \118\101\114\115\105\111\110 \099\111\109\105\110\103 \111\110\108\105\110\101\059 \117\110\108\111\097\100\105\110\103 \116\104\101 \111\108\100 \118\101\114\115\105\111\110")l:Disconnect()n:unload()end)G.setLogLevelThunk(function()return K:getLogLevel()end)local I=i.Store.new(F,w)local O=e(y.StudioProvider,nil,{e(s.StudioProvider,{plugin=n},{RootUI=e(V,{root=S})})})local E=Z.createElement(X.StoreProvider,{store=I},{app=O})local b=Z.mount(E,S,"\065\080\080-\085\073")n:beforeUnload(function()Z.unmount(b)a:Disconnect()return I:getState()end)end return g
local Root = script:FindFirstAncestor('MazeGeneratorPlugin')
local Roact = require(Root:WaitForChild('Roact'))
local Plugin = Root.Plugin
local Rodux = require(Root.Rodux)
local RoactRodux = require(Root.RoactRodux)
local Log = require(Root.Log)

local DevSettings = require(Plugin.DevSettings)

local App = require(Plugin.Components.App)
local Reducer = require(Plugin.Reducer)
local Theme = require(Plugin.Components.Theme)
local Assets = require(Plugin.Assets)

local Version = require(Plugin.Version)
local Config = require(Plugin.Config)
local PluginSettings = require(Plugin.Components.PluginSettings)

local e = Roact.createElement
local function Main(pluginFacade, savedState)
	local WIDGET_ID = 'MazeGenerator'
	local PLUGIN_TITLE = 'Maze Generator'
	local PLUGIN_DESC = 'Show or hide the Maze Generator panel'

	-- PLUGIN CONFIGURATION
	local displayedVersion = Version.display(Config.version)

	if Config.isDevBuild then
		displayedVersion = displayedVersion .. '-local'
		WIDGET_ID = WIDGET_ID .. displayedVersion
		PLUGIN_TITLE = PLUGIN_TITLE .. ' (LOCAL)'
	end

	local toolbar = pluginFacade:toolbar('Maze Generator ' .. displayedVersion)

	local widgetInfo = DockWidgetPluginGuiInfo.new(
		-- Minimum size
		Enum.InitialDockState.Right,
		false, -- Initially enabled state
		false, -- Whether to override the widget's previous state
		360,
		190, -- Floating size
		360,
		190
	)

	local dockWidget = pluginFacade:createDockWidgetPluginGui(WIDGET_ID, widgetInfo)
	dockWidget.Name = PLUGIN_TITLE .. ' ' .. displayedVersion
	dockWidget.Title = PLUGIN_TITLE .. '' .. displayedVersion
	dockWidget.AutoLocalize = false
	dockWidget.ZIndexBehavior = Enum.ZIndexBehavior.Sibling

	local toggleButton = pluginFacade:button(toolbar, PLUGIN_TITLE, PLUGIN_DESC, Assets.Images.Icon)
	toggleButton.ClickableWhenViewportHidden = true
	toggleButton.Click:Connect(function()
		dockWidget.Enabled = not dockWidget.Enabled
	end)

	local dockWidgetEnabled = dockWidget:GetPropertyChangedSignal('Enabled'):Connect(function()
		toggleButton:SetActive(dockWidget.Enabled)
	end)

	local unloadConnection
	unloadConnection = dockWidget.AncestryChanged:Connect(function()
		print('New MazeGenerator version coming online; unloading the old version')
		unloadConnection:Disconnect()
		pluginFacade:unload()
	end)

	Log.setLogLevelThunk(function()
		return DevSettings:getLogLevel()
	end)
	--- APP UI
	local store = Rodux.Store.new(Reducer, savedState)
	local app =
		e(Theme.StudioProvider, nil, {
			e(
				PluginSettings.StudioProvider,
				{ plugin = pluginFacade },
				{ RootUI = e(App, { root = dockWidget }) }
			),
		})
	local element = Roact.createElement(RoactRodux.StoreProvider, { store = store }, { app = app })

	local instance = Roact.mount(element, dockWidget, 'APP-UI')

	pluginFacade:beforeUnload(function()
		Roact.unmount(instance)
		dockWidgetEnabled:Disconnect()
		return store:getState()
	end)
end

return Main