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=require(script.Parent.TextLabel)local f=o.Component:extend("\083\101\099\116\105\111\110")function f.init(D)D.lastClickTime=0 D.mainSizeY,D.updateMainSizeY=o.createBinding(0)D.contentsSizeY,D.updateContentsSizeY=o.createBinding(0)D.minimized,D.updateMinimized=o.createBinding(false)end function f.render(D)local f=D.props[o.Children]f.Layout=o.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder;[o.Change.AbsoluteContentSize]=function(o)D.updateContentsSizeY(o.AbsoluteContentSize.Y)end})return o.createElement(m.Consumer,{render=function(m)return o.createElement("\070\114\097\109\101",{LayoutOrder=D.props.LayoutOrder;BackgroundTransparency=1,Size=D.mainSizeY:map(function(D)return UDim2.new(1,0,0,D)end)},{ListLayout=o.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder,[o.Change.AbsoluteContentSize]=function(o)D.updateMainSizeY(o.AbsoluteContentSize.Y)end}),TitleBar=o.createElement("\073\109\097\103\101\066\117\116\116\111\110",{LayoutOrder=1,BorderSizePixel=0,Size=UDim2.new(1,0,0,27);BackgroundColor3=m:GetColor(Enum.StudioStyleGuideColor.Titlebar);[o.Event.MouseButton1Down]=function()local o=tick()if o-D.lastClickTime<.5 then D.updateMinimized(not D.minimized:getValue())D.lastClickTime=0 else D.lastClickTime=o end end},{Label=o.createElement(c,{Text=D.props.Title,Font=Enum.Font.SourceSansBold;TextSize=15,TextXAlignment=Enum.TextXAlignment.Left,Position=UDim2.new(0,27,0,0),Size=UDim2.new(1,-27,1,-3)}),Button=o.createElement("\073\109\097\103\101\066\117\116\116\111\110",{Image=D.minimized:map(function(D)return D and"\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\084\101\114\114\097\105\110\084\111\111\108\115\047\098\117\116\116\111\110\095\097\114\114\111\119\046\112\110\103"or"\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\084\101\114\114\097\105\110\084\111\111\108\115\047\098\117\116\116\111\110\095\097\114\114\111\119\095\100\111\119\110\046\112\110\103"end);Size=UDim2.fromOffset(9,9),AnchorPoint=Vector2.new(.5,.5);Position=UDim2.new(0,13.5,0,13.5);BackgroundTransparency=1;[o.Event.Activated]=function()D.updateMinimized(not D.minimized:getValue())end})});Contents=o.createElement("\070\114\097\109\101",{LayoutOrder=2;BackgroundTransparency=1,Size=D.contentsSizeY:map(function(D)return UDim2.new(1,0,0,D)end);Visible=D.minimized:map(function(D)return not D end)},f)})end})end return f
local TextEditor = script:FindFirstAncestor("TextEditor")
local Roact = require(TextEditor.Packages.Roact)

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

function Section:init()
  self.lastClickTime = 0
  self.mainSizeY, self.updateMainSizeY = Roact.createBinding(0)
  self.contentsSizeY, self.updateContentsSizeY = Roact.createBinding(0)
  self.minimized, self.updateMinimized = Roact.createBinding(false)
end

function Section:render()
  local ContentsChildren = self.props[Roact.Children]
  ContentsChildren.Layout = Roact.createElement("UIListLayout", {
    SortOrder = Enum.SortOrder.LayoutOrder,
    [Roact.Change.AbsoluteContentSize] = function(rbx)
      self.updateContentsSizeY(rbx.AbsoluteContentSize.Y)
    end,
  })

  return Roact.createElement(StudioThemeContext.Consumer, {
    render = function(theme)
      return Roact.createElement("Frame", {
        LayoutOrder = self.props.LayoutOrder,
        BackgroundTransparency = 1,
        Size = self.mainSizeY:map(function(value)
          return UDim2.new(1, 0, 0, value)
        end),
      }, {
        ListLayout = Roact.createElement("UIListLayout", {
          SortOrder = Enum.SortOrder.LayoutOrder,
          [Roact.Change.AbsoluteContentSize] = function(rbx)
            self.updateMainSizeY(rbx.AbsoluteContentSize.Y)
          end,
        }),

        TitleBar = Roact.createElement("ImageButton", {
          LayoutOrder = 1,
          -- AutoButtonColor = false,
          BorderSizePixel = 0,
          Size = UDim2.new(1, 0, 0, 27),
          BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.Titlebar),
          [Roact.Event.MouseButton1Down] = function()
            local now = tick()
            if now - self.lastClickTime < 0.5 then
              self.updateMinimized(not self.minimized:getValue())
              self.lastClickTime = 0
            else
              self.lastClickTime = now
            end
          end,
        }, {
          Label = Roact.createElement(ThemedTextLabel, {
            Text = self.props.Title,
            Font = Enum.Font.SourceSansBold,
            TextSize = 15,
            TextXAlignment = Enum.TextXAlignment.Left,
            Position = UDim2.new(0, 27, 0, 0),
            Size = UDim2.new(1, -27, 1, -3),
          }),

          Button = Roact.createElement("ImageButton", {
            Image = self.minimized:map(function(value)
              return value and "rbxasset://textures/TerrainTools/button_arrow.png" or "rbxasset://textures/TerrainTools/button_arrow_down.png"
            end),
            Size = UDim2.fromOffset(9, 9),
            AnchorPoint = Vector2.new(0.5, 0.5),
            Position = UDim2.new(0, 27 / 2, 0, 27 / 2),
            BackgroundTransparency = 1,
            [Roact.Event.Activated] = function()
              self.updateMinimized(not self.minimized:getValue())
            end,
          })
        }),

        Contents = Roact.createElement("Frame", {
          LayoutOrder = 2,
          BackgroundTransparency = 1,
          Size = self.contentsSizeY:map(function(value)
            return UDim2.new(1, 0, 0, value)
          end),
          Visible = self.minimized:map(function(value)
            return not value
          end),
        }, ContentsChildren)
      })
    end
  })
end

return Section