using System.Windows;
namespace HC_APTBS.Views.Dialogs
{
///
/// Small input dialog that prompts for a username and password, or a password only.
/// Used by when adding a new user or
/// changing an existing user's password. Kept as a code-behind dialog (not MVVM)
/// because it is a transient prompt with no shared state.
///
public partial class UserPromptDialog : Window
{
/// Username entered by the operator. Empty when is false.
public string EnteredUsername { get; private set; } = string.Empty;
/// Password entered by the operator.
public string EnteredPassword { get; private set; } = string.Empty;
///
/// Creates the dialog.
///
/// Window title (already-localised string).
///
/// True to show the username field (Add user flow); false to hide it (Change password flow).
///
///
/// Pre-filled, read-only username shown as a label when is false.
/// Ignored otherwise.
///
public UserPromptDialog(string title, bool usernameVisible, string prefillUsername = "")
{
InitializeComponent();
Title = title;
if (usernameVisible)
{
EnteredUsername = string.Empty;
TbUsername.Focus();
}
else
{
// Hide username row; reserve width so layout doesn't shift.
LblUsername.Visibility = Visibility.Collapsed;
TbUsername.Visibility = Visibility.Collapsed;
EnteredUsername = prefillUsername;
PbPassword.Focus();
}
}
private void OnAccept(object sender, RoutedEventArgs e)
{
if (TbUsername.Visibility == Visibility.Visible)
EnteredUsername = TbUsername.Text;
EnteredPassword = PbPassword.Password;
DialogResult = true;
Close();
}
}
}