using Elwig.Documents;
using Elwig.Helpers;
using Elwig.Helpers.Billing;
using Elwig.Helpers.Export;
using Elwig.Helpers.Weighing;
using Elwig.Models.Dtos;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Xceed.Wpf.Toolkit.Primitives;

namespace Elwig.Windows {
    public partial class TestWindow : Window {

        public TestWindow() {
            InitializeComponent();
            MyComboBox.ItemsSource = new string[] { "Klasse A" , "Klasse B", "Klasse C", "Klasse D", "Klasse E", "Klasse F" };
            MyListBox.ItemsSource = new string[] { "Test 1", "Test 2", "Test 3", "Test 4" };
        }

        private void OnItemSelectionChanged(object sender, ItemSelectionChangedEventArgs e) {
            MyText.Text = string.Join(", ", MyComboBox.SelectedItems.Cast<string>());
        }

        private async void WeighingButton1_Click(object sender, RoutedEventArgs evt) {
            try {
                if (App.Scales[0] is not ICommandScale cs) return;
                var res = await cs.GetCurrentWeight();
                Output.Text = res.ToString();
            } catch (Exception e) {
                MessageBox.Show($"Beim Wiegen ist ein Fehler aufgetreten:\n\n{e.Message}", "Waagenfehler",
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private async void WeighingButton2_Click(object sender, RoutedEventArgs evt) {
            try {
                if (App.Scales[0] is not ICommandScale cs) return;
                var res = await cs.Weigh();
                Output.Text = res.ToString();
            } catch (Exception e) {
                MessageBox.Show($"Beim Wiegen ist ein Fehler aufgetreten:\n\n{e.Message}", "Waagenfehler",
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private async void ZipButton_Click(object sender, RoutedEventArgs evt) {
            using var ctx = new AppDbContext();
            using var ods = new OdsFile(@"C:\Users\Lorenz\Desktop\test.ods");
            await ods.AddTable(await DeliveryConfirmationDeliveryData.ForMember(ctx.DeliveryParts, 2023, ctx.Members.Find(2948)));
        }
    }
}
