
	(void)panelH;
	RefreshAccountSelector();
}

void TMSelectServerScene::RefreshAccountSelector()
{
	const int count = AccountConfig_GetSavedCount();
	const int current = AccountConfig_GetCurrentIndex();

	if (m_pLoginPanelText)
	{
		char title[64]{};
		if (count <= 0)
		{
			sprintf_s(title, "Contas (vazio)");
		}
		else
		{
			char name[16]{};
			AccountConfig_GetSaved(current, name, sizeof(name), nullptr, 0);
			sprintf_s(title, "%s  (%d/%d)", name[0] ? name : "?", current + 1, count);
		}
		m_pLoginPanelText->SetText(title, 0);
		m_pLoginPanelText->SetVisible(1);
	}

	const bool showNav = count > 1;
	if (m_pAccountPrevBtn)
		m_pAccountPrevBtn->SetVisible(showNav ? 1 : 0);
	if (m_pAccountNextBtn)
		m_pAccountNextBtn->SetVisible(showNav ? 1 : 0);

	for (int i = 0; i < 5; ++i)
	{
		if (!m_pAccountSlotBtns[i])
			continue;

		char name[16]{};
		char pass[16]{};
		if (i < count && AccountConfig_GetSaved(i, name, sizeof(name), pass, sizeof(pass)) && name[0])
		{
			char label[16]{};
			sprintf_s(label, "%.10s", name);
			m_pAccountSlotBtns[i]->SetText(label);
			m_pAccountSlotBtns[i]->SetVisible(1);
			m_pAccountSlotBtns[i]->SetSelected(i == current ? 1 : 0);
		}
		else
		{
			m_pAccountSlotBtns[i]->SetVisible(0);
			m_pAccountSlotBtns[i]->SetSelected(0);
		}
	}
}

void TMSelectServerScene::ApplySelectedAccountToFields()
{
	char account[16]{};
	char password[16]{};
	const int idx = AccountConfig_GetCurrentIndex();
	if (!AccountConfig_GetSaved(idx, account, sizeof(account), password, sizeof(password)))
	{
		const AccountConfigData& cfg = AccountConfig_Get();
		strncpy_s(account, cfg.account, _TRUNCATE);
		strncpy_s(password, cfg.password, _TRUNCATE);
	}

	if (m_pEditID && account[0])
		m_pEditID->SetText(account);
	if (m_pEditPW)
		m_pEditPW->SetText(password);

	RefreshAccountSelector();
}

