using CollaborativePlatformMain.DFEntity.MessageSubUtil;
using CollaborativePlatformMain.Form.MessageSubPage.AddImage;
using CollaborativePlatformMain.Form.MessageSubPage.Legend;
using CollaborativePlatformMain.Util;
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.Shapes;

namespace CollaborativePlatformMain.Form.MessageSubPage
{
    /// <summary>
    /// SeconLegendPage.xaml 的交互逻辑
    /// </summary>
    public partial class SeconLegendPage : Page
    {

        public HomepageForm HomepageForm;

        public SeconLegendPage(HomepageForm homepageForm)
        {
            InitializeComponent();
            HomepageForm = homepageForm;
        }

        /// <summary>
        /// 文件夹名称
        /// </summary>
        public List<LegendEntity> LegendEntities = new List<LegendEntity>() {
             new LegendEntity("门窗大样", @"/Image/folderImage.png"),
             new LegendEntity("家具", @"/Image/folderImage.png"),
             new LegendEntity("户型", @"/Image/folderImage.png"),
             new LegendEntity("墙体大样", @"/Image/folderImage.png"),
             new LegendEntity("新增", @"/Image/add.png"),
        };


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {


            sv_legend.ItemsSource = null;
            sv_legend.ItemsSource = LegendEntities;
        }

        /// <summary>
        /// 最后的文件夹分级名字
        /// </summary>
        public string lastLegendName = "sp_add1";

        /// <summary>
        /// 最后个数命名序号
        /// </summary>
        public int Num = 1;

        /// <summary>
        /// 是否存在页面
        /// </summary>
        public Dictionary<string, Page> id_Pages = new Dictionary<string, Page>();

        /// <summary>
        /// 新增文件夹分级
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
        {
            StackPanel stackPanel = sender as StackPanel;
            if (stackPanel == null) return;

            Label label = stackPanel.FindName("lb_legendName") as Label;
            if (label == null) return;

            if (label.Content.ToString() == "新增")
            {
                AddImageForm addImageForm = new AddImageForm(this);
                addImageForm.ShowDialog();
            }
            else
            {
                if (id_Pages.Where(x => x.Key == label.Content.ToString()).Count() == 0)
                {
                    DetailedLegendPage detailedLegendForm = new DetailedLegendPage(this, HomepageForm, label.Content.ToString());

                    HomepageForm.seconLegendPage.Navigate(detailedLegendForm);
                    id_Pages.Add(label.Content.ToString(), detailedLegendForm);
                }
                else
                {
                    HomepageForm.seconLegendPage.Navigate(id_Pages[label.Content.ToString()]);
                }
            }
        }


        /// <summary>
        /// 新增文件夹
        /// </summary>
        /// <param name="legendName"></param>
        public bool AddLegendMath(string legendName)
        {
            for (int i = 0; i < LegendEntities.Count; i++)
            {
                if (LegendEntities[i].Name.Equals(legendName))
                {
                    MessageBox.Show("已具有相同名称文件夹");
                    return false;
                }
            }
            //添加数据
            LegendEntity legendEntity = new LegendEntity(legendName, @"/Image/folderImage.png");
            int index = LegendEntities.Count - 1;
            LegendEntities.Insert(index, legendEntity);

            sv_legend.ItemsSource = null;
            sv_legend.ItemsSource = LegendEntities;
            return true;
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {

        }

    }
}
