local K=import("\046\046\047\097\115\115\105\103\110")local T=import("\046\046\047\116\121\112\101\075\101\121")local y=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local o=import("\046\047\085\068\105\109")local function q(K,T,y)return(1-y)*K+T*y end local A={}setmetatable(A,{__tostring=function()return"\085\068\105\109\050"end})local H={}function H.Lerp(y,K,T)return A.new(q(y.X.Scale,K.X.Scale,T),q(y.X.Offset,K.X.Offset,T),q(y.Y.Scale,K.Y.Scale,T),q(y.Y.Offset,K.Y.Offset,T))end local R={}R[T]="\085\068\105\109\050"function R.__index(T,K)local y=(getmetatable(T)).internal if y[K]~=nil then return y[K]end if H[K]~=nil then return H[K]end error(string.format("\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \085\068\105\109\050",tostring(K)),2)end function R.__eq(T,K)return T.X==K.X and T.Y==K.Y end function R.__add(T,K)return A.new(T.X+K.X,T.Y+K.Y)end function A.new(...)if select("\035",...)==0 then return A.new(o.new(0,0),o.new(0,0))end if select("\035",...)==4 then local K,T,y,q=...if type(K)~="\110\117\109\098\101\114"or type(T)~="\110\117\109\098\101\114"or type(y)~="\110\117\109\098\101\114"or type(q)~="\110\117\109\098\101\114"then error("\085\068\105\109\050\046\110\101\119\040\120\083\099\097\108\101\044 \120\079\102\102\115\101\116\044 \121\083\099\097\108\101\044 \121\079\102\102\115\101\116\041 \116\097\107\101\115 \105\110 \052 \110\117\109\098\101\114\115",2)end return A.new(o.new(K,T),o.new(y,q))end local T,q=...if y(T)~="\085\068\105\109"or y(q)~="\085\068\105\109"then error("\085\068\105\109\050\046\110\101\119\040\120\068\105\109\044 \121\068\105\109\041 \116\097\107\101\115 \105\110 \050 \085\068\105\109\115",2)end local H={X=T,Y=q;Width=T,Height=q}local U=newproxy(true)K(getmetatable(U),R);(getmetatable(U)).internal=H return U end return A
local assign = import("../assign")
local typeKey = import("../typeKey")
local typeof = import("../functions/typeof")
local UDim = import("./UDim")

local function lerpNumber(a, b, alpha)
	return (1 - alpha) * a + b * alpha
end

local UDim2 = {}

setmetatable(UDim2, {
	__tostring = function()
		return "UDim2"
	end,
})

local prototype = {}

function prototype:Lerp(goal, alpha)
	return UDim2.new(
		lerpNumber(self.X.Scale, goal.X.Scale, alpha),
		lerpNumber(self.X.Offset, goal.X.Offset, alpha),
		lerpNumber(self.Y.Scale, goal.Y.Scale, alpha),
		lerpNumber(self.Y.Offset, goal.Y.Offset, alpha)
	)
end

local metatable = {}
metatable[typeKey] = "UDim2"

function metatable:__index(key)
	local internal = getmetatable(self).internal

	if internal[key] ~= nil then
		return internal[key]
	end

	if prototype[key] ~= nil then
		return prototype[key]
	end

	error(string.format("%s is not a valid member of UDim2", tostring(key)), 2)
end

function metatable:__eq(other)
	return self.X == other.X and self.Y == other.Y
end

function metatable:__add(other)
	return UDim2.new(self.X + other.X, self.Y + other.Y)
end

function UDim2.new(...)
	if select("#", ...) == 0 then
		return UDim2.new(
			UDim.new(0, 0),
			UDim.new(0, 0)
		)
	end

	if select("#", ...) == 4 then
		local xScale, xOffset, yScale, yOffset = ...
		if type(xScale) ~= "number" or type(xOffset) ~= "number" or
			type(yScale) ~= "number" or type(yOffset) ~= "number" then
			error("UDim2.new(xScale, xOffset, yScale, yOffset) takes in 4 numbers", 2)
		end

		return UDim2.new(
			UDim.new(xScale, xOffset),
			UDim.new(yScale, yOffset)
		)
	end

	local xDim, yDim = ...

	if typeof(xDim) ~= "UDim" or typeof(yDim) ~= "UDim" then
		error("UDim2.new(xDim, yDim) takes in 2 UDims", 2)
	end

	local internalInstance = {
		X = xDim,
		Y = yDim,
		Width = xDim,
		Height = yDim,
	}
	local instance = newproxy(true)

	assign(getmetatable(instance), metatable)
	getmetatable(instance).internal = internalInstance

	return instance
end

return UDim2
