local e={}e.default=function(e,J,B)local g=J.Name local M=J.ValueType local H=CreateTextBox(B)H.Size=UDim2.new(1,-2*Styles.Margin,1,0)H.Position=UDim2.new(0,Styles.Margin,0,0)local function h()local J=e[g]H.Text=ToString(J,M)end if not B then H.FocusLost:connect(function(B)Set(e,J,ToValue(H.Text,M))h()end)end h()e.Changed:connect(function(e)if e==g then h()end end)return H end e.bool=function(e,J,B)local g=J.Name local M=e[g]local H,h=CreateCheckbox(M,B,function(B)Set(e,J,not M)end)H.Position=UDim2.new(0,Styles.Margin,0,Styles.Margin)h(M)local function z()M=e[g]h(M)end e.Changed:connect(function(e)if e==g then z()end end)if e:IsA("\066\111\111\108\086\097\108\117\101")then e.Changed:connect(function(e)z()end)end z()return H end e.BrickColor=function(e,J,B)local g=J.Name local M,H,h=CreateBrickColor(B,function(B)Set(e,J,B)end)local function z()local J=e[g]h.BackgroundColor3=J.Color H.Text=tostring(J)end z()e.Changed:connect(function(e)if e==g then z()end end)return M end e.Color3=function(e,J,B)local g=J.Name local M,H,h=CreateColor3Control(B)H.FocusLost:connect(function(B)Set(e,J,ToValue(H.Text,"\067\111\108\111\114\051"))local M=e[g]h.BackgroundColor3=M H.Text=ToString(M,"\067\111\108\111\114\051")end)local function z()local J=e[g]h.BackgroundColor3=J H.Text=ToString(J,"\067\111\108\111\114\051")end z()e.Changed:connect(function(e)if e==g then z()end end)return M end e.Enum=function(e,J,B)local g=J.Name local M=J.ValueType local H=e[g].Name local h={}for e,J in pairs(Enum[tostring(M)]:GetEnumItems())do table.insert(h,J.Name)end local z,X=CreateDropDown(h,H,B,function(B)Set(e,J,B)end)local function O()local J=e[g].Name X.Text=tostring(J)end O()e.Changed:connect(function(e)if e==g then O()end end)return z end e.Object=function(e,J,B)local g=J.Name local M=J.ValueType local H=CreateObject(B,function() end)H.Size=UDim2.new(1,-2*Styles.Margin,1,0)H.Position=UDim2.new(0,Styles.Margin,0,0)local function h()if AwaitingObjectObj==e then if AwaitingObjectValue==true then H.Text="\083\101\108\101\099\116 \097\110 \079\098\106\101\099\116"return end end local J=e[g]H.Text=ToString(J,M)end if not B then H.MouseButton1Click:connect(function()if AwaitingObjectValue then AwaitingObjectValue=false h()return end AwaitingObjectValue=true AwaitingObjectObj=e AwaitingObjectProp=J H.Text="\083\101\108\101\099\116 \097\110 \079\098\106\101\099\116"end)H.Cancel.Visible=true H.Cancel.MouseButton1Click:connect(function()e[g]=nil end)end h()e.Changed:connect(function(e)if e==g then h()end end)if e:IsA("\079\098\106\101\099\116\086\097\108\117\101")then e.Changed:connect(function(e)h()end)end return H end function GetControl(J,B,g)local M=B.ValueType local H=nil if e[M]then H=e[M](J,B,g)elseif RbxApi.IsEnum(M)then H=e.Enum(J,B,g)else H=e.default(J,B,g)end return H end


local Controls = {}

Controls["default"] = function(object, propertyData, readOnly)
	local propertyName = propertyData["Name"]
	local propertyType = propertyData["ValueType"]
	
	local box = CreateTextBox(readOnly)
	box.Size = UDim2.new(1, -2 * Styles.Margin, 1, 0)
	box.Position = UDim2.new(0, Styles.Margin, 0, 0)

	local function update()
		local value = object[propertyName]
		box.Text = ToString(value, propertyType)
	end
	
	if not readOnly then
		box.FocusLost:connect(function(enterPressed)
			Set(object, propertyData, ToValue(box.Text,propertyType))
			update()
		end)
	end
	
	update()
	
	object.Changed:connect(function(property)
		if (property == propertyName) then
			update()
		end
	end)
	
	return box
end

Controls["bool"] = function(object, propertyData, readOnly)
	local propertyName = propertyData["Name"]
	local checked = object[propertyName]
	
	local checkbox, setValue = CreateCheckbox(checked, readOnly, function(value)
		Set(object, propertyData, not checked)
	end)
	checkbox.Position = UDim2.new(0, Styles.Margin, 0, Styles.Margin)
	
	setValue(checked)
	
	local function update()
		checked = object[propertyName]
		setValue(checked)
	end
	
	object.Changed:connect(function(property)
		if (property == propertyName) then
			update()
		end
	end)
	
	if object:IsA("BoolValue") then
		object.Changed:connect(function(val)
			update()
		end)
	end
	
	update()
	
	return checkbox
end

Controls["BrickColor"] = function(object, propertyData, readOnly)
	local propertyName = propertyData["Name"]

	local frame,label,brickColorBox = CreateBrickColor(readOnly, function(brickColor)
		Set(object, propertyData, brickColor)
	end)
	
	local function update()
		local value = object[propertyName]
		brickColorBox.BackgroundColor3 = value.Color
		label.Text = tostring(value)
	end
	
	update()
	
	object.Changed:connect(function(property)
		if (property == propertyName) then
			update()
		end
	end)
	
	return frame
end

Controls["Color3"] = function(object, propertyData, readOnly)
	local propertyName = propertyData["Name"]

	local frame,textBox,colorBox = CreateColor3Control(readOnly)
	
	textBox.FocusLost:connect(function(enterPressed)
		Set(object, propertyData, ToValue(textBox.Text,"Color3"))
		local value = object[propertyName]
		colorBox.BackgroundColor3 = value
		textBox.Text = ToString(value, "Color3")
	end)
			
	local function update()
		local value = object[propertyName]
		colorBox.BackgroundColor3 = value
		textBox.Text = ToString(value, "Color3")
	end
	
	update()
	
	object.Changed:connect(function(property)
		if (property == propertyName) then
			update()
		end
	end)
	
	return frame
end

Controls["Enum"] = function(object, propertyData, readOnly)
	local propertyName = propertyData["Name"]
	local propertyType = propertyData["ValueType"]
	
	local enumName = object[propertyName].Name
	
	local enumNames = {}
	for _,enum in pairs(Enum[tostring(propertyType)]:GetEnumItems()) do
		table.insert(enumNames, enum.Name)
	end
	
	local dropdown, propertyLabel = CreateDropDown(enumNames, enumName, readOnly, function(value)
		Set(object, propertyData, value)
	end)
	--dropdown.Parent = frame
	
	local function update()
		local value = object[propertyName].Name
		propertyLabel.Text = tostring(value)
	end
	
	update()
	
	object.Changed:connect(function(property)
		if (property == propertyName) then
			update()
		end
	end)
	
	return dropdown
end

Controls["Object"] = function(object, propertyData, readOnly)
	local propertyName = propertyData["Name"]
	local propertyType = propertyData["ValueType"]
	
	local box = CreateObject(readOnly,function()end)
	box.Size = UDim2.new(1, -2 * Styles.Margin, 1, 0)
	box.Position = UDim2.new(0, Styles.Margin, 0, 0)

	local function update()
		if AwaitingObjectObj == object then
			if AwaitingObjectValue == true then
				box.Text = "Select an Object"
				return
			end
		end
		local value = object[propertyName]
		box.Text = ToString(value, propertyType)
	end
	
	if not readOnly then
		box.MouseButton1Click:connect(function()
			if AwaitingObjectValue then
				AwaitingObjectValue = false
				update()
				return
			end
			AwaitingObjectValue = true
			AwaitingObjectObj = object
			AwaitingObjectProp = propertyData
			box.Text = "Select an Object"
		end)
		
		box.Cancel.Visible = true
		box.Cancel.MouseButton1Click:connect(function()
			object[propertyName] = nil
		end)
	end
	
	update()
	
	object.Changed:connect(function(property)
		if (property == propertyName) then
			update()
		end
	end)
	
	if object:IsA("ObjectValue") then
		object.Changed:connect(function(val)
			update()
		end)
	end
	
	return box
end

function GetControl(object, propertyData, readOnly)
	local propertyType = propertyData["ValueType"]
	local control = nil
	
	if Controls[propertyType] then
		control = Controls[propertyType](object, propertyData, readOnly)
	elseif RbxApi.IsEnum(propertyType) then
		control = Controls["Enum"](object, propertyData, readOnly)
	else
		control = Controls["default"](object, propertyData, readOnly)
	end
	return control
end