extends PopupPanel

@onready var fullscreen_checkbox = $VBoxContainer/CheckBox
@onready var resolution_dropdown = $VBoxContainer/Resolution
@onready var apply_button = $VBoxContainer/Apply
@onready var exit_button = $VBoxContainer/Exit

@onready var polish = $VBoxContainer/Polish
@onready var english = $VBoxContainer/English
@onready var german = $VBoxContainer/Germany

var resolutions = [
	Vector2i(1280, 720),
	Vector2i(1600, 900),
	Vector2i(1920, 1080),
	Vector2i(2560, 1440)
]

func _ready():
	# Stan checkboxa fullscreen
	fullscreen_checkbox.button_pressed = DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN
	# Połączenia
	apply_button.pressed.connect(_on_apply_pressed)
	exit_button.pressed.connect(_on_close_pressed)
	
	polish.pressed.connect(_on_polish_pressed)
	english.pressed.connect(_on_english_pressed)
	german.pressed.connect(_on_german_pressed)

	# Wypełnienie listy rozdzielczości
	for res in resolutions:
		resolution_dropdown.add_item("%d x %d" % [res.x, res.y])

	# Wybór aktualnej
	var current_size = DisplayServer.window_get_size()
	for i in range(resolutions.size()):
		if resolutions[i] == current_size:
			resolution_dropdown.select(i)
			break

func _on_apply_pressed():
	var selected = resolution_dropdown.get_selected_id()
	var new_size = resolutions[selected]

	if fullscreen_checkbox.button_pressed:
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
	else:
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
		
		# Pobierz główne okno gry (root)
		var main_window = get_tree().root.get_window()
		main_window.size = new_size

		# Wyśrodkuj
		var screen_size = DisplayServer.screen_get_size()
		main_window.position = (screen_size - new_size) / 2

	print("Zmieniono ROZMIAR OKNA GRY na:", new_size)
	hide()



func _on_close_pressed():
	hide()
func _on_polish_pressed():
	TranslationServer.set_locale("pl") # wersja jezykowa
	print("polski")
func _on_german_pressed():
	TranslationServer.set_locale("de") # wersja jezykowa
func _on_english_pressed():
	TranslationServer.set_locale("en") # wersja jezykowa
	
