local D=game:GetService("\084\101\120\116\083\101\114\118\105\099\101")local o=script:FindFirstAncestor("\084\101\120\116\069\100\105\116\111\114")local m=require(o.Packages.Roact)local c=require(script.Parent.StudioThemeContext)local f=m.Component:extend("\084\101\120\116\076\097\098\101\108")f.defaultProps={BackgroundTransparency=1;BorderSizePixel=1;Visible=true;Font=Enum.Font.SourceSans;TextSize=20,Text="\112\114\111\112\115\046\084\101\120\116";TextWrapped=false;TextXAlignment=Enum.TextXAlignment.Left,TextYAlignment=Enum.TextYAlignment.Center,RichText=false;backgroundThemeType=Enum.StudioStyleGuideColor.MainBackground,themeType=Enum.StudioStyleGuideColor.MainText,themeModifier=Enum.StudioStyleGuideModifier.Default}function f.init(o)local c=o.props.Size if not c then if o.props.TextWrapped then c=UDim2.fromScale(1,0)else local m=D:GetTextSize(typeof(o.props.Text)=="\115\116\114\105\110\103"and o.props.Text or o.props.Text:getValue(),o.props.TextSize,o.props.Font,Vector2.new(math.huge,math.huge))c=UDim2.new(o.props.Width or UDim.new(0,m.X),UDim.new(0,m.Y))end end o.size,o.updateSize=m.createBinding(c)end function f.render(o)return m.createElement(c.Consumer,{render=function(c)return m.createElement("\084\101\120\116\076\097\098\101\108",{AnchorPoint=o.props.AnchorPoint;LayoutOrder=o.props.LayoutOrder;Position=o.props.Position,Size=o.size;BackgroundColor3=o.props.BackgroundColor3 or c:GetColor(o.props.backgroundThemeType,o.props.themeModifier),BackgroundTransparency=o.props.BackgroundTransparency,BorderSizePixel=o.props.BorderSizePixel,Visible=o.props.Visible,Font=o.props.Font,TextSize=o.props.TextSize;TextColor3=o.props.TextColor3 or c:GetColor(o.props.themeType,o.props.themeModifier),Text=o.props.Text;TextWrapped=o.props.TextWrapped;TextXAlignment=o.props.TextXAlignment;TextYAlignment=o.props.TextYAlignment;RichText=o.props.RichText;[m.Change.Text]=function(c,...)local f=o.props.TextWrapped and c.AbsoluteSize.X-2 or math.huge local R=D:GetTextSize(c.Text,o.props.TextSize,o.props.Font,Vector2.new(f,math.huge))o.updateSize(UDim2.new(o.props.TextWrapped and UDim.new(1,0)or o.props.Width or UDim.new(0,R.X),UDim.new(0,R.Y)))if o.props[m.Change.Text]then o.props[m.Change.Text](c,...)end end})end})end return f
-- Based off https://github.com/tiffany352/Roblox-Tag-Editor/blob/master/src/Components/TextLabel.lua
local TextService = game:GetService("TextService")
local TextEditor = script:FindFirstAncestor("TextEditor")
local Roact = require(TextEditor.Packages.Roact)

local StudioThemeContext = require(script.Parent.StudioThemeContext)
local TextLabel = Roact.Component:extend("TextLabel")

TextLabel.defaultProps = {
  BackgroundTransparency = 1,
  BorderSizePixel = 1,
  Visible = true,

  Font = Enum.Font.SourceSans,
  TextSize = 20,
  Text = "props.Text",
  TextWrapped = false,
  TextXAlignment = Enum.TextXAlignment.Left,
  TextYAlignment = Enum.TextYAlignment.Center,
  RichText = false,

  backgroundThemeType = Enum.StudioStyleGuideColor.MainBackground,
  themeType = Enum.StudioStyleGuideColor.MainText,
  themeModifier = Enum.StudioStyleGuideModifier.Default,
}

function TextLabel:init()
  local size = self.props.Size
  if not size then
    if self.props.TextWrapped then
      size = UDim2.fromScale(1, 0)
    else
      local TextBounds = TextService:GetTextSize(typeof(self.props.Text) == "string" and self.props.Text or self.props.Text:getValue(), self.props.TextSize, self.props.Font, Vector2.new(math.huge, math.huge))
      size = UDim2.new(self.props.Width or UDim.new(0, TextBounds.X), UDim.new(0, TextBounds.Y))
    end
  end
  self.size, self.updateSize = Roact.createBinding(size)
end

function TextLabel:render()
  return Roact.createElement(StudioThemeContext.Consumer, {
    render = function(theme)
      return Roact.createElement("TextLabel", {
        AnchorPoint = self.props.AnchorPoint,
        LayoutOrder = self.props.LayoutOrder,
        Position = self.props.Position,
        Size = self.size,
        BackgroundColor3 = self.props.BackgroundColor3 or theme:GetColor(self.props.backgroundThemeType, self.props.themeModifier),
        BackgroundTransparency = self.props.BackgroundTransparency,
        BorderSizePixel = self.props.BorderSizePixel,
        Visible = self.props.Visible,

        Font = self.props.Font,
        TextSize = self.props.TextSize,
        TextColor3 = self.props.TextColor3 or theme:GetColor(self.props.themeType, self.props.themeModifier),
        Text = self.props.Text,
        TextWrapped = self.props.TextWrapped,
        TextXAlignment = self.props.TextXAlignment,
        TextYAlignment = self.props.TextYAlignment,
        RichText = self.props.RichText,

        [Roact.Change.Text] = function(rbx, ...)
          local MaxWidth = self.props.TextWrapped and rbx.AbsoluteSize.X - 2 or math.huge
          local TextBounds = TextService:GetTextSize(rbx.Text, self.props.TextSize, self.props.Font, Vector2.new(MaxWidth, math.huge))
          self.updateSize(UDim2.new(self.props.TextWrapped and UDim.new(1, 0) or self.props.Width or UDim.new(0, TextBounds.X), UDim.new(0, TextBounds.Y)))
          if self.props[Roact.Change.Text] then
            self.props[Roact.Change.Text](rbx, ...)
          end
        end,
      })
    end
  })
end


return TextLabel