local m=script.Parent.Parent return function(Y)local n=require(m.Bundles)local k=n.data local h=n.themeSystem local P=n.icons local A=n.flags local L=n.Fusion local u=L.New local K=L.Children local X=L.Value local V=L.Computed local S=L.Observer local s=L.Ref local g=L.OnEvent local p=require(m.utilities)local c=p.get local O=p.animate local l=p.customFont local o=p.typecheck local G=require(m.simpleElements)local b=G.UIPadding local J=G.UICorner local N=G.UITextSizeConstraint local t=G.UIListLayout local j=Enum.SortOrder local a=Enum.VerticalAlignment local F=Enum.HorizontalAlignment local U=Enum.FillDirection local E,v=o(Y,{Name="";DisabledText="",IsEnabled=false;Visible=false;Callback=function() end,FLAG="";PlaceHolderText="",ClearTextOnFocus=false,OnlyNumbers=true,OnLeave=true,Default="";IgnoreConfig=true},{Y.DisabledText and""or"\068\105\115\097\098\108\101\100\084\101\120\116";Y.IsEnabled and""or"\073\115\069\110\097\098\108\101\100",Y.Visible and""or"\086\105\115\105\098\108\101",Y.PlaceHolderText and""or"\080\108\097\099\101\072\111\108\100\101\114\084\101\120\116";Y.ClearTextOnFocus and""or"\067\108\101\097\114\084\101\120\116\079\110\070\111\099\117\115";Y.OnlyNumbers and""or"\079\110\108\121\078\117\109\098\101\114\115";Y.OnLeave and""or"\079\110\076\101\097\118\101",Y.Default and""or"\068\101\102\097\117\108\116",Y.FLAG and""or"\070\076\065\071",Y.IgnoreConfig and""or"\073\103\110\111\114\101\067\111\110\102\105\103"})assert(E,table.concat(v,"\n"))local z=k.find("\115\101\108\101\099\116\101\100\084\097\098")local B=k.find("\117\115\101\067\111\110\102\105\103")local e=k.find("\115\101\097\114\099\104\084\101\120\116")local d=k.add(Y)local R=Y.Parent local Z=Y.Name local M=Y.DisabledText or X("\067\111\109\112\111\110\101\110\116 \068\105\115\097\098\108\101\100")local C=Y.IsEnabled or X(true)local I=Y.Visible or X(true)local i=Y.Callback local H=Y.OnlyNumbers or X(false)local Q=Y.Default or X("")local f=Y.OnLeave or X(false)local D=Y.ClearTextOnFocus or X(false)local T=Y.IgnoreConfig or X(false)local r=Y.PlaceHolderText or X("")local w=Y.FLAG or X(d.uid)local W if c(w)~=""then W=A.register(c(w),{correctText=X("")},"\116\101\120\116\098\111\120",c(w)==d.uid)W.user.Value=c(W.status.correctText)end local y=X(c(z.string)==(c(d.tab)).uid);(S(z.string)):onChange(function()y:set(c(z.string)==(c(d.tab)).uid)end)local x=O(function()return c(y)and 0 or 1 end,40,1)local q=X()local mv=X(false)local Yv=X("")local nv=X(c(W.status.correctText))local kv=X("")local hv=X(false);(S(Yv)):onChange(function()if c(H)then if tonumber(c(Yv))or c(Yv)==""then nv:set(c(Yv))end else nv:set(c(Yv))end local m=c(q)m.Text=c(nv)if c(f)then return end if c(H)then if(tonumber(c(Yv))or c(Yv)=="")and c(kv)~=c(Yv)then task.spawn(c(i),c(Yv))W.status.correctText:set(c(Yv))kv:set(c(Yv))end else if c(kv)==c(Yv)then return end task.spawn(c(i),c(Yv))W.status.correctText:set(c(Yv))kv:set(c(Yv))end end);(S(mv)):onChange(function()if c(f)and not c(mv)then if c(H)then if(tonumber(c(Yv))or c(Yv)=="")and c(kv)~=c(Yv)then task.spawn(c(i),c(Yv))W.status.correctText:set(c(Yv))kv:set(c(Yv))end else if c(kv)==c(Yv)then return end task.spawn(c(i),c(Yv))W.status.correctText:set(c(Yv))kv:set(c(Yv))end end end)local Pv=X()local Av=X(0);(u("\070\114\097\109\101"))({Parent=R;Visible=V(function()if c(e.string)~=""and not string.find((c(Z)):lower(),(c(e.string)):lower())or not c(I)then return false end return true end),BackgroundTransparency=1,Size=UDim2.new(1,0,0,36),[K]={(u("\070\114\097\109\101"))({ZIndex=2;Visible=V(function()if not c(C)then return true end return false end),BackgroundTransparency=O(function()return c(y)and.2 or 1 end,40,1);BackgroundColor3=h.disabledBackground;Size=UDim2.fromScale(1,1);[K]={J(6);(u("\073\109\097\103\101\076\097\098\101\108"))({Size=UDim2.fromOffset(24,24),AnchorPoint=Vector2.new(0,.5);Position=UDim2.new(0,5,.5,0);BackgroundTransparency=1;Image=P.lock;ImageColor3=h.disabledText;ImageTransparency=x});(u("\084\101\120\116\076\097\098\101\108"))({FontFace=l("\077\111\110\116\115\101\114\114\097\116",Enum.FontWeight.Bold);BackgroundTransparency=1;Size=UDim2.new(1,-24,0,18),TextColor3=h.disabledText;TextTransparency=x;TextScaled=true,AnchorPoint=Vector2.new(0,.5),Position=UDim2.new(0,29,.5,0);Text=V(function()return c(M)end);TextXAlignment=Enum.TextXAlignment.Left;RichText=true,[K]={b(0,5)}})}}),(u("\070\114\097\109\101"))({Size=UDim2.fromScale(1,1);BackgroundTransparency=1;[K]={t(j.LayoutOrder,U.Horizontal,F.Left,a.Center,UDim.new(0,3)),(u("\084\101\120\116\076\097\098\101\108"))({Size=UDim2.fromScale(0,1),BackgroundColor3=h.background2,BackgroundTransparency=x,TextSize=18;Text=Z;AutomaticSize=Enum.AutomaticSize.X,TextTransparency=x;TextXAlignment=Enum.TextXAlignment.Left;RichText=true;TextColor3=h.text;FontFace=l("\077\111\110\116\115\101\114\114\097\116",Enum.FontWeight.Bold),[g("\067\104\097\110\103\101\100")]=function(m)if m=="\065\098\115\111\108\117\116\101\083\105\122\101"and c(Pv)~=nil then Av:set((c(Pv)).AbsoluteSize.X)end end,[s]=Pv;[K]={J(6);b(0,6)}}),(u("\084\101\120\116\066\117\116\116\111\110"))({Interactable=V(function()if not c(C)then return false end return c(y)end);Size=V(function()if c(Pv)then return UDim2.new(1,-c(Av)-3,1)end return UDim2.fromScale(.35,1)end),BackgroundColor3=h.background2,BackgroundTransparency=x;[g("\065\099\116\105\118\097\116\101\100")]=function()local m=c(q)if m then m:CaptureFocus()end end,[K]={J(6),b(0,6),t(j.LayoutOrder,U.Horizontal,F.Left,a.Center,UDim.new(0,5));(u("\073\109\097\103\101\076\097\098\101\108"))({ZIndex=0,Size=UDim2.fromOffset(20,20);BackgroundTransparency=1,Image=P.input;ImageColor3=h.text2;ImageTransparency=x});(u("\084\101\120\116\066\111\120"))({Interactable=V(function()if not c(C)then return false end return c(y)end);ClipsDescendants=true,Size=UDim2.new(1,-25,1,0);BackgroundTransparency=1;PlaceholderText=r;PlaceholderColor3=h.text2,TextColor3=h.text;TextSize=16,TextXAlignment=Enum.TextXAlignment.Left;FontFace=l("\077\111\110\116\115\101\114\114\097\116",Enum.FontWeight.Bold),Text=nv,TextTransparency=x,ClearTextOnFocus=D,[s]=q;[g("\067\104\097\110\103\101\100")]=function(m)local Y=c(q)if Y.TextBounds.X>Y.AbsoluteSize.X then hv:set(true)end if Y and(Y.Text and m=="\084\101\120\116")then Yv:set(Y.Text)end end;[g("\070\111\099\117\115\101\100")]=function()mv:set(true)end;[g("\070\111\099\117\115\076\111\115\116")]=function()mv:set(false)end,[K]={(u("\070\114\097\109\101"))({Size=UDim2.fromScale(1,1);BackgroundTransparency=0;[K]={(u("\085\073\071\114\097\100\105\101\110\116"))({Rotation=0;Color=O(function()return ColorSequence.new({ColorSequenceKeypoint.new(0,h.get("\098\097\099\107\103\114\111\117\110\100\050")),ColorSequenceKeypoint.new(1,h.get("\098\097\099\107\103\114\111\117\110\100\050"))})end,40,1),Transparency=O(function()if not c(y)then return NumberSequence.new({NumberSequenceKeypoint.new(0,1),NumberSequenceKeypoint.new(.5,1);NumberSequenceKeypoint.new(1,1)})end if c(hv)then if c(mv)then return NumberSequence.new({NumberSequenceKeypoint.new(0,0),NumberSequenceKeypoint.new(.1,1),NumberSequenceKeypoint.new(1,1)})else return NumberSequence.new({NumberSequenceKeypoint.new(0,1);NumberSequenceKeypoint.new(.9,1),NumberSequenceKeypoint.new(1,0)})end end return NumberSequence.new({NumberSequenceKeypoint.new(0,1);NumberSequenceKeypoint.new(1,1)})end,40,1)})}})}})}})}})}})if c(B.boolean)and not c(T)then W.file:Connect(function(m)local Y=true if m~=nil then if c(f)then mv:set(true)end Yv:set(m)if c(f)then mv:set(false)end Y=false end if Y then if c(f)then mv:set(true)end Yv:set(c(Q))if c(f)then mv:set(false)end end end)if W.private then if c(f)then mv:set(true)end Yv:set(c(Q))if c(f)then mv:set(false)end end else if c(f)then mv:set(true)end Yv:set(c(Q))if c(f)then mv:set(false)end end if W.preregistered and W.preregisteredValue then E,v=o({FlagValue=W.preregisteredValue},{FlagValue=""})if E then if c(f)then mv:set(true)end Yv:set(W.preregisteredValue)if c(f)then mv:set(false)end end end local Lv={}function Lv.SetName(Y,m)local n,k=o({SetName=m},{SetName=""})assert(n,table.concat(k,"\n"))Z:set(m)end function Lv.SetInput(Y,m)local n,k=o({SetInput=m},{SetInput=c(H)and 1 or""})assert(n,table.concat(k,"\n"))Yv:set(m)end function Lv.Enable(m)C:set(true)end function Lv.Disable(m)C:set(false)end function Lv.Visible(m)I:set(true)end function Lv.Invisible(m)I:set(false)end return Lv end
local darius = script.Parent.Parent
return function(property)
	local bundles = require(darius.Bundles)
	local data = bundles.data
	local theme = bundles.themeSystem
	local icons = bundles.icons
	local flagCreator = bundles.flags
	local Fusion = bundles.Fusion
		local new = Fusion.New
		local children = Fusion.Children
		local value = Fusion.Value
		local computed = Fusion.Computed
		local observe = Fusion.Observer
		local ref = Fusion.Ref
		local onevent = Fusion.OnEvent

	local utilities = require(darius.utilities)
	local get = utilities.get
	local animate = utilities.animate
	local customFont = utilities.customFont
	local typecheck = utilities.typecheck

	local simpleElements = require(darius.simpleElements)
	local UIPadding = simpleElements.UIPadding
	local UICorner = simpleElements.UICorner
	local UITextSizeConstraint = simpleElements.UITextSizeConstraint
	local UIListLayout = simpleElements.UIListLayout
	local SO = Enum.SortOrder
	local VA = Enum.VerticalAlignment
	local HA = Enum.HorizontalAlignment
	local FD = Enum.FillDirection

	-- Typecheck

	local didPass, failedItems = typecheck(property,{
		Name = "",
		DisabledText = "",
		IsEnabled = false,
		Visible = false,
		Callback = function()end,

		FLAG = "",
        PlaceHolderText = "",
        ClearTextOnFocus = false,
        OnlyNumbers = true,
        OnLeave = true,
        Default = "",
		IgnoreConfig = true
	},{
		property.DisabledText and "" or "DisabledText",
		property.IsEnabled and "" or "IsEnabled",
		property.Visible and "" or "Visible",

		property.PlaceHolderText and "" or "PlaceHolderText",
		property.ClearTextOnFocus and "" or "ClearTextOnFocus",
		property.OnlyNumbers and "" or "OnlyNumbers",
		property.OnLeave and "" or "OnLeave",
		property.Default and "" or "Default",
		property.FLAG and "" or "FLAG",
		property.IgnoreConfig and "" or "IgnoreConfig"
	})
	assert(didPass, table.concat(failedItems, "\n"))

	-- Data

	local selectedTab = data.find("selectedTab")
	local useConfig = data.find("useConfig")
	local searchText = data.find("searchText")
	local textbox = data.add(property)

	-- Properties

	local _parent = property.Parent
	local name = property.Name
	local disabledText = property.DisabledText or value("Component Disabled")
	local isEnabled = property.IsEnabled or value(true)
	local visible = property.Visible or value(true)
	local callback = property.Callback

	local onlyNumbers = property.OnlyNumbers or value(false)
	local default = property.Default or value("")
	local onLeave = property.OnLeave or value(false)
	local clearTextOnFocus = property.ClearTextOnFocus or value(false)
	local ignoreConfig = property.IgnoreConfig or value(false)
	local placeHolder = property.PlaceHolderText or value("")

	local flag = property.FLAG or value(textbox.uid)
	local _flag
	if get(flag) ~= "" then
		_flag = flagCreator.register(get(flag), {
			correctText = value(""),
		},"textbox", get(flag) == textbox.uid)
		_flag.user.Value = get(_flag.status.correctText)
	end

	-- Variables

	local isSelected = value(get(selectedTab.string) == get(textbox.tab).uid)
	observe(selectedTab.string):onChange(function()
		isSelected:set(get(selectedTab.string) == get(textbox.tab).uid)
	end)
	local selectedAnimation = animate(function()
		return get(isSelected) and 0 or 1
	end, 40, 1)
	local textboxRef = value()
	local focused = value(false)
	local correctText = value("")
	local lastCorrectText = value(get(_flag.status.correctText))
	local lastCalled = value("")
	local largerThanBox = value(false)

	observe(correctText):onChange(function()
		if get(onlyNumbers) then
			if tonumber(get(correctText)) or get(correctText) == "" then
				lastCorrectText:set(get(correctText))
			end
		else
			lastCorrectText:set(get(correctText))
		end
		local textBox = get(textboxRef)
		textBox.Text = get(lastCorrectText)
		if get(onLeave) then
			return
		end
		if get(onlyNumbers) then
			if (tonumber(get(correctText)) or get(correctText) == "") and get(lastCalled) ~= get(correctText) then
				task.spawn(get(callback), get(correctText))
				_flag.status.correctText:set(get(correctText))
				lastCalled:set(get(correctText))
			end
		else
			if get(lastCalled) == get(correctText) then
				return
			end
			task.spawn(get(callback), get(correctText))
			_flag.status.correctText:set(get(correctText))
			lastCalled:set(get(correctText))
		end
	end)
	observe(focused):onChange(function()
		if get(onLeave) and not get(focused) then
			if get(onlyNumbers) then
				if (tonumber(get(correctText)) or get(correctText) == "") and get(lastCalled) ~= get(correctText) then
					task.spawn(get(callback), get(correctText))
					_flag.status.correctText:set(get(correctText))
					lastCalled:set(get(correctText))
				end
			else
				if get(lastCalled) == get(correctText) then
					return
				end
				task.spawn(get(callback), get(correctText))
				_flag.status.correctText:set(get(correctText))
				lastCalled:set(get(correctText))
			end
		end
	end)
	local titleTextLabel = value()
	local titleX = value(0)

	-- TextBox

	new "Frame" {
		Parent = _parent,
		Visible = computed(function()
			if get(searchText.string) ~= "" and not string.find(get(name):lower(), get(searchText.string):lower()) or not get(visible) then
				return false
			end
			return true
		end),
		BackgroundTransparency = 1,
		Size = UDim2.new(1,0,0,36),

		[children] = {
			new "Frame" { -- Disabled Frame
				ZIndex = 2,
				Visible = computed(function()
					if not get(isEnabled)  then
						return true
					end
					return false
				end),
				BackgroundTransparency = animate(function()
					return get(isSelected) and 0.2 or 1
				end,40,1),
				BackgroundColor3 = theme.disabledBackground,
				Size = UDim2.fromScale(1,1),

				[children] = {
					UICorner(6),
					new "ImageLabel" { -- Icon
						Size = UDim2.fromOffset(24,24),
						AnchorPoint = Vector2.new(0,0.5),
						Position = UDim2.new(0,5,0.5,0),
						BackgroundTransparency = 1,
						Image = icons.lock,
						ImageColor3 = theme.disabledText,
						ImageTransparency = selectedAnimation,
					},
					new "TextLabel" {
						FontFace = customFont("Montserrat", Enum.FontWeight.Bold),
						BackgroundTransparency = 1,
						Size = UDim2.new(1,-24,0,18),
						TextColor3 = theme.disabledText,
						TextTransparency = selectedAnimation,
						TextScaled = true,
						AnchorPoint = Vector2.new(0,0.5),
						Position = UDim2.new(0,29,0.5,0),
						Text = computed(function()
							return get(disabledText)
						end),
						TextXAlignment = Enum.TextXAlignment.Left,
						RichText = true,

						[children] = {
							UIPadding(0,5)
						}
					}
				}
			},
			new "Frame" {
				Size = UDim2.fromScale(1,1),
				BackgroundTransparency = 1,

				[children] = {
					UIListLayout(SO.LayoutOrder,FD.Horizontal,HA.Left,VA.Center,UDim.new(0,3)),
					new "TextLabel" {
						Size = UDim2.fromScale(0,1),
						BackgroundColor3 = theme.background2,
						BackgroundTransparency = selectedAnimation,
						TextSize = 18,
						Text = name,
						AutomaticSize = Enum.AutomaticSize.X,
						TextTransparency = selectedAnimation,
						TextXAlignment = Enum.TextXAlignment.Left,
						RichText = true,
						TextColor3 = theme.text,
						FontFace = customFont("Montserrat", Enum.FontWeight.Bold),
						[onevent "Changed"] = function(changedProperty)
							if changedProperty == "AbsoluteSize" and get(titleTextLabel) ~= nil then
								titleX:set(get(titleTextLabel).AbsoluteSize.X)
							end
						end,

						[ref] = titleTextLabel,

						[children] = {
							UICorner(6),
							UIPadding(0,6),
							--[[
							new "TextLabel" {
								
								Size = UDim2.new(0,0,0,18),
								BackgroundTransparency = 1,
								
								--TextScaled = true,
								

								

								[children] = {}
							}
								]]
						}
					},
					new "TextButton" {
						Interactable = computed(function()
							if not get(isEnabled) then
								return false
							end
							return get(isSelected)
						end),
						Size = computed(function()
							if get(titleTextLabel) then
								return UDim2.new(1,-get(titleX) - 3,1)
							end
							return UDim2.fromScale(0.35,1)
						end),
						BackgroundColor3 = theme.background2,
						BackgroundTransparency = selectedAnimation,

						[onevent "Activated"] = function()
							local _textbox = get(textboxRef)
							if _textbox then
								_textbox:CaptureFocus()
							end
						end,

						[children] = {
							UICorner(6),
							UIPadding(0,6),
							UIListLayout(SO.LayoutOrder,FD.Horizontal,HA.Left,VA.Center,UDim.new(0,5)),
							new "ImageLabel" {
								ZIndex = 0,
								Size = UDim2.fromOffset(20,20),
								BackgroundTransparency = 1,
								Image = icons.input,
								ImageColor3 = theme.text2,
								ImageTransparency = selectedAnimation
							},
							new "TextBox" {
								Interactable = computed(function()
									if not get(isEnabled) then
										return false
									end
									return get(isSelected)
								end),
								ClipsDescendants = true,
								Size = UDim2.new(1,-25,1,0),
								BackgroundTransparency = 1,
								PlaceholderText = placeHolder,
								PlaceholderColor3 = theme.text2,
								TextColor3 = theme.text,
								TextSize = 16,
								TextXAlignment = Enum.TextXAlignment.Left,
								FontFace = customFont("Montserrat", Enum.FontWeight.Bold),
								Text = lastCorrectText,
								TextTransparency = selectedAnimation,
								ClearTextOnFocus = clearTextOnFocus,

								[ref] = textboxRef,

								[onevent "Changed"] = function(changedProperty)
									local _textbox = get(textboxRef)
									if _textbox.TextBounds.X > _textbox.AbsoluteSize.X then
										largerThanBox:set(true)
									end
									if _textbox and _textbox.Text and changedProperty == "Text" then
										correctText:set(_textbox.Text)
									end
								end,

								[onevent "Focused"] = function()
									focused:set(true)
								end,
								[onevent "FocusLost"] = function()
									focused:set(false)
								end,

								[children] = {
									new "Frame" {
										Size = UDim2.fromScale(1,1),
										BackgroundTransparency = 0,

										[children] = {
											new "UIGradient" {
												Rotation = 0,
												Color = animate(function()
													return ColorSequence.new {
														ColorSequenceKeypoint.new(0, theme.get("background2")),
														ColorSequenceKeypoint.new(1, theme.get("background2"))
													}
												end,40,1),
												Transparency = animate(function()
													if not get(isSelected) then
														return NumberSequence.new {
															NumberSequenceKeypoint.new(0, 1),
															NumberSequenceKeypoint.new(0.5, 1),
															NumberSequenceKeypoint.new(1, 1)
														}
													end
													if get(largerThanBox) then
														if get(focused) then
															return NumberSequence.new {
																NumberSequenceKeypoint.new(0, 0),
																NumberSequenceKeypoint.new(0.1, 1),
																NumberSequenceKeypoint.new(1, 1)
															}
														else
															return NumberSequence.new {
																NumberSequenceKeypoint.new(0, 1),
																NumberSequenceKeypoint.new(0.9, 1),
																NumberSequenceKeypoint.new(1, 0)
															}
														end
													end
													return NumberSequence.new {
														NumberSequenceKeypoint.new(0, 1),
														NumberSequenceKeypoint.new(1, 1)
													}
												end,40,1)
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	-- Closure

	if get(useConfig.boolean) and not get(ignoreConfig) then
		_flag.file:Connect(function(file)
			local noCorrectText = true
			if file ~= nil then
				if get(onLeave) then
					focused:set(true)
				end
				correctText:set(file)
				if get(onLeave) then
					focused:set(false)
				end
				noCorrectText = false
			end
			if noCorrectText then
				if get(onLeave) then
					focused:set(true)
				end
				correctText:set(get(default))
				if get(onLeave) then
					focused:set(false)
				end
			end
		end)
		if _flag.private then
			if get(onLeave) then
				focused:set(true)
			end
			correctText:set(get(default))
			if get(onLeave) then
				focused:set(false)
			end
		end
	else
		if get(onLeave) then
			focused:set(true)
		end
		correctText:set(get(default))
		if get(onLeave) then
			focused:set(false)
		end
	end
	if _flag.preregistered and _flag.preregisteredValue then
		didPass, failedItems = typecheck({FlagValue = _flag.preregisteredValue},{FlagValue = ""})
		if didPass then
			if get(onLeave) then
				focused:set(true)
			end
			correctText:set(_flag.preregisteredValue)
			if get(onLeave) then
				focused:set(false)
			end
		end
	end

	local returnFunctions = {}
	function returnFunctions:SetName(newText)
		local _didPass, _failedItems = typecheck({['SetName'] = newText}, {SetName = ""})
		assert(_didPass, table.concat(_failedItems, "\n"))

		name:set(newText)
	end
	function returnFunctions:SetInput(newInput)
		local _didPass, _failedItems = typecheck({['SetInput'] = newInput}, {SetInput = get(onlyNumbers) and 1 or ""})
		assert(_didPass, table.concat(_failedItems, "\n"))

		correctText:set(newInput)
	end
	function returnFunctions:Enable()
		isEnabled:set(true)
	end
	function returnFunctions:Disable()
		isEnabled:set(false)
	end
	function returnFunctions:Visible()
		visible:set(true)
	end
	function returnFunctions:Invisible()
		visible:set(false)
	end
	return returnFunctions
end