using Godot;
using Sfs3.Client.Entities;
using System;

public partial class GameListItem : PanelContainer
{
	[Export]
	public Label nameLabel;
	[Export]
	public Label playerSlotsLabel;
	[Export]
	public Label spectatorSlotsLabel;
	[Export]
	public Button playButton;
	[Export]
	public Button watchButton;

	private Room room;

	public void Init(Room room)
	{
		this.room = room;

		nameLabel.Text = room.Name;

		Update();
	}
	
	public void Update()
    {
        var playerSlots = room.MaxUsers - room.UserCount;
		var spectatorSlots = room.MaxSpectators - room.SpectatorCount;

		// Set player count and spectator count in game list item
		playerSlotsLabel.Text = "Player slots: " + playerSlots;
		spectatorSlotsLabel.Text = "Spectator slots: " + spectatorSlots;

		// Enable/disable buttons
		playButton.Disabled = playerSlots == 0;
		watchButton.Disabled = spectatorSlots == 0;
    }
}
