local h=script.Parent.Parent local z=require(h.Vendor.Roact)local r=require(h.Vendor.StudioComponents)local k=r.Widget local P=r.Label local x=r.TextInput local w=r.Button local D=r.MainButton local t=z.Component:extend("\076\097\121\101\114\087\105\100\103\101\116")function t.init(h)h:setState({LastText="\076\097\121\101\114 "..#h.props.Layers+1})h.setLastText=function(z)h:setState({LastText=z})end end function t.render(h)local r=h.state.LastText local t=h.props.Layers local X=true local O=nil if#r==0 then X=false elseif#r>20 then X=false O="\078\097\109\101 \116\111\111 \108\111\110\103"else for h,z in ipairs(t)do if z.name==r then X=false O="\078\097\109\101 \097\108\114\101\097\100\121 \117\115\101\100"break end end end return z.createElement(k,{Id="\099\114\101\097\116\101\076\097\121\101\114\087\105\100\103\101\116",Name="\099\114\101\097\116\101\076\097\121\101\114\087\105\100\103\101\116",Title=h.props.Title,InitialDockState=Enum.InitialDockState.Float;MinimumWindowSize=Vector2.new(185,85);OnClosed=h.props.OnClosed},{Padding=z.createElement("\085\073\080\097\100\100\105\110\103",{PaddingLeft=UDim.new(0,7),PaddingRight=UDim.new(0,7),PaddingTop=UDim.new(0,7);PaddingBottom=UDim.new(0,4)}),Label=z.createElement(P,{Size=UDim2.fromOffset(31,20);Text="\078\097\109\101";TextXAlignment=Enum.TextXAlignment.Left,TextTruncate=Enum.TextTruncate.AtEnd});InputHolder=z.createElement("\070\114\097\109\101",{Position=UDim2.fromOffset(38,0);Size=UDim2.new(1,-38,0,20);BackgroundTransparency=1},{Input=z.createElement(x,{ClearTextOnFocus=false;PlaceholderText="\069\110\116\101\114 \110\097\109\101",Text=h.state.LastText;OnChanged=h.setLastText,OnFocusLost=function(z)if z and X then h.props.OnSubmitted(r)end end})});Message=O and z.createElement(P,{Position=UDim2.fromOffset(38,21),Size=UDim2.new(1,-38,0,20),Text=O;TextXAlignment=Enum.TextXAlignment.Left,TextTruncate=Enum.TextTruncate.AtEnd,TextColorStyle=Enum.StudioStyleGuideColor.ErrorText}),Buttons=z.createElement("\070\114\097\109\101",{AnchorPoint=Vector2.new(0,1),Position=UDim2.fromScale(0,1);Size=UDim2.new(1,0,0,28);BackgroundTransparency=1},{Layout=z.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder,FillDirection=Enum.FillDirection.Horizontal,HorizontalAlignment=Enum.HorizontalAlignment.Right;Padding=UDim.new(0,4)}),CreateButton=z.createElement(D,{LayoutOrder=2;Size=UDim2.new(0,65,1,0);Text="\067\114\101\097\116\101";Disabled=not X;OnActivated=function()h.props.OnSubmitted(r)end});CancelButton=z.createElement(w,{LayoutOrder=1,Size=UDim2.new(0,65,1,0);Text="\067\097\110\099\101\108",OnActivated=h.props.OnClosed})})})end return t
local Plugin = script.Parent.Parent

local Roact = require(Plugin.Vendor.Roact)
local StudioComponents = require(Plugin.Vendor.StudioComponents)

local Widget = StudioComponents.Widget
local Label = StudioComponents.Label
local TextInput = StudioComponents.TextInput
local Button = StudioComponents.Button
local MainButton = StudioComponents.MainButton

local LayerWidget = Roact.Component:extend("LayerWidget")

function LayerWidget:init()
	self:setState({ LastText = "Layer " .. #self.props.Layers + 1 })

	self.setLastText = function(LastText)
		self:setState({ LastText = LastText })
	end
end

function LayerWidget:render()
	local lastText = self.state.LastText
	local layers = self.props.Layers

	local valid = true
	local message = nil
	if #lastText == 0 then
		valid = false
	elseif #lastText > 20 then
		valid = false
		message = "Name too long"
	else
		for _, group in ipairs(layers) do
			if group.name == lastText then
				valid = false
				message = "Name already used"
				break
			end
		end
	end

	return Roact.createElement(Widget, {
		Id = "createLayerWidget",
		Name = "createLayerWidget",
		Title = self.props.Title,
		InitialDockState = Enum.InitialDockState.Float,
		MinimumWindowSize = Vector2.new(185, 85),
		OnClosed = self.props.OnClosed
	}, {
		Padding = Roact.createElement("UIPadding", {
			PaddingLeft = UDim.new(0, 7),
			PaddingRight = UDim.new(0, 7),
			PaddingTop = UDim.new(0, 7),
			PaddingBottom = UDim.new(0, 4),
		}),
		Label = Roact.createElement(Label, {
			Size = UDim2.fromOffset(31, 20),
			Text = "Name",
			TextXAlignment = Enum.TextXAlignment.Left,
			TextTruncate = Enum.TextTruncate.AtEnd,
		}),
		InputHolder = Roact.createElement("Frame", {
			Position = UDim2.fromOffset(38, 0),
			Size = UDim2.new(1, -38, 0, 20),
			BackgroundTransparency = 1,
		}, {
			Input = Roact.createElement(TextInput, {
				ClearTextOnFocus = false,
				PlaceholderText = "Enter name",
				Text = self.state.LastText,
				OnChanged = self.setLastText,
				OnFocusLost = function(enterPressed)
					if enterPressed and valid then
						self.props.OnSubmitted(lastText)
					end
				end,
			}),
		}),
		Message = message and Roact.createElement(Label, {
			Position = UDim2.fromOffset(38, 21),
			Size = UDim2.new(1, -38, 0, 20),
			Text = message,
			TextXAlignment = Enum.TextXAlignment.Left,
			TextTruncate = Enum.TextTruncate.AtEnd,
			TextColorStyle = Enum.StudioStyleGuideColor.ErrorText,
		}),
		Buttons = Roact.createElement("Frame", {
			AnchorPoint = Vector2.new(0, 1),
			Position = UDim2.fromScale(0, 1),
			Size = UDim2.new(1, 0, 0, 28),
			BackgroundTransparency = 1,
		}, {
			Layout = Roact.createElement("UIListLayout", {
				SortOrder = Enum.SortOrder.LayoutOrder,
				FillDirection = Enum.FillDirection.Horizontal,
				HorizontalAlignment = Enum.HorizontalAlignment.Right,
				Padding = UDim.new(0, 4),
			}),
			CreateButton = Roact.createElement(MainButton, {
				LayoutOrder = 2,
				Size = UDim2.new(0, 65, 1, 0),
				Text = "Create",
				Disabled = not valid,
				OnActivated = function()
					self.props.OnSubmitted(lastText)
				end,
			}),
			CancelButton = Roact.createElement(Button, {
				LayoutOrder = 1,
				Size = UDim2.new(0, 65, 1, 0),
				Text = "Cancel",
				OnActivated = self.props.OnClosed,
			}),
		})
	})
end

return LayerWidget