using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using FasdDesktopUi.Pages.SlimPage.Models;
using FasdDesktopUi.Basics;
using FasdDesktopUi.Basics.Models;
using FasdDesktopUi.Basics.Enums;

using Newtonsoft.Json;

namespace FasdDesktopUi.Pages.SlimPage
{
    public class SlimPageViewModel : BaseViewModel
    {
        #region Properties

        public cSupportCaseDataProvider DataProvider { get; set; }

        #region ZoomInPercent

        private int zoomInPercent;

        public int ZoomInPercent
        {
            get { return zoomInPercent; }
            set
            {
                if (value < 50)
                    value = 50;
                else if (value > 250)
                    value = 250;

                zoomInPercent = value;
                cFasdCockpitConfig.Instance.SetSlimPageZoom(value);
                OnPropertyChanged();
            }
        }

        #endregion

        #region Cockpit Properties

        #region HeadingData Property

        private List<cHeadingDataModel> headingData;

        public List<cHeadingDataModel> HeadingData
        {
            get { return headingData; }
            set
            {
                headingData = value;
                OnPropertyChanged();
            }
        }

        #endregion

        #region Widget Property

        private List<List<cWidgetValueModel>> widgetData;

        public List<List<cWidgetValueModel>> WidgetData
        {
            get { return widgetData; }
            set
            {
                widgetData = value;
                OnPropertyChanged();
            }
        }

        #endregion

        #region MenuBarData property

        private List<cMenuDataBase> menuBarData;

        public List<cMenuDataBase> MenuBarData
        {
            get { return menuBarData; }
            set
            {
                menuBarData = value;
                OnPropertyChanged();
                OnPropertyChanged(nameof(MenuDrawerData));
            }
        }

        #endregion

        #region MenuDrawerData property

        public List<cMenuDataBase> MenuDrawerData
        {
            get
            {
                if (MenuBarData != null)
                    return MenuBarData.Where(x => x.IconPositionIndex < 0).ToList();

                return new List<cMenuDataBase>();
            }
        }

        #endregion

        #endregion

        #region DataHistory Properties

        private List<cSlimPageDataHistoryModel> dataHistoryList;

        public List<cSlimPageDataHistoryModel> DataHistoryList
        {
            get { return dataHistoryList; }
            set
            {
                dataHistoryList = value;
                OnPropertyChanged();
            }
        }

        #endregion

        #endregion

        public SlimPageViewModel()
        {
            cFasdCockpitConfig.Instance.UiSettingsChanged += CockpitConfig_UiSettingsChanged;
        }

        private void CockpitConfig_UiSettingsChanged(object sender, EventArgs e)
        {
            ZoomInPercent = cFasdCockpitConfig.Instance.SlimPageZoom;
        }

        public void InitializeProperties(cSlimPageData slimPageData)
        {
            DataProvider = slimPageData.DataProvider;
            HeadingData = slimPageData.HeadingData;
            WidgetData = slimPageData.WidgetData;
            DataHistoryList = slimPageData.DataHistoryList;
            MenuBarData = slimPageData.MenuBarData;
        }
    }

}
