extends PanelContainer

signal job_accepted

var job_data: JobData
var job_time: String
var job_material: String
@onready var job_name: Label = $MarginContainer/VBoxContainer/HBoxContainer2/PartName
@onready var job_amount: Label = $MarginContainer/VBoxContainer/HBoxContainer3/PartAmount
@onready var job_reward: Label = $MarginContainer/VBoxContainer/HBoxContainer/RewardLabel
@onready var job_experience: Label = $MarginContainer/VBoxContainer/HBoxContainer3/PartExperience
@onready var job_time_label: Label = $MarginContainer/VBoxContainer/HBoxContainer/TimeLabel
@onready var job_material_label: Label = $MarginContainer/VBoxContainer/HBoxContainer2/PartMaterial


func initialize_job(data: JobData) -> void:
	job_data = data
	job_material = 'PLA'
	job_time = calculate_time()
	job_name.text = job_data.job_name
	job_amount.text = 'Amount: %d pcs' % job_data.job_amount
	job_reward.text = 'Reward: %.2f €' % job_data.job_reward
	job_experience.text = 'Experience: %.0f xp' % job_data.job_experience
	job_time_label.text = 'Time: %s' % job_time
	job_material_label.text = '| %s' % job_material

func calculate_time() -> String:
	var print_time: float = sqrt(job_data.job_experience + job_data.job_reward) * job_data.job_amount
	var round_time: float = round(print_time * 100) / 100
	var minutes: int = 0
	
	if round_time >= 60:
		while round_time >= 60:
			minutes += 1
			round_time -= 60
		return '%d m %.2f s' % [minutes, round_time]
	else:
		return '%.2f s' % round_time

func _on_accept_job_pressed() -> void:
	job_accepted.emit(self)

func _on_skip_job_pressed() -> void:
	queue_free()
	GameData.current_job_count -= 1
