using System;
using System.Collections.Generic;
using System.Data;
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.Shapes;
using EpsonPrinter.Model;
using Pos.Models;
using Pos.Service;

namespace Pos
{
    /// <summary>
    /// Interaction logic for SaleOfDay.xaml
    /// </summary>
    public partial class SaleOfDay : Window
    {
        private bool _initialLoad = true;
        private TotalSaleDetail totalSaleDetail;
        public SaleOfDay()
        {
            InitializeComponent();
            SaleService saleService = new SaleService();
            totalSaleDetail = saleService.TotalSale(DateTime.Now);
            TotalSale.Content = $"Dagens salg: kr. {totalSaleDetail.TotalSale:0.00}";
            StartDatePicker.SelectedDate = DateTime.Now;
            GridSaleDetail.ItemsSource = totalSaleDetail.TotalSaleCategories;
            _initialLoad = false;
        }

        private void StartDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_initialLoad)
                return;

            _initialLoad = false;
            DateTime selectedDate = DateTime.Parse(sender.ToString());
            SaleService saleService = new SaleService();
            totalSaleDetail = saleService.TotalSale(selectedDate);
            TotalSale.Content = $"Dagens salg: kr. {totalSaleDetail.TotalSale:0.00}";
            GridSaleDetail.ItemsSource = totalSaleDetail.TotalSaleCategories;
        }

        private void PrintSale_OnClick(object sender, RoutedEventArgs e)
        {
            SaleService saleService = new SaleService();
            saleService.PrintSaleOfDay(StartDatePicker.SelectedDate.Value,totalSaleDetail);
        }
    }
}
