using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using MECF.Framework.UI.Client.RecipeEditorLib.DGExtension.CustomColumn;
using SciChart.Charting2D.Interop;

namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params
{
    public class PositionParam : ParamBaseWithGenericValue<string>
    {
        public override string Value
        {
            get => _value;
            set
            {
                OptionChanged(value);
                Set(ref _value, value);
            }
        }
        public ObservableCollection<ComboxColumn.Option> Options { get; set; }

        private void OptionChanged(string value)
        {
            IEnumerable<ComboxColumn.Option> opts = Options.Where(op => op.ControlName == value);

            if (opts.Count() > 0)
            {
                string[] relatedparams = opts.ToList()[0].RelatedParameters.Split(',');
                Parent.ToList().ForEach(param =>
                {
                    if (relatedparams.Contains(param.ControlName) || param.ControlName == "Position" || param.ControlName == "StepNo" || param.ControlName == "Module")
                        param.Visible = Visibility.Visible;
                    else
                        param.Visible = Visibility.Hidden;
                });
            }
            else
            {
                Parent.ToList().ForEach(param =>
                {
                    if (param.ControlName == "Position" || param.ControlName == "StepNo" || param.ControlName == "Module")
                        param.Visible = Visibility.Visible;
                    else
                        param.Visible = Visibility.Hidden;
                });
            }
        }
    }
}
