using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;

namespace Content.Client.Traitor.Uplink
{
    /// <summary>
    ///     Window to select amount TC to withdraw from Uplink account
    ///     Used as sub-window in Uplink UI
    /// </summary>
    [GenerateTypedNameReferences]
    public sealed partial class UplinkWithdrawWindow : DefaultWindow
    {
        public event System.Action<int>? OnWithdrawAttempt;

        public UplinkWithdrawWindow(int tcCount)
        {
            RobustXamlLoader.Load(this);

            // setup withdraw slider
            WithdrawSlider.MinValue = 1;
            WithdrawSlider.MaxValue = tcCount;

            // and buttons
            ApplyButton.OnButtonDown += _ =>
            {
                OnWithdrawAttempt?.Invoke(WithdrawSlider.Value);
                Close();
            };
            CancelButton.OnButtonDown += _ => Close();
        }
    }
}
