using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using HistoryWallEditTool.Utilities;
using HistoryWallEditTool.Helper;

namespace HistoryWallEditTool.Controls.PreviewControl
{
    /// <summary>
    /// DetailPreview.xaml 的互動邏輯
    /// </summary>
    public partial class DetailPreview : UserControl
    {
        #region Constructor

        public DetailPreview()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(DetailPreview_Loaded);
        }

        #endregion

        #region Events

        private void DetailPreview_Loaded(object sender, RoutedEventArgs e)
        {
            ChangeBackgrundColor();
            LoadEventColor();
            LoadTimelineColor();
            LoadTimelineExtentColor();
            LoadDetailPreview();
        }

        #endregion

        #region Methods

        private void ChangeBackgrundColor()
        {
            if (!File.Exists(GlobalFunction.thumbPath + HistoryWall.MainBackCollect.ImgBackground))
            {
                SolidColorBrush brush = new SolidColorBrush(HistoryWall.MainBackCollect.BackgroundColor);
                uxEventGrid.Background = brush;
            }
            else
            {
                uxEventGrid.Background = new ImageBrush(UtilityFunctions.LoadBitmapImage(GlobalFunction.thumbPath + HistoryWall.MainBackCollect.ImgBackground, (int)this.Width));
            }
        }

        private void LoadEventColor()
        {
            SolidColorBrush brushBackground = new SolidColorBrush(HistoryWall.EventCollect.BackgroundColor);
            SolidColorBrush brushText = new SolidColorBrush(HistoryWall.EventCollect.TextColor);
            SolidColorBrush brushThickness = new SolidColorBrush(HistoryWall.EventCollect.ThicknessColor);
            for (int i = 0; i < uxEventGrid.Children.Count; i++)
            {
                Label lbl = uxEventGrid.Children[i] as Label;
                lbl.Foreground = brushText;
                lbl.Background = brushBackground;
                lbl.BorderBrush = Brushes.Transparent;//brushThickness;
            }
        }

        private void LoadTimelineColor()
        {
            SolidColorBrush brushBackground = new SolidColorBrush(HistoryWall.TimelineCollect.BackgroundColor);
            SolidColorBrush brushText = new SolidColorBrush(HistoryWall.TimelineCollect.TextColor);
            SolidColorBrush brushThickness = new SolidColorBrush(HistoryWall.TimelineCollect.ThicknessColor);
            for (int i = 0; i < uxTimelineGrid.Children.Count; i++)
            {
                Label lbl = uxTimelineGrid.Children[i] as Label;
                lbl.Foreground = brushText;
                lbl.Background = brushBackground;
                //lbl.BorderBrush = brushThickness;
            }
            uxUnselectLeftTextLabel.Foreground = brushText;
            uxUnselectRightTextLabel.Foreground = brushText;
        }

        private void LoadTimelineExtentColor()
        {
            SolidColorBrush brushBackground = new SolidColorBrush(HistoryWall.TimelineExtentCollect.BackgroundColor);
            SolidColorBrush brushText = new SolidColorBrush(HistoryWall.TimelineExtentCollect.TextColor);
            SolidColorBrush brushThickness = new SolidColorBrush(HistoryWall.TimelineExtentCollect.ThicknessColor);
            for (int i = 0; i < uxExtentTimelineStackpanel.Children.Count; i++)
            {
                Label lbl = uxExtentTimelineStackpanel.Children[i] as Label;
                lbl.Background = brushBackground;
                lbl.BorderBrush = Brushes.Transparent;
            }
            uxSelectTextLabel.Foreground = brushText;
        }

        private void LoadDetailPreview()
        {
            uxRootBorder.Background = new SolidColorBrush(HistoryWall.EventContentCollect.BackgroundColor);
            return;
            SolidColorBrush brush = new SolidColorBrush(HistoryWall.EventContentCollect.ThicknessColor);
            for (int i = 1; i < uxImageGrid.Children.Count; i++)
            {
                Rectangle rectangle = uxImageGrid.Children[i] as Rectangle;
                rectangle.Stroke = brush;
                if (i == 7)
                {
                    rectangle.Fill = brush;
                }
            }

            SolidColorBrush textBrush = new SolidColorBrush(HistoryWall.EventContentCollect.TextColor);
            for (int i = 0; i < uxTextPanel.Children.Count; i++)
            {
                TextBlock tb = uxTextPanel.Children[i] as TextBlock;
                tb.Foreground = textBrush;
            }

            uxLang1Lbl.Content = HistoryWall.MainBackCollect.LangText[0];
            uxLang2Lbl.Content = HistoryWall.MainBackCollect.LangText[1];
            uxLang3Lbl.Content = HistoryWall.MainBackCollect.LangText[2];
            uxLang4Lbl.Content = HistoryWall.MainBackCollect.LangText[3];

            if (HistoryWall.MainBackCollect.LangText[0] == "")
                uxLang1Lbl.Visibility = Visibility.Hidden;
            else
                uxLang1Lbl.Visibility = Visibility.Visible;

            if (HistoryWall.MainBackCollect.LangText[1] == "")
                uxLang2Lbl.Visibility = Visibility.Hidden;
            else
                uxLang2Lbl.Visibility = Visibility.Visible;

            if (HistoryWall.MainBackCollect.LangText[2] == "")
                uxLang3Lbl.Visibility = Visibility.Hidden;
            else
                uxLang3Lbl.Visibility = Visibility.Visible;

            if (HistoryWall.MainBackCollect.LangText[3] == "")
                uxLang4Lbl.Visibility = Visibility.Hidden;
            else
                uxLang4Lbl.Visibility = Visibility.Visible;

            if (HistoryWall.MainBackCollect.DefaultLangIndex == 0)
            {
                uxLang1Lbl.Foreground = uxCloseLbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColor);
                uxLang1Lbl.Background = uxCloseLbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColor);
                uxLang2Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang2Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang3Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang3Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang4Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang4Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxContentText.Text = "第一語系，第一語系，第一語系，第一語系，第一語系，第一語系";
            }
            else if (HistoryWall.MainBackCollect.DefaultLangIndex == 1)
            {
                uxLang2Lbl.Foreground = uxCloseLbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColor);
                uxLang2Lbl.Background = uxCloseLbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColor);
                uxLang1Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang1Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang3Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang3Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang4Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang4Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxContentText.Text = "第二語系，第二語系，第二語系，第二語系，第二語系，第二語系";
            }
            else if (HistoryWall.MainBackCollect.DefaultLangIndex == 2)
            {
                uxLang3Lbl.Foreground = uxCloseLbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColor);
                uxLang3Lbl.Background = uxCloseLbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColor);
                uxLang1Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang1Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang2Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang2Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang4Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang4Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxContentText.Text = "第三語系，第三語系，第三語系，第三語系，第三語系，第三語系";
            }
            else if (HistoryWall.MainBackCollect.DefaultLangIndex == 3)
            {
                uxLang4Lbl.Foreground = uxCloseLbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColor);
                uxLang4Lbl.Background = uxCloseLbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColor);
                uxLang1Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang1Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang2Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang2Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxLang3Lbl.Foreground = new SolidColorBrush(HistoryWall.BtnSelectCollect.TextColorUnselect);
                uxLang3Lbl.Background = new SolidColorBrush(HistoryWall.BtnSelectCollect.BackgroundColorUnselect);
                uxContentText.Text = "第四語系，第四語系，第四語系，第四語系，第四語系，第四語系";
            }
        }

        #endregion
    }
}
