extends Node3D


const _Player = preload("res://src/overworld/player.gd")

@export var _interact_prompt_label: RichTextLabel
@export var _day_label: RichTextLabel
@export var _fade_rect: ColorRect
@export var _player: _Player 


func _enter_tree() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	_fade_rect.show()
	create_tween().tween_property(_fade_rect, "color:a", 0, 0.2)


func _process(_delta: float) -> void:
	_interact_prompt_label.visible = is_instance_valid(_player.interact_target)
	_day_label.text = "[right]Day %d[/right]" % GameState.fetch().day


func start_trade(npc_data: Script) -> void:
	GameState.fetch().is_player_input_disabled = true
	Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	
	var fade_tween := create_tween()
	fade_tween.tween_property(_fade_rect, "color:a", 1, 0.2)
	await fade_tween.finished
	await get_tree().create_timer(0.1).timeout
	
	GameState.fetch().trade_npc_data = npc_data
	MainEvents.scene_change_requested.emit("res://src/trade/trade.tscn", true)
	GameState.fetch().is_player_input_disabled = false
