-- Compiled with roblox-ts v2.1.0

local TS = require(game:GetService("ReplicatedStorage"):WaitForChild("rbxts_include"):WaitForChild("RuntimeLib"))
local Log = TS.import(script, game:GetService("ReplicatedStorage"), "rbxts_include", "node_modules", "@rbxts", "log", "out").default
local _components = TS.import(script, game:GetService("ReplicatedStorage"), "TS", "components")
local Body = _components.Body
local NPC = _components.NPC
local Wants = _components.Wants
local function customer(world, _)
	for id, wants in world:queryChanged(Wants) do
		if not wants.old and wants.new then
			Log.Info("v Wants " .. (tostring(id) .. (" | " .. (tostring(wants.new.product.amount) .. ("x " .. wants.new.product.product)))))
			task.delay(1, function()
				if not world:contains(id) then
					return nil
				end
				local npc = world:get(id, NPC)
				local _result = world:get(id, Body)
				if _result ~= nil then
					_result = _result.model
				end
				local body = _result
				if not npc or not body then
					Log.Error("No NPC or Body component for customer")
					return nil
				end
				body.DialogGui.DialogFrame.DialogText.Text = "I want " .. (tostring(wants.new.product.amount) .. ("x " .. wants.new.product.product))
				body.DialogGui.Enabled = true
			end)
		end
		if wants.old and wants.new then
			Log.Info("x Wants " .. (tostring(id) .. (" | " .. (tostring(wants.new.product.amount) .. ("x " .. wants.new.product.product)))))
			if not world:contains(id) then
				return nil
			end
			local npc = world:get(id, NPC)
			local _result = world:get(id, Body)
			if _result ~= nil then
				_result = _result.model
			end
			local body = _result
			if not npc or not body then
				Log.Error("No NPC or Body component for customer")
				continue
			end
			body.DialogGui.DialogFrame.DialogText.Text = "I want " .. (tostring(wants.new.product.amount) .. ("x " .. wants.new.product.product))
			body.DialogGui.Enabled = true
		end
		if wants.old and not wants.new then
			if not world:contains(id) then
				return nil
			end
			local npc = world:get(id, NPC)
			local _result = world:get(id, Body)
			if _result ~= nil then
				_result = _result.model
			end
			local body = _result
			if not npc or not body then
				Log.Error("No NPC or Body component for customer")
				continue
			end
			body.DialogGui.DialogFrame.DialogText.Text = "Thanks!"
			task.wait(2)
			body.DialogGui.Enabled = false
		end
	end
end
return customer
