using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 AsystentZakupów
{
    /// <summary>
    /// Logika interakcji dla klasy MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Model model;

        private void uzgodnijWidok()
        {
            tbSuma.Text = model.Suma.ToString();
        }

        public MainWindow()
        {
            InitializeComponent();

            decimal sumaPoczątkowa = Properties.Settings.Default.Suma;
            model = new Model(1000, sumaPoczątkowa);
            uzgodnijWidok();
        }        

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                decimal kwota = decimal.Parse(tbKwota.Text);
                model.Dodaj(kwota);
                uzgodnijWidok();
            }
            catch(Exception exc)
            {
                MessageBox.Show("Błąd podczas dodawania kwoty: " + exc.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Properties.Settings.Default.Suma = model.Suma;
            Properties.Settings.Default.Save();
        }
    }
}
