local M=Vector2.new(math.huge,math.huge)function TextBox.getSize(r)if not(r.props.Width or r.props.Height or r.props.Size=="\087\082\065\080\095\067\079\078\084\069\078\084")then return r.props.Size end local f,l if typeof(r.props.Width)=="\085\068\105\109"then f=r.props.Width elseif typeof(r.props.Height)=="\085\068\105\109"then l=r.props.Height end local Y=r.props.TextSize if r.props.TextScaled and r.AbsoluteSize then Y=r.AbsoluteSize.Y end local F=TextService:GetTextSize(r.props.Text,Y,r.props.Font,M)if not f and(r.props.Width=="\087\082\065\080\095\067\079\078\084\069\078\084"or r.props.Size=="\087\082\065\080\095\067\079\078\084\069\078\084")then f=UDim.new(0,F.X)end if not l and(r.props.Height=="\087\082\065\080\095\067\079\078\084\069\078\084"or r.props.Size=="\087\082\065\080\095\067\079\078\084\069\078\084")then l=UDim.new(0,F.Y)end return UDim2.new(f or r.props.Size and r.props.Size.X or UDim.new(),l or r.props.Size and r.props.Size.Y or UDim.new())end function TextBox.updateSize(M)local r=M:getSize()local f=M.props.TextScaled and(M.AbsoluteSize and M.AbsoluteSize.Y)or M.props.TextSize if M.state.Size~=r or M.state.TextSize~=f then M:setState({Size=r,TextSize=f})end end function TextBox.init(M)M.Updating=true M.state={Size=UDim2.new(),TextSize=0}end function TextBox.willUpdate(f,M,r)f.Updating=true end function TextBox.render(M)local r=Support.Merge({},M.props,{Size=M.state.Size,TextSize=M.state.TextSize;TextScaled=false,[Roact.Ref]=function(r)M.AbsoluteSize=r and r.AbsoluteSize or M.AbsoluteSize end,[Roact.Change.AbsoluteSize]=function(r)M.AbsoluteSize=r.AbsoluteSize if not M.Updating then M:updateSize()end end})if type(r.TextColor)=="\115\116\114\105\110\103"then local M,f,l=(r.TextColor:lower()):match("\035\063\040\046\046\041\040\046\046\041\040\046\046\041")r.TextColor3=Color3.fromRGB(tonumber(M,16),tonumber(f,16),tonumber(l,16))end local f=Support.Merge({},M.props[Roact.Children])r.Width=nil r.Height=nil r.Bold=nil r.TextColor=nil r[Roact.Children]=nil if M.props.Bold then local M=Support.CloneTable(r)M.Size=UDim2.new(1,0,1,0)M.Position=nil M.TextScaled=true M.AnchorPoint=nil f.Bold=new(TextBox,M)end return new("\084\101\120\116\066\111\120",r,f)end function TextBox.didMount(M)M.Updating=nil M:updateSize()end function TextBox.didUpdate(f,M,r)f.Updating=nil f:updateSize()end return TextBox

local INFINITE_BOUNDS = Vector2.new(math.huge, math.huge)

function TextBox:getSize()

    -- Return size directly if fixed
    if not (self.props.Width or self.props.Height or self.props.Size == 'WRAP_CONTENT') then
        return self.props.Size
    end

    -- Get fixed sizes for individual axes
    local Width, Height
    if typeof(self.props.Width) == 'UDim' then
        Width = self.props.Width
    elseif typeof(self.props.Height) == 'UDim' then
        Height = self.props.Height
    end

    -- Get text size from height if autoscaled
    local TextSize = self.props.TextSize
    if self.props.TextScaled and self.AbsoluteSize then
        TextSize = self.AbsoluteSize.Y
    end

    -- Calculate content bounds
    local Bounds = TextService:GetTextSize(
        self.props.Text,
        TextSize,
        self.props.Font,
        INFINITE_BOUNDS
    )

    -- Set width and height based on content if requested
    if not Width and (self.props.Width == 'WRAP_CONTENT' or self.props.Size == 'WRAP_CONTENT') then
        Width = UDim.new(0, Bounds.X)
    end
    if not Height and (self.props.Height == 'WRAP_CONTENT' or self.props.Size == 'WRAP_CONTENT') then
        Height = UDim.new(0, Bounds.Y)
    end

    -- Return the calculated size
    return UDim2.new(
        Width or (self.props.Size and self.props.Size.X) or UDim.new(),
        Height or (self.props.Size and self.props.Size.Y) or UDim.new()
    )

end

function TextBox:updateSize()

    -- Calculate new size
    local Size = self:getSize()
    local TextSize = self.props.TextScaled and
        (self.AbsoluteSize and self.AbsoluteSize.Y) or
        self.props.TextSize

    -- Check if state is outdated
    if self.state.Size ~= Size or
        self.state.TextSize ~= TextSize then

        -- Update state
        self:setState {
            Size = Size,
            TextSize = TextSize
        }
    end
end

function TextBox:init()
    self.Updating = true
    self.state = {
        Size = UDim2.new(),
        TextSize = 0
    }
end

function TextBox:willUpdate(nextProps, nextState)
    self.Updating = true
end

function TextBox:render()
    local props = Support.Merge({}, self.props, {

        -- Override size
        Size = self.state.Size,
        TextSize = self.state.TextSize,
        TextScaled = false,

        -- Get initial size
        [Roact.Ref] = function (rbx)
            self.AbsoluteSize = rbx and
                rbx.AbsoluteSize or
                self.AbsoluteSize
        end,

        -- Track size changes
        [Roact.Change.AbsoluteSize] = function (rbx)
            self.AbsoluteSize = rbx.AbsoluteSize
            if not self.Updating then
                self:updateSize()
            end
        end

    })

    -- Parse hex colors
    if type(props.TextColor) == 'string' then
        local R, G, B = props.TextColor:lower():match('#?(..)(..)(..)')
        props.TextColor3 = Color3.fromRGB(tonumber(R, 16), tonumber(G, 16), tonumber(B, 16))
    end

    -- Separate children from props
    local children = Support.Merge({}, self.props[Roact.Children])

    -- Clear invalid props
    props.Width = nil
    props.Height = nil
    props.Bold = nil
    props.TextColor = nil
    props[Roact.Children] = nil

    -- Add a bold layer if specified
    if self.props.Bold then
        local BoldProps = Support.CloneTable(props)
        BoldProps.Size = UDim2.new(1, 0, 1, 0)
        BoldProps.Position = nil
        BoldProps.TextScaled = true
        BoldProps.AnchorPoint = nil
        children.Bold = new(TextBox, BoldProps)
    end

    -- Display component in wrapper
    return new('TextBox', props, children)

end

function TextBox:didMount()
    self.Updating = nil
    self:updateSize()
end

function TextBox:didUpdate(previousProps, previousState)
    self.Updating = nil
    self:updateSize()
end

return TextBox
