extends PanelContainer

signal buy_printer

var printer_data: PrinterData
@onready var printer_name: Label = $MarginContainer/VBoxContainer/PrinterInfo/PrinterName
@onready var printer_model: Label = $MarginContainer/VBoxContainer/PrinterInfo/PrinterModel
@onready var printer_speed: Label = $MarginContainer/VBoxContainer/PrinterStats/SpeedLabel
@onready var printer_quality: Label = $MarginContainer/VBoxContainer/PrinterStats/QualityLabel
@onready var printer_price: Label = $MarginContainer/VBoxContainer/HBoxContainer/Price
@onready var buy_button: Button = $MarginContainer/VBoxContainer/HBoxContainer/BuyButton

func _ready() -> void:
	PlayerData.money_changed.connect(_on_toggle_button)

func initialize_printer(data: PrinterData) -> void:
	printer_data = data
	printer_name.text = printer_data.printer_manufacturer
	printer_model.text = printer_data.printer_type
	printer_speed.text = "Speed: " + str(printer_data.printer_speed) + "/5"
	printer_quality.text = "Quality: " + str(printer_data.printer_quality) + "/5"
	printer_price.text = "Price: " + str(printer_data.printer_price) + "€"
	
	if PlayerData.money > printer_data.printer_price:
		buy_button.disabled = false
	else:
		buy_button.disabled = true

func _on_buy_button_pressed() -> void:
	buy_printer.emit(self)
	print("Shop tab printer clicked: " + self.printer_data.printer_manufacturer)

func _on_toggle_button(money) -> void:
	if PlayerData.money > printer_data.printer_price:
		buy_button.disabled = false
	else:
		buy_button.disabled = true
