local D=script:FindFirstAncestor("\084\101\120\116\069\100\105\116\111\114")local o=require(D.Packages.Roact)local m=require(script.Parent.StudioThemeContext)local c=o.PureComponent:extend("\082\111\117\110\100\084\101\120\116\066\117\116\116\111\110")function c.init(D)D.state={Hovering=false;Pressed=false}D.mouseEnter=function()if D.props.Enabled then D:mouseHoverChanged(true)end end D.mouseLeave=function()if D.props.Enabled then D:mouseHoverChanged(false)D:setState({Pressed=false})end end end function c.mouseHoverChanged(o,D)if nil~=o.props.OnHoverChanged then o.props.OnHoverChanged(o.props.Value,D)end o:setState({Hovering=D})end function c.render(D)local c=D.props.Enabled local f=D.state.Hovering local R=D.props.BorderMatchesBackground return o.createElement(m.Consumer,{render=function(m)local K={ButtonColor=m:GetColor(Enum.StudioStyleGuideColor.MainButton);ButtonHoverColor=m:GetColor(Enum.StudioStyleGuideColor.MainButton,Enum.StudioStyleGuideModifier.Hover);ButtonPressedColor=m:GetColor(Enum.StudioStyleGuideColor.Button,Enum.StudioStyleGuideModifier.Pressed),ButtonDisabledColor=m:GetColor(Enum.StudioStyleGuideColor.Button,Enum.StudioStyleGuideModifier.Disabled),TextColor=Color3.new(1,1,1);TextDisabledColor=m:GetColor(Enum.StudioStyleGuideColor.DimmedText),BorderColor=m:GetColor(Enum.StudioStyleGuideColor.Light)}local C={BackgroundTransparency=1;Image="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\083\116\117\100\105\111\084\111\111\108\098\111\120\047\082\111\117\110\100\101\100\066\097\099\107\103\114\111\117\110\100\046\112\110\103";ImageTransparency=0;ScaleType=Enum.ScaleType.Slice;SliceCenter=Rect.new(3,3,13,13),Position=UDim2.new(0,0,0,0);Size=D.props.Size or UDim2.new(0,125,0,35),LayoutOrder=D.props.LayoutOrder or 1,ZIndex=D.props.ZIndex or 1,[o.Event.MouseEnter]=D.mouseEnter,[o.Event.MouseLeave]=D.mouseLeave,[o.Event.Activated]=function()if c then D.props.OnClicked(D.props.Value)end end;[o.Event.InputBegan]=function(o,m)if c and m.UserInputType==Enum.UserInputType.MouseButton1 then D:setState({Pressed=true})end end;[o.Event.InputEnded]=function(o,m)if c and m.UserInputType==Enum.UserInputType.MouseButton1 then D:setState({Pressed=false})end end}if c then if D.props.ShowPressed and D.state.Pressed then C.ImageColor3=K.ButtonPressedColor else C.ImageColor3=f and K.ButtonHoverColor or K.ButtonColor end else C.ImageColor3=K.ButtonDisabledColor end return o.createElement("\073\109\097\103\101\066\117\116\116\111\110",C,{Border=o.createElement("\073\109\097\103\101\076\097\098\101\108",{Size=UDim2.new(1,0,1,0);BackgroundTransparency=1;Image="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\083\116\117\100\105\111\084\111\111\108\098\111\120\047\082\111\117\110\100\101\100\066\111\114\100\101\114\046\112\110\103",ImageColor3=R and C.ImageColor3 or K.BorderColor;ScaleType=Enum.ScaleType.Slice;SliceCenter=Rect.new(3,3,13,13),ZIndex=D.props.ZIndex or 1});Text=o.createElement("\084\101\120\116\076\097\098\101\108",{Size=UDim2.new(1,0,1,0);BackgroundTransparency=1,BorderSizePixel=0;Font=Enum.Font.SourceSans,TextColor3=c and K.TextColor or K.TextDisabledColor;TextSize=22,Text=D.props.Name,ZIndex=D.props.ZIndex or 1})})end})end return c
-- Based off https://github.com/CloneTrooper1019/Roblox-Client-Tracker/blob/roblox/BuiltInPlugins/GameSettings/RoactStudioWidgets/RoundTextButton.lua
--[[
	A button with rounded corners.

	Supports one of two styles:
		"Blue": A blue button with white text and no border.
		"White": A white button with black text and a black border.

	Props:
		bool Enabled = Whether or not this button can be clicked.
		UDim2 Size = UDim2.new(0, Constants.BUTTON_WIDTH, 0, Constants.BUTTON_HEIGHT)
		int LayoutOrder = The order this RoundTextButton will sort to when placed in a UIListLayout.
		string Name = The text to display in this Button.
		function OnClicked = The function that will be called when this button is clicked.
		function OnHoverChanged = The function that will be called when the hover state changes.
		variant Value = Data that can be accessed from the OnClicked callback.
		table Style = {
			ButtonColor,
			ButtonHoverColor,
			ButtonPressedColor,
			ButtonDisabledColor,
			TextColor,
			TextDisabledColor,
			BorderColor,
		}
		bool ShowPressed = Whether the button appears a different color when pressed
		Mouse = plugin mouse for changing the mouse icon
]]


local TextEditor = script:FindFirstAncestor("TextEditor")
local Roact = require(TextEditor.Packages.Roact)

local StudioThemeContext = require(script.Parent.StudioThemeContext)
local RoundTextButton = Roact.PureComponent:extend("RoundTextButton")

function RoundTextButton:init()
  self.state = {
    Hovering = false,
    Pressed = false
  }

  self.mouseEnter = function()
    if self.props.Enabled then
      self:mouseHoverChanged(true)
    end
  end

  self.mouseLeave = function()
    if self.props.Enabled then
      self:mouseHoverChanged(false)
      self:setState({
        Pressed = false,
      })
    end
  end
end

function RoundTextButton:mouseHoverChanged(hovering)
  if nil ~= self.props.OnHoverChanged then
    self.props.OnHoverChanged(self.props.Value, hovering)
  end

  self:setState({
    Hovering = hovering,
  })
end

function RoundTextButton:render()
  local active = self.props.Enabled
  local hovering = self.state.Hovering
  local match = self.props.BorderMatchesBackground

  return Roact.createElement(StudioThemeContext.Consumer, {
    render = function(theme)
      local style = {
        ButtonColor = theme:GetColor(Enum.StudioStyleGuideColor.MainButton),
        ButtonHoverColor = theme:GetColor(Enum.StudioStyleGuideColor.MainButton, Enum.StudioStyleGuideModifier.Hover),
        ButtonPressedColor = theme:GetColor(Enum.StudioStyleGuideColor.Button, Enum.StudioStyleGuideModifier.Pressed),
        ButtonDisabledColor = theme:GetColor(Enum.StudioStyleGuideColor.Button, Enum.StudioStyleGuideModifier.Disabled),
        TextColor = Color3.new(1, 1, 1),
        TextDisabledColor = theme:GetColor(Enum.StudioStyleGuideColor.DimmedText),
        BorderColor = theme:GetColor(Enum.StudioStyleGuideColor.Light),
      }
    
      local backgroundProps = {
        -- Necessary to make the rounded background
        BackgroundTransparency = 1,
        Image = "rbxasset://textures/StudioToolbox/RoundedBackground.png",
        ImageTransparency = 0,
        ScaleType = Enum.ScaleType.Slice,
        SliceCenter = Rect.new(3, 3, 13, 13),
    
        Position = UDim2.new(0, 0, 0, 0),
        Size = self.props.Size or UDim2.new(0, 125, 0, 35),
    
        LayoutOrder = self.props.LayoutOrder or 1,
        ZIndex = self.props.ZIndex or 1,
    
        [Roact.Event.MouseEnter] = self.mouseEnter,
        [Roact.Event.MouseLeave] = self.mouseLeave,
    
        [Roact.Event.Activated] = function()
          if active then
            self.props.OnClicked(self.props.Value)
          end
        end,
    
        [Roact.Event.InputBegan] = function(_rbx, input)
          if active and input.UserInputType == Enum.UserInputType.MouseButton1 then
            self:setState({
              Pressed = true,
            })
          end
        end,
    
        [Roact.Event.InputEnded] = function(_rbx, input)
          if active and input.UserInputType == Enum.UserInputType.MouseButton1 then
            self:setState({
              Pressed = false,
            })
          end
        end
      }
    
      if active then
        if self.props.ShowPressed and self.state.Pressed then
          backgroundProps.ImageColor3 = style.ButtonPressedColor
        else
          backgroundProps.ImageColor3 = hovering and style.ButtonHoverColor or style.ButtonColor
        end
      else
        backgroundProps.ImageColor3 = style.ButtonDisabledColor
      end

      return Roact.createElement("ImageButton", backgroundProps, {
        Border = Roact.createElement("ImageLabel", {
          Size = UDim2.new(1, 0, 1, 0),
          BackgroundTransparency = 1,
          Image = "rbxasset://textures/StudioToolbox/RoundedBorder.png",
          ImageColor3 = match and backgroundProps.ImageColor3 or style.BorderColor,
          ScaleType = Enum.ScaleType.Slice,
          SliceCenter = Rect.new(3, 3, 13, 13),
          ZIndex = self.props.ZIndex or 1,
        }),
  
        Text = Roact.createElement("TextLabel", {
          Size = UDim2.new(1, 0, 1, 0),
          BackgroundTransparency = 1,
          BorderSizePixel = 0,
          Font = Enum.Font.SourceSans,
          TextColor3 = active and style.TextColor or style.TextDisabledColor,
          TextSize = 22,
          Text = self.props.Name,
          ZIndex = self.props.ZIndex or 1,
        }),
      })
    end
  })
end

return RoundTextButton