using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace koltsegvetes
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public static int currentBalance = 0;

        private void transactions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void selectedItemDeletingButton_Click(object sender, RoutedEventArgs e)
        {
            if (transactions.SelectedItem != null)
            {
                int value = Convert.ToInt32(transactions.SelectedValue);

                transactions.Items.RemoveAt(transactions.SelectedIndex);
                
                transactions.Items.Refresh();

                // bevételt törlünk
                //mivel előjelesen van eltárolva így a -- = + érvényesül


                currentBalance -= value;

                balance.Text = $"{currentBalance} Ft";
            }
            transactions.SelectedItem = null;

        }

        private void incomeButton_Click(object sender, RoutedEventArgs e)
        {
            if (amountTextBox.Text != "")
            {
                int income;
                bool isNumber = Int32.TryParse(amountTextBox.Text, out income);
                if (isNumber) {
                    transactions.Items.Add($"{amountTextBox.Text}");
                    currentBalance += income;
                    balance.Text = $"{currentBalance} Ft";
                }                
            }
        }

        private void expenseButton_Click(object sender, RoutedEventArgs e)
        {
            if (amountTextBox.Text != "")
            {
                int expense;
                bool isNumber = Int32.TryParse(amountTextBox.Text, out expense);
                if (isNumber) {
                    transactions.Items.Add($"-{amountTextBox.Text}");
                    currentBalance -= expense;
                    balance.Text = $"{currentBalance} Ft";
                }
            }
        }
    }
}