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.Component:extend("\084\111\111\108\098\097\114\066\117\116\116\111\110")local f=require(script.Parent.Tooltip)function c.init(D)D:setState({hovered=false})end function c.render(D)return o.createElement(m.Consumer,{render=function(m)local c={LayoutOrder=D.props.LayoutOrder;Size=UDim2.fromScale(1,1);BackgroundColor3=m:GetColor(Enum.StudioStyleGuideColor.RibbonButton,D.props.IsSelected and Enum.StudioStyleGuideModifier.Selected or Enum.StudioStyleGuideModifier.Default),BorderSizePixel=0;[o.Event.Activated]=D.props.OnClick;[o.Event.MouseEnter]=function()D:setState({hovered=true})end,[o.Event.MouseLeave]=function()D:setState({hovered=false})end}if D.props.type=="\073\109\097\103\101\066\117\116\116\111\110"then c.Image=D.props.Image c.ImageColor3=m:GetColor(Enum.StudioStyleGuideColor.TitlebarText)else c.Text=D.props.Text c.TextColor3=m:GetColor(Enum.StudioStyleGuideColor.TitlebarText)c.RichText=true end return o.createElement(D.props.type or"\084\101\120\116\066\117\116\116\111\110",c,{AspectRatio=o.createElement("\085\073\065\115\112\101\099\116\082\097\116\105\111\067\111\110\115\116\114\097\105\110\116"),ToolTip=D.props.Tooltip and o.createElement(f,{Text=D.props.Tooltip;TextSize=14;Position=UDim2.new(0,5,1,5);RichText=true,ZIndex=5;Visible=D.state.hovered})or nil})end})end return c
local TextEditor = script:FindFirstAncestor("TextEditor")
local Roact = require(TextEditor.Packages.Roact)

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

function ToolbarButton:init()
  self:setState({
    hovered = false,
  })
end

function ToolbarButton:render()
  return Roact.createElement(StudioThemeContext.Consumer, {
    render = function(theme)
      local elementProps = {
        LayoutOrder = self.props.LayoutOrder,
        Size = UDim2.fromScale(1, 1),
        BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.RibbonButton, self.props.IsSelected and Enum.StudioStyleGuideModifier.Selected or Enum.StudioStyleGuideModifier.Default),
        BorderSizePixel = 0,

        [Roact.Event.Activated] = self.props.OnClick,
        [Roact.Event.MouseEnter] = function()
          self:setState({ hovered = true })
        end,
        [Roact.Event.MouseLeave] = function()
          self:setState({ hovered = false })
        end,
      }

      if self.props.type == "ImageButton" then
        elementProps.Image = self.props.Image
        elementProps.ImageColor3 = theme:GetColor(Enum.StudioStyleGuideColor.TitlebarText)
      else
        elementProps.Text = self.props.Text
        elementProps.TextColor3 = theme:GetColor(Enum.StudioStyleGuideColor.TitlebarText)
        elementProps.RichText = true
      end

      return Roact.createElement(self.props.type or "TextButton", elementProps, {
        AspectRatio = Roact.createElement("UIAspectRatioConstraint"),

        ToolTip = self.props.Tooltip and Roact.createElement(Tooltip, {
          Text = self.props.Tooltip,
          TextSize = 14,
          Position = UDim2.new(0, 5, 1, 5),
          RichText = true,
          ZIndex = 5,
          Visible = self.state.hovered,
        }) or nil
      })
    end
  })
end

return ToolbarButton