using MultiLayout.UiModule;
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 Unity;
namespace MultiLayout
{
    /// <summary>
    /// PgMenu.xaml 的交互逻辑
    /// </summary>
    public partial class PgMenu : Page
    {
        FlyLayoutManager manager;
        public PgMenu()
        {
            InitializeComponent();
        }
        public void Init(FlyLayoutManager manager)
        {
            this.manager = manager;
            manager.IsInOption = true;
            var defaultBrush = this.Resources["Color_menu"] as SolidColorBrush;

            //CustomMenu.MainEditMenu editMenu = new CustomMenu.MainEditMenu(manager.container, manager);
            //List<IMenu> menus = new List<IMenu>();
            //menus.Add(editMenu);
            //itemsControl0.ItemsSource = menus;


            if (manager.container.IsRegistered<IUnityContainer>("customMenu.ui"))
            {
                var container_cm = manager.container.Resolve<IUnityContainer>("customMenu.ui");
                //枚举全部button出来
                var menus = container_cm.ResolveAll<IMenu>();
                //把Brush 为null 的都设置为#FF0083D7
                foreach (var menu in menus)
                {
                    if (menu.Brush == null)
                    {

                        menu.Brush = defaultBrush;
                    }
                }
                itemsControl0.ItemsSource = menus;
            }
        }
        private void btnBackClick(object sender, RoutedEventArgs e)
        {
            manager.IsInOption = false;
            FlyLayoutManager.NavigationService.GoBack();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            var menu = btn.DataContext as IMenu;
            menu.OnClick();
        }
    }
}
