local O=string.split or function(O,z)if type(O)~="\115\116\114\105\110\103"then error("\069\120\112\101\099\116\101\100 \115\116\114\105\110\103 \103\111\116 "..typeof(O))end local b={}local i=1 local X,y=string.find(O,z,i)while X do table.insert(b,string.sub(O,i,X-1))i=y+1 X,y=string.find(O,z,i)end table.insert(b,string.sub(O,i))return b end local z=game:GetService("\082\117\110\083\101\114\118\105\099\101")local b=z:IsServer()local i=game:GetService("\083\101\114\118\101\114\083\099\114\105\112\116\083\101\114\118\105\099\101")local X=game:GetService("\083\101\114\118\101\114\083\116\111\114\097\103\101")local y=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local q=require(script.Parent.Path)local M={}local h={["\108\111\099\097\108"]=b and X or y,core=(b or __LEMUR__)and i:FindFirstChild("\087\111\114\108\100\069\110\103\105\110\101");corelib=y:FindFirstChild("\087\111\114\108\100\069\110\103\105\110\101")}local function o(O)return O:gsub("\094\037\115\042\040\046-\041\037\115\042\036","\037\049")end local function c(O,b)if type(O)=="\115\116\114\105\110\103"then O=q.parse(O)end local i=not z:IsServer()b.homePath=b.homePath or i and game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")or game:GetService("\083\101\114\118\101\114\083\099\114\105\112\116\083\101\114\118\105\099\101")b.variables=h b.modules=M return q.get(O,b)end local B={}B.__index=B function B.from(b,z)local i={}local X=c(O(z,"\047"),{relativeTo=b.relativeTo})for z,b in next,b.imports do local y=c(O(b,"\047"),{relativeTo=X})if y:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then table.insert(i,require(y))else error(("\091\105\109\112\111\114\116\093 \073\110\118\097\108\105\100 \105\109\112\111\114\116\058 \037\115 \040\037\115\041"):format(b,y.ClassName),3)end end return unpack(i)end local e={}local function V(O,z,b)local i=nil if type(O)=="\116\097\098\108\101"then return setmetatable({imports=O;relativeTo=z;overrides=b},B)end if typeof(O)=="\073\110\115\116\097\110\099\101"then i=require(O)elseif type(O)=="\115\116\114\105\110\103"then local X=O:match("\094\091\037\046\093\043\047")z=z or X and(getfenv(4)).script or h.corelib if not z then error("\073\110\118\097\108\105\100 \114\101\108\097\116\105\118\101\084\111 \105\110 \105\109\112\111\114\116")end b=b or{}i=i or c(O,{homePath=b.homePath,relativeTo=z,findRelative=not X})local y=(getfenv(4)).script or"\099\111\109\109\097\110\100\066\097\114"if typeof(i)=="\073\110\115\116\097\110\099\101"then if i:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then if b.rawImport then return i else e[y]=i local O=i local z=0 while O do z=z+1 O=e[O]if O==i then local b=O.Name or"\063"for z=1,z,1 do O=e[O]b=b..(" -\062 "..O.Name)end error("\070\097\105\108\101\100 \116\111 \105\109\112\111\114\116\033 \068\101\116\101\099\116\101\100 \097 \099\105\114\099\117\108\097\114 \100\101\112\101\110\100\101\110\099\121 \099\104\097\105\110\058 "..b,2)end end i=require(i)if e[y]==module then e[y]=nil end return i end else error(("\091\105\109\112\111\114\116\093 \073\110\118\097\108\105\100 \105\109\112\111\114\116\058 \037\115 \040\037\115\044 \073\115\065 \037\115\041"):format(O,i:GetFullName(),i.ClassName),2)end else return i end end end local function l(O,z,b)if typeof(O)=="\073\110\115\116\097\110\099\101"then return require(O)end if type(O)=="\115\116\114\105\110\103"and O:match("\094\040\091\065-\122\048-\057\037\046\037-\047\064\093\043\041\036")or type(O)=="\116\097\098\108\101"then return V(O,z,b)else local i={}local X=q.parseList(O)for O,X in next,X do table.insert(i,V(X,z,b))end return unpack(i)end end local function j(O)assert(typeof(O)=="\073\110\115\116\097\110\099\101"and O:IsA("\077\111\100\117\108\101\083\099\114\105\112\116"),"\073\109\112\111\114\116\115 \100\101\099\108\097\114\097\116\105\111\110 \115\104\111\117\108\100 \098\101 \097 \077\111\100\117\108\101\083\099\114\105\112\116\033")local z=require(O)assert(typeof(z)=="\116\097\098\108\101")for O,z in next,z do assert(typeof(z)=="\073\110\115\116\097\110\099\101",O.." \105\115 \110\111\116 \097\110 \105\110\115\116\097\110\099\101")h[O]=z end end if b then local O=i:FindFirstChild("\046\105\109\112\111\114\116\115",true)if O and O:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then j(O)end else local O=y:FindFirstChild("\046\105\109\112\111\114\116\115",true)if O and O:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then j(O)end end local function P(z,b)for b,i in pairs(b)do local X=c(O(o(i),"\047"),{relativeTo=z})M[X.Name]=X end end local function K(z)for z,b in pairs(z:GetChildren())do if b:IsA("\083\116\114\105\110\103\086\097\108\117\101")and b.Name=="\109\111\100\117\108\101\115"then P(b.Parent,O(b.Value,"\n"))else K(b)end end end K(y)local J={}if __LEMUR__ then function J.lemur(O)if not __LEMUR__ then error("\096\105\109\112\111\114\116\046\084\101\115\116\096 \099\097\110 \111\110\108\121 \098\101 \117\115\101\100 \098\121 \076\101\109\117\114\046",2)end return function(z,b)if O then local O=l(z,b,{rawImport=true,homePath=i})print("\091\073\109\112\111\114\116\040\083\101\114\118\101\114\041\093 \084\101\115\116 \105\109\112\111\114\116\058 ",("\037\115 \040\037\115\041"):format(z,O and O:GetFullName()or"\063"))return O,O and O:GetFullName()or"\063"else local O=l(z,b,{rawImport=true})print("\091\073\109\112\111\114\116\040\067\108\105\101\110\116\041\093 \084\101\115\116 \105\109\112\111\114\116\058 ",("\037\115 \040\037\115\041"):format(tostring(z),typeof(O)=="\073\110\115\116\097\110\099\101"and O:GetFullName()or tostring(O)))return O,typeof(O)=="\073\110\115\116\097\110\099\101"and O:GetFullName()or tostring(O)end end end end function J.shared(O)return l(O,y)end function J.library(O)return l(O,y:WaitForChild("\087\111\114\108\100\069\110\103\105\110\101"))end function J.server(O)return l(O,i)end function J.relative(O)return l(O,(getfenv(2)).script)end function J.lazy(O)local z return setmetatable({},{__index=function(b,i)if not z then z=V(O)end return z[i]end})end function J.json(O)local z=l(O)return(game:GetService("\072\116\116\112\083\101\114\118\105\099\101")):JSONDecode(z)end function J.async(O,z,b)local i=require(script.Parent.Promise)return i.new(function(X,y)i.spawn(function()local i,q=pcall(l,O,z,b)if i then X(q)else y(q)end end)end)end local function Q(O,z)local b=h[z]if b then return function(O,z)return l(z,b)end else error(tostring(z).." \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \105\109\112\111\114\116\046\112\114\111\116\111\116\121\112\101",2)end end return setmetatable(J,{__call=function(O,...)return l(...)end,__index=Q,__tostring=function()return"\073\109\112\111\114\116\083\121\115\116\101\109"end})
local split = string.split or function(self, delimiter)
		if type(self) ~= "string" then
			error("Expected string got " .. typeof(self))
		end

		local result = {}
		local from = 1
		local delim_from, delim_to = string.find(self, delimiter, from)
		while delim_from do
			table.insert(result, string.sub(self, from, delim_from - 1))
			from = delim_to + 1
			delim_from, delim_to = string.find(self, delimiter, from)
		end
		table.insert(result, string.sub(self, from))
		return result
	end

local RunService = game:GetService("RunService")
local IS_SERVER = RunService:IsServer()
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Path = require(script.Parent.Path)

local modules = {}

local vars = {
	["local"] = IS_SERVER and ServerStorage or ReplicatedStorage,
	core = (IS_SERVER or __LEMUR__) and ServerScriptService:FindFirstChild("WorldEngine"),
	corelib = ReplicatedStorage:FindFirstChild("WorldEngine")
}

local function strtrim(s)
	return (s:gsub("^%s*(.-)%s*$", "%1"))
end

local function path(array, opts)
	if type(array) == "string" then
		array = Path.parse(array)
	end

	local isClient = not RunService:IsServer()

	opts.homePath =
		opts.homePath or (isClient and game:GetService("ReplicatedStorage") or game:GetService("ServerScriptService"))
	opts.variables = vars
	opts.modules = modules
	return Path.get(array, opts)
end

local MultiImport = {}
MultiImport.__index = MultiImport
function MultiImport:from(relativePath)
	local imports = {}
	local parent =
		path(
		split(relativePath, "/"),
		{
			relativeTo = self.relativeTo
		}
	)

	for _, item in next, self.imports do
		local target = path(split(item, "/"), {relativeTo = parent})
		if target:IsA("ModuleScript") then
			table.insert(imports, require(target))
		else
			error(("[import] Invalid import: %s (%s)"):format(item, target.ClassName), 3)
		end
	end

	return unpack(imports)
end

local currentlyLoading = {}
local function import_internal(value, relativeTo, overrides)
	local result = nil

	if type(value) == "table" then -- Handle multi-import
		return setmetatable(
			{
				imports = value,
				relativeTo = relativeTo,
				overrides = overrides
			},
			MultiImport
		)
	end
	if typeof(value) == "Instance" then
		-- luacheck: ignore
		result = require(value)
	elseif type(value) == "string" then
		local isRelativeImport = value:match("^[%.]+/")
		relativeTo = relativeTo or (isRelativeImport and getfenv(4).script or vars.corelib)
		if not relativeTo then
			-- luacov: disable
			error("Invalid relativeTo in import")
		-- luacov: enable
		end

		overrides = overrides or {}

		result =
			result or
			path(
				value,
				{
					homePath = overrides.homePath,
					relativeTo = relativeTo,
					findRelative = not isRelativeImport
				}
			)

		local caller = getfenv(4).script or "commandBar"

		if typeof(result) == "Instance" then
			if result:IsA("ModuleScript") then
				if overrides.rawImport then
					return result
				else
					currentlyLoading[caller] = result
					local currentModule = result
					local depth = 0

					while currentModule do
						depth = depth + 1
						currentModule = currentlyLoading[currentModule]

						if currentModule == result then
							local str = currentModule.Name or "?"

							for _ = 1, depth do
								currentModule = currentlyLoading[currentModule]
								str = str .. " -> " .. currentModule.Name
							end

							error("Failed to import! Detected a circular dependency chain: " .. str, 2)
						end
					end

					result = require(result)

					if currentlyLoading[caller] == module then
						currentlyLoading[caller] = nil
					end

					return result
				end
			else
				error(("[import] Invalid import: %s (%s, IsA %s)"):format(value, result:GetFullName(), result.ClassName), 2)
			end
		else
			return result
		end
	end
end

local function import(value, relativeTo, overrides)
	if typeof(value) == "Instance" then
		return require(value)
	end

	if (type(value) == "string" and value:match("^([A-z0-9%.%-/@]+)$")) or type(value) == "table" then
		return import_internal(value, relativeTo, overrides)
	else
		local importList = {}
		local parts = Path.parseList(value)

		for _, part in next, parts do
			table.insert(importList, import_internal(part, relativeTo, overrides))
		end

		return unpack(importList)
	end
end

local function load_imports(module)
	assert(typeof(module) == "Instance" and module:IsA("ModuleScript"), "Imports declaration should be a ModuleScript!")

	local extraVars = require(module)
	assert(typeof(extraVars) == "table")
	for name, value in next, extraVars do
		assert(typeof(value) == "Instance", name .. " is not an instance")
		vars[name] = value
	end
end

-- luacov: disable
-- variable discovery

if (IS_SERVER) then
	local extraServerVarsModule = ServerScriptService:FindFirstChild(".imports", true)
	if (extraServerVarsModule and extraServerVarsModule:IsA("ModuleScript")) then
		load_imports(extraServerVarsModule)
	end
else
	local extraVarsModule = ReplicatedStorage:FindFirstChild(".imports", true)
	if (extraVarsModule and extraVarsModule:IsA("ModuleScript")) then
		load_imports(extraVarsModule)
	end
end

local function getModules(dir, mods)
	for _, modulePath in pairs(mods) do
		local module = path(split(strtrim(modulePath), "/"), {relativeTo = dir})
		modules[module.Name] = module
	end
end

local function findModuleDeclarations(dir)
	for _, child in pairs(dir:GetChildren()) do
		if (child:IsA("StringValue") and child.Name == "modules") then
			getModules(child.Parent, split(child.Value, "\n"))
		else
			findModuleDeclarations(child)
		end
	end
end

findModuleDeclarations(ReplicatedStorage)

local prototype = {}

if (__LEMUR__) then
	function prototype.lemur(isServer)
		if not __LEMUR__ then
			error("`import.Test` can only be used by Lemur.", 2)
		end

		return function(p, r)
			if isServer then
				local value = import(p, r, {rawImport = true, homePath = ServerScriptService})
				print("[Import(Server)] Test import: ", ("%s (%s)"):format(p, value and value:GetFullName() or "?"))
				return value, value and value:GetFullName() or "?"
			else
				local value = import(p, r, {rawImport = true})
				print(
					"[Import(Client)] Test import: ",
					("%s (%s)"):format(tostring(p), typeof(value) == "Instance" and value:GetFullName() or tostring(value))
				)
				return value, typeof(value) == "Instance" and value:GetFullName() or tostring(value)
			end
		end
	end
end

function prototype.shared(relativePath)
	return import(relativePath, ReplicatedStorage)
end

function prototype.library(relativePath)
	return import(relativePath, ReplicatedStorage:WaitForChild("WorldEngine"))
end

function prototype.server(relativePath)
	return import(relativePath, ServerScriptService)
end

function prototype.relative(relativePath)
	return import(relativePath, getfenv(2).script)
end

function prototype.lazy(relativePath)
	local ref
	return setmetatable(
		{},
		{
			__index = function(self, index)
				if not ref then
					ref = import_internal(relativePath)
				end

				return ref[index]
			end
		}
	)
end

function prototype.json(relativePath)
	local text = import(relativePath)
	return game:GetService("HttpService"):JSONDecode(text)
end

function prototype.async(relativePath, relativeTo, overrides)
	local Promise = require(script.Parent.Promise)
	return Promise.new(
		function(resolve, reject)
			Promise.spawn(
				function()
					local success, result = pcall(import, relativePath, relativeTo, overrides)
					if success then
						resolve(result)
					else
						reject(result)
					end
				end
			)
		end
	)
end

local function importNSVariable(self, name)
	local value = vars[name]
	if value then
		return function(_, relativePath)
			return import(relativePath, value)
		end
	else
		error(tostring(name) .. " is not a valid member of import.prototype", 2)
	end
end

return setmetatable(
	prototype,
	{
		__call = function(_, ...)
			return import(...)
		end, -- alias: import.relative
		__index = importNSVariable,
		__tostring = function()
			return "ImportSystem"
		end
	}
)
-- luacov: enable
