--!strict

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GraspDetection = require(ReplicatedStorage.GraspDetection)

local Thresholds = script.Parent.Thresholds
local TName, TValue = Thresholds.ThresholdName, Thresholds.ThresholdValue

local THRESHOLDS = GraspDetection.GetThresholds()
local ThresholdIndex = 1

TName.Text = THRESHOLDS[ThresholdIndex]
TValue.Text = GraspDetection.GetThresholdValue(THRESHOLDS[ThresholdIndex])

TName.Activated:Connect(function()
  ThresholdIndex += 1
  
  if ThresholdIndex > #THRESHOLDS then
    ThresholdIndex = 1
  end
  
  TName.Text = THRESHOLDS[ThresholdIndex]
  TValue.Text = GraspDetection.GetThresholdValue(THRESHOLDS[ThresholdIndex])
end)

TValue.FocusLost:Connect(function(enterPressed)
  if not enterPressed then
    return
  end
  
  GraspDetection.UpdateThreshold(THRESHOLDS[ThresholdIndex], tonumber(TValue.Text))
  TValue.Text = GraspDetection.GetThresholdValue(THRESHOLDS[ThresholdIndex])
end)
