--[[ local Workspace = game:GetService("Workspace")
local GuiService = game:GetService("GuiService")

local Camera = Workspace.CurrentCamera
local TopInset, BottomInset = GuiService:GetGuiInset()

local Roact = require("Roact")

local Scale = Roact.PureComponent:extend("Scale")

function Scale:init()
	self:update()

	self.Listener = Camera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
		self:update()
	end)
end

function Scale:update()
	local currentSize = self.props.Size
	local viewportSize = Camera.ViewportSize - (TopInset + BottomInset)

	self:setState({
		Scale = 1 / math.max(
			currentSize.X / viewportSize.X,
			currentSize.Y / viewportSize.Y
		)
	})
end

function Scale:willUnmount()
	self.Listener:Disconnect()
end

function Scale:render()
	return Roact.createElement("UIScale", {
		Scale = self.state.Scale * self.props.Scale
	})
end

Scale.defaultProps = {
	Scale = 1
}

return Scale

 ]]


local Fusion = require(game.ReplicatedStorage.Packages.Fusion)
local New = Fusion.New
local Children = Fusion.Children
local OnEvent = Fusion.OnEvent
local OnChange = Fusion.OnChange
local State = Fusion.State
local Computed = Fusion.Computed
local Spring = Fusion.Spring


local Workspace = game:GetService("Workspace")
local GuiService = game:GetService("GuiService")

local Camera = Workspace.CurrentCamera
local TopInset, BottomInset = GuiService:GetGuiInset()



local function UIScale(props)
	--props:  Size = v3   Scale = float
	local	ScaleState = State()

	local function update()
		local currentSize = props.Size
		local viewportSize = Camera.ViewportSize - (TopInset + BottomInset)
	
		ScaleState:set(1 / math.max(
			currentSize.X / viewportSize.X,
			currentSize.Y / viewportSize.Y
		))
	end

	update()
	Camera:GetPropertyChangedSignal("ViewportSize"):Connect(update)

	return New "UIScale" {
		Scale = Computed(function()
			return ScaleState:get() * props.Scale
		end)
	}
end


return UIScale
