using CollaborativePlatformMain.DFEntity.MessageSubUtil;
using CollaborativePlatformMain.Form.MessageSubPage.AddImage;
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.Legend
{
    /// <summary>
    /// DetailedLegendForm.xaml 的交互逻辑
    /// </summary>
    public partial class DetailedLegendPage : Page
    {

        /// <summary>
        /// 父级窗体
        /// </summary>
        public SeconLegendPage SeconLegendPage;

        /// <summary>
        /// 数据信息
        /// </summary>
        public List<LegendEntity> LegendEntities = new List<LegendEntity>();

        public Dictionary<string, List<LegendEntity>> KeyValuePairs = new Dictionary<string, List<LegendEntity>>()
        {
             {"门窗大样",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/folderImage.png"),
             } },
             {"家具",new List<LegendEntity>(){
                 new LegendEntity("床", @"/Image/folderImage.png"),
                 new LegendEntity("沙发", @"/Image/folderImage.png"),
                 new LegendEntity("衣柜", @"/Image/folderImage.png"),
                 new LegendEntity("玄关柜", @"/Image/folderImage.png"),
             } },
             {"户型",new List<LegendEntity>(){
                  new LegendEntity("一居室", @"/Image/folderImage.png"),
                  new LegendEntity("二居室", @"/Image/folderImage.png"),
             } },
             {"墙体大样",new List<LegendEntity>(){
                 new LegendEntity("墙体大样图1", @"/Image/folderImage.png"),
                  new LegendEntity("墙体大样图2", @"/Image/folderImage.png"),
             } },
        };

        /// <summary>
        /// 父级窗体选中标签
        /// </summary>
        public string LegendName = "";

        /// <summary>
        /// 首级页面
        /// </summary>
        public HomepageForm HomepageForm;

        public DetailedLegendPage(SeconLegendPage seconLegendPage, HomepageForm homepageForm, string legendName)
        {
            InitializeComponent();
            LegendName = legendName;
            HomepageForm = homepageForm;
            SeconLegendPage = seconLegendPage;
        }

        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
            {

            }
        }

        /// <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;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (LegendName.Equals("门窗大样"))
            {
                this.Title = "门窗大样";
                LegendEntities = KeyValuePairs["门窗大样"];
            }
            else if (LegendName.Equals("家具"))
            {
                this.Title = "家具";
                LegendEntities = KeyValuePairs["家具"];
            }
            else if (LegendName.Equals("户型"))
            {
                this.Title = "户型";
                LegendEntities = KeyValuePairs["户型"];
            }
            else if (LegendName.Equals("墙体大样"))
            {
                this.Title = "墙体大样";
                LegendEntities = KeyValuePairs["墙体大样"];
            }
            if (LegendEntities.Where(x => x.Name.Equals("新增")).Count() == 0)
            {
                LegendEntity insertLegend = new LegendEntity("新增", @"/Image/add.png");
                LegendEntities.Add(insertLegend);
            }
            sv_legend.ItemsSource = null;
            sv_legend.ItemsSource = LegendEntities;
        }

        private void returnBackBu_Click(object sender, RoutedEventArgs e)
        {
            HomepageForm.seconLegendPage.Navigate(SeconLegendPage);
        }
    }
}
