local P=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 F=import("\046\046\047\069\110\117\109\047\083\099\114\111\108\108\066\097\114\073\110\115\101\116")local d=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 K=import("\046\047\071\117\105\079\098\106\101\099\116")local f=import("\046\046\047\073\110\115\116\097\110\099\101\080\114\111\112\101\114\116\121")local Q=import("\046\046\047\116\121\112\101\115\047\085\068\105\109\050")local w=import("\046\046\047\116\121\112\101\115\047\086\101\099\116\111\114\050")local e=K:extend("\083\099\114\111\108\108\105\110\103\070\114\097\109\101",{creatable=true})e.properties.AbsoluteWindowSize=f.readOnly({get=function(P)local F=P.AbsoluteSize local d=P.ScrollBarThickness local K=0 local f=0 if P:_canScrollHorizontal()then K=d end if P:_canScrollVertical()then f=d end return w.new(math.max(0,F.X-K),math.max(0,F.Y-f))end})e.properties.CanvasPosition=f.typed("\086\101\099\116\111\114\050",{getDefault=function()return w.new()end})e.properties.CanvasSize=f.typed("\085\068\105\109\050",{getDefault=function()return Q.new()end})e.properties.ScrollBarThickness=f.typed("\110\117\109\098\101\114",{getDefault=function()return 12 end})e.properties.ScrollingDirection=f.enum(P,{getDefault=function()return P.XY end})e.properties.ScrollingEnabled=f.typed("\098\111\111\108\101\097\110",{getDefault=function()return true end})e.properties.VerticalScrollBarInset=f.enum(F,{getDefault=function()return F.None end})e.properties.VerticalScrollBarPosition=f.enum(d,{getDefault=function()return d.Right end})function e.prototype._canScrollHorizontal(F)local d=F.ScrollingDirection return F.ScrollingEnabled and(d==P.X or d==P.XY)end function e.prototype._canScrollVertical(F)local d=F.ScrollingDirection return F.ScrollingEnabled and(d==P.Y or d==P.XY)end return e
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