using F4SD_AdaptableIcon.Enums;
using F4SDicons.Models;
using FasdDesktopUi.Basics.UserControls.AdaptableIcon;
using MaterialIcons;
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;
using static FasdDesktopUi.Basics.UserControls.AdaptableIcon.cIconPainter;

namespace F4SDicons.User_Controls
{

    public partial class IconList : UserControl
    {



        public List<cAdvancedIconInformation> IconInformation
        {
            get { return (List<cAdvancedIconInformation>)GetValue(IconInformationProperty); }
            set { SetValue(IconInformationProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IconInformation.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IconInformationProperty =
            DependencyProperty.Register("IconInformation", typeof(List<cAdvancedIconInformation>), typeof(IconList), new PropertyMetadata(null));


        public IconList()
        {
            InitializeComponent();
        }

        #region Klick

        private void MaterialStackPanel_TouchDown(object sender, TouchEventArgs e)
        {
            MaterialStackPanelWasClicked(sender);
        }

        private void MaterialStackPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            MaterialStackPanelWasClicked(sender);
        }

        #endregion

        #region Event

        public event RoutedEventHandler IconSelected
        {

            add { AddHandler(IconCollectionUserControl.IconSelectedEvent, value); }
            remove { RemoveHandler(IconCollectionUserControl.IconSelectedEvent, value); }

        }

        #endregion

        private void MaterialStackPanelWasClicked(object sender)
        {

            if (!(sender is FrameworkElement frameworkElement))
                return;

            enumIconTypes? iconType = null;

            if (Enum.TryParse(frameworkElement.Tag.ToString(), out MaterialIconType _))
                iconType = enumIconTypes.material;
            else if (Enum.TryParse(frameworkElement.Tag.ToString(), out enumInternIcons _))
                iconType = enumIconTypes.intern;

            if (iconType is null)
                return;

            RoutedEventArgsIconInfo eventArgs = new RoutedEventArgsIconInfo(IconCollectionUserControl.IconSelectedEvent) { IconName = frameworkElement.Tag.ToString(), IconType = iconType.Value };
            RaiseEvent(eventArgs);
        }

    }
}
