using System.Windows.Controls;
using System.Windows.Media;
using HistoryWallEditTool.JsonFile;
using System.Windows;

namespace HistoryWallEditTool.ControlsForData
{
    /// <summary>
    /// EventCreator.xaml 的互動邏輯
    /// </summary>
    public partial class EventCreator : UserControl
    {
        private HistoryWallEventJson hweventJson;
        private EventGroup eventGroup;

        private void SetUiControllerLanResource(EventCreatorClass ecc)
        {
            if (ecc == EventCreatorClass.MainEvent)
            {
                uxSelectLineText.SetResourceReference(TextBlock.TextProperty, "maineventByTime");
                uxWarningText.SetResourceReference(TextBlock.TextProperty, "maineventsuggest");
            }
            else if (ecc == EventCreatorClass.SubEvent)
            {
                uxSelectLineText.SetResourceReference(TextBlock.TextProperty, "subeventByTime");
                uxWarningText.SetResourceReference(TextBlock.TextProperty, "subeventsuggest");
            }
        }
        //初始化~ 主類別的初始化
        public EventCreator(CurrentEditLanguage cel, EventCreatorClass ecc)
        {
            InitializeComponent();

            SetUiControllerLanResource(ecc);
            curLanguage = cel;
            curEventClass = ecc;
            curLanguageDir = HistoryWall.MainBackCollect.LangFlowDir[(int)curLanguage];

            //匯入ICON
            AddCategoryToolBar();

            if (curEventClass == EventCreatorClass.MainEvent)
            {
                this.hweventJson = MainContainer.hweventJson;
                uxWarningText.Foreground = Brushes.Red;
                //透過傳入的資料載入資訊
                LoadMainDataByJson();
            }
            else if (curEventClass == EventCreatorClass.SubEvent)
            {
                this.eventGroup = MainContainer.hweventJson.EventGroups[MainContainer.mainEventIndex];
                uxWarningText.Foreground = Brushes.Gray;
                //透過傳入的資料載入資訊
                LoadSubDataByJson();
            }
        }

        public void SetDefaultCheck(int index)
        {
            uxItemListBox.SelectedIndex = index;
        }

        private void LoadMainDataByJson()
        {
            for (int i = 0; i < hweventJson.EventGroups.Count; i++)
            {
                UserEventItem ue = new UserEventItem(ControlMode.Display, curEventClass, i, curLanguage, curLanguageDir);

                uxItemListBox.Items.Add(ue);
            }
        }

        private void LoadSubDataByJson()
        {
            for (int i = 0; i < eventGroup.ListDates.Count; i++)
            {
                UserEventItem ue = new UserEventItem(ControlMode.Display, curEventClass, i, curLanguage, curLanguageDir);

                uxItemListBox.Items.Add(ue);
            }
        }
    }
}
