local H=import("\046\046\047\069\110\117\109\047\083\099\114\111\108\108\105\110\103\068\105\114\101\099\116\105\111\110")local a=import("\046\046\047\069\110\117\109\047\083\099\114\111\108\108\066\097\114\073\110\115\101\116")local X=import("\046\046\047\069\110\117\109\047\086\101\114\116\105\099\097\108\083\099\114\111\108\108\066\097\114\080\111\115\105\116\105\111\110")local t=import("\046\047\071\117\105\079\098\106\101\099\116")local Y=import("\046\046\047\073\110\115\116\097\110\099\101\080\114\111\112\101\114\116\121")local R=import("\046\046\047\116\121\112\101\115\047\085\068\105\109\050")local T=import("\046\046\047\116\121\112\101\115\047\086\101\099\116\111\114\050")local F=t:extend("\083\099\114\111\108\108\105\110\103\070\114\097\109\101",{creatable=true})F.properties.AbsoluteWindowSize=Y.readOnly({get=function(H)local a=H.AbsoluteSize local X=H.ScrollBarThickness local t=0 local Y=0 if H:_canScrollHorizontal()then t=X end if H:_canScrollVertical()then Y=X end return T.new(math.max(0,a.X-t),math.max(0,a.Y-Y))end})F.properties.CanvasPosition=Y.typed("\086\101\099\116\111\114\050",{getDefault=function()return T.new()end})F.properties.CanvasSize=Y.typed("\085\068\105\109\050",{getDefault=function()return R.new()end})F.properties.ScrollBarThickness=Y.typed("\110\117\109\098\101\114",{getDefault=function()return 12 end})F.properties.ScrollingDirection=Y.enum(H,{getDefault=function()return H.XY end})F.properties.ScrollingEnabled=Y.typed("\098\111\111\108\101\097\110",{getDefault=function()return true end})F.properties.VerticalScrollBarInset=Y.enum(a,{getDefault=function()return a.None end})F.properties.VerticalScrollBarPosition=Y.enum(X,{getDefault=function()return X.Right end})function F.prototype._canScrollHorizontal(a)local X=a.ScrollingDirection return a.ScrollingEnabled and(X==H.X or X==H.XY)end function F.prototype._canScrollVertical(a)local X=a.ScrollingDirection return a.ScrollingEnabled and(X==H.Y or X==H.XY)end return F
local ScrollingDirection = import("../Enum/ScrollingDirection")
local ScrollBarInset = import("../Enum/ScrollBarInset")
local VerticalScrollBarPosition = import("../Enum/VerticalScrollBarPosition")
local GuiObject = import("./GuiObject")
local InstanceProperty = import("../InstanceProperty")
local UDim2 = import("../types/UDim2")
local Vector2 = import("../types/Vector2")

local ScrollingFrame = GuiObject:extend("ScrollingFrame", {
	creatable = true,
})

ScrollingFrame.properties.AbsoluteWindowSize = InstanceProperty.readOnly({
	get = function(self)
		local size = self.AbsoluteSize

		local thickness = self.ScrollBarThickness
		local marginX = 0
		local marginY = 0

		if self:_canScrollHorizontal() then
			marginX = thickness
		end

		if self:_canScrollVertical() then
			marginY = thickness
		end

		return Vector2.new(
			math.max(0, size.X - marginX),
			math.max(0, size.Y - marginY)
		)
	end,
})

ScrollingFrame.properties.CanvasPosition = InstanceProperty.typed("Vector2", {
	getDefault = function()
		return Vector2.new()
	end,
})

ScrollingFrame.properties.CanvasSize = InstanceProperty.typed("UDim2", {
	getDefault = function()
		return UDim2.new()
	end,
})

ScrollingFrame.properties.ScrollBarThickness = InstanceProperty.typed("number", {
	getDefault = function()
		return 12
	end,
})

ScrollingFrame.properties.ScrollingDirection = InstanceProperty.enum(ScrollingDirection, {
	getDefault = function()
		return ScrollingDirection.XY
	end,
})

ScrollingFrame.properties.ScrollingEnabled = InstanceProperty.typed("boolean", {
	getDefault = function()
		return true
	end,
})

ScrollingFrame.properties.VerticalScrollBarInset = InstanceProperty.enum(ScrollBarInset, {
	getDefault = function()
		return ScrollBarInset.None
	end,
})

ScrollingFrame.properties.VerticalScrollBarPosition = InstanceProperty.enum(VerticalScrollBarPosition, {
	getDefault = function()
		return VerticalScrollBarPosition.Right
	end,
})

function ScrollingFrame.prototype:_canScrollHorizontal()
	local scrollDir = self.ScrollingDirection
	return self.ScrollingEnabled and
		(scrollDir == ScrollingDirection.X or
		scrollDir == ScrollingDirection.XY)
end

function ScrollingFrame.prototype:_canScrollVertical()
	local scrollDir = self.ScrollingDirection
	return self.ScrollingEnabled and
		(scrollDir == ScrollingDirection.Y or
		scrollDir == ScrollingDirection.XY)
end

return ScrollingFrame