using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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;
using System.Windows.Threading;
using ChatController.HauptKlassen;

namespace ChatController
{
    /// <summary>
    /// Interaktionslogik für ChatEmojiiControl.xaml
    /// </summary>
    public partial class ChatEmojiiControl : UserControl
    {

        ChatMainControl chatView;
        private ChatEmoji _emojii;

        public ChatEmojiiControl()
        {
            InitializeComponent();

            _emojii = new ChatEmoji();

          
            SetEmojis();
        }

        public void InitChatView(ChatMainControl c)
        {
            chatView = c;
        }

        public void SetEmojis()
        {
            EmojisListBox1.ItemsSource = _emojii.EmojisListBox1;
            EmojisListBox2.ItemsSource = _emojii.EmojisListBox2;
            EmojisListBox3.ItemsSource = _emojii.EmojisListBox3;
            EmojisListBox4.ItemsSource = _emojii.EmojisListBox4;
            EmojisListBox5.ItemsSource = _emojii.EmojisListBox5;
            EmojisListBox6.ItemsSource = _emojii.EmojisListBox6;
            EmojisListBox7.ItemsSource = _emojii.EmojisListBox7;

            TabItem1.Header = _emojii.TabItem1;
            TabItem2.Header = _emojii.TabItem2;
            TabItem3.Header = _emojii.TabItem3;
            TabItem4.Header = _emojii.TabItem4;
            TabItem5.Header = _emojii.TabItem5;
            TabItem6.Header = _emojii.TabItem6;
            TabItem7.Header = _emojii.TabItem7;
        }

        private void OnEmojiClick(object sender, RoutedEventArgs e)
        {

            foreach (Object selecteditem in EmojisListBox1.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }

            foreach (Object selecteditem in EmojisListBox2.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }


            foreach (Object selecteditem in EmojisListBox3.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }

            foreach (Object selecteditem in EmojisListBox4.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }

            foreach (Object selecteditem in EmojisListBox5.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }

            foreach (Object selecteditem in EmojisListBox6.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }

            foreach (Object selecteditem in EmojisListBox7.SelectedItems)
            {
                DirectoryListing Item = selecteditem as DirectoryListing;

                if (Item.EmojiCode != "")
                {
                    ÜbergebeEmojiAnChatView(Item.EmojiCode, Item.Pfad);
                }
            }

            EmojisListBox1.SelectedIndex = -1;
            EmojisListBox2.SelectedIndex = -1;
            EmojisListBox3.SelectedIndex = -1;
            EmojisListBox4.SelectedIndex = -1;
            EmojisListBox5.SelectedIndex = -1;
            EmojisListBox6.SelectedIndex = -1;
            EmojisListBox7.SelectedIndex = -1;

           // ChatEmojiView.Activate();
        }

        public void ÜbergebeEmojiAnChatView(string emojiicode, string muell)
        {
            try
            {
                Dispatcher.Invoke(
                    DispatcherPriority.Normal,
                    (ThreadStart)delegate
                    {
                        chatView.Chatbox.Focus();
                        chatView.Chatbox.Text += " " + emojiicode;
                        chatView.Chatbox.SelectionStart = chatView.Chatbox.Text.Length;
                        
                    });
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

    }
}
