local z=script.Parent.Parent local a=require(z.Creator)local h=a.New local n=a.AddSignal local P=z.Components local f={}f.__index=f f.__type="\073\110\112\117\116"function f.New(h,z,a)local f=h.Library assert(a.Title,"\073\110\112\117\116 - \077\105\115\115\105\110\103 \084\105\116\108\101")a.Callback=a.Callback or function() end local M={Value=a.Default or"";Numeric=a.Numeric or false;Finished=a.Finished or false;Callback=a.Callback or function(z) end;Type="\073\110\112\117\116"}local B=(require(P.Element))(a.Title,a.Description,h.Container,false)M.SetTitle=B.SetTitle M.SetDesc=B.SetDesc local s=(require(P.Textbox))(B.Frame,true)s.Frame.Position=UDim2.new(1,-10,.5,0)s.Frame.AnchorPoint=Vector2.new(1,.5)s.Frame.Size=UDim2.fromOffset(160,30)s.Input.Text=a.Default or""s.Input.PlaceholderText=a.Placeholder or""local U=s.Input function M.SetValue(h,z)if a.MaxLength and#z>a.MaxLength then z=z:sub(1,a.MaxLength)end if M.Numeric then if not tonumber(z)and z:len()>0 then z=M.Value end end M.Value=z U.Text=z f:SafeCallback(M.Callback,M.Value)f:SafeCallback(M.Changed,M.Value)end if M.Finished then n(U.FocusLost,function(z)if not z then return end M:SetValue(U.Text)end)else n(U:GetPropertyChangedSignal("\084\101\120\116"),function()M:SetValue(U.Text)end)end function M.OnChanged(a,z)M.Changed=z z(M.Value)end function M.Destroy(a)B:Destroy()f.Options[z]=nil end f.Options[z]=M return M end return f
local Root = script.Parent.Parent
local Creator = require(Root.Creator)

local New = Creator.New
local AddSignal = Creator.AddSignal
local Components = Root.Components

local Element = {}
Element.__index = Element
Element.__type = "Input"

function Element:New(Idx, Config)
	local Library = self.Library
	assert(Config.Title, "Input - Missing Title")
	Config.Callback = Config.Callback or function() end

	local Input = {
		Value = Config.Default or "",
		Numeric = Config.Numeric or false,
		Finished = Config.Finished or false,
		Callback = Config.Callback or function(Value) end,
		Type = "Input",
	}

	local InputFrame = require(Components.Element)(Config.Title, Config.Description, self.Container, false)

	Input.SetTitle = InputFrame.SetTitle
	Input.SetDesc = InputFrame.SetDesc

	local Textbox = require(Components.Textbox)(InputFrame.Frame, true)
	Textbox.Frame.Position = UDim2.new(1, -10, 0.5, 0)
	Textbox.Frame.AnchorPoint = Vector2.new(1, 0.5)
	Textbox.Frame.Size = UDim2.fromOffset(160, 30)
	Textbox.Input.Text = Config.Default or ""
	Textbox.Input.PlaceholderText = Config.Placeholder or ""

	local Box = Textbox.Input

	function Input:SetValue(Text)
		if Config.MaxLength and #Text > Config.MaxLength then
			Text = Text:sub(1, Config.MaxLength)
		end

		if Input.Numeric then
			if (not tonumber(Text)) and Text:len() > 0 then
				Text = Input.Value
			end
		end

		Input.Value = Text
		Box.Text = Text

		Library:SafeCallback(Input.Callback, Input.Value)
		Library:SafeCallback(Input.Changed, Input.Value)
	end

	if Input.Finished then
		AddSignal(Box.FocusLost, function(enter)
			if not enter then
				return
			end
			Input:SetValue(Box.Text)
		end)
	else
		AddSignal(Box:GetPropertyChangedSignal("Text"), function()
			Input:SetValue(Box.Text)
		end)
	end

	function Input:OnChanged(Func)
		Input.Changed = Func
		Func(Input.Value)
	end

	function Input:Destroy()
		InputFrame:Destroy()
		Library.Options[Idx] = nil
	end

	Library.Options[Idx] = Input
	return Input
end

return Element
