using Demo_Project.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.WinControls.Diagrams;

namespace Demo_Project
{
    public class DistributionHallManager
    {
        private static List<BaseModel> List { get; set; } = new List<BaseModel>();

        public static ShelveModel GetShelveForSpot(SpotModel spotModel)
        {
            return List.FirstOrDefault(x => x is ShelveModel shelve && shelve.Spots.Contains(spotModel)) as ShelveModel;
        }

        public void DrawShelves()
        {
            foreach(var elem in List)
            {
                if (elem is ShelveModel shelve)
                {
                    shelve.Draw();
                    shelve.Group();
                }
            }
        }

        public void LoadHallData(Telerik.WinControls.UI.RadDiagram diagram)
        {
            var horShelve = new ShelveModel
            {
                Diagram = diagram,
                Name = "Shelve 1",
                Orientation = ShelveOrientation.LeftToRight,
                Position = new System.Drawing.Point(80, 40),
            };
            var verShelve = new ShelveModel
            {
                Diagram = diagram,
                Name = "Shelve 2",
                Orientation = ShelveOrientation.BottomToTop,
                Position = new System.Drawing.Point(80, 250),
            };
            for (int i = 1; i <= 5; i++)
            {
                var shelve1Spot = new SpotModel
                {
                    Diagram = diagram,
                    Name = $"Spot {i}",
                    Position = i
                };
                var shelve2Spot = new SpotModel
                {
                    Diagram = diagram,
                    Name = $"Spot {i}",
                    Position = i
                };
                horShelve.Spots.Add(shelve1Spot);
                verShelve.Spots.Add(shelve2Spot);
                List.Add(shelve1Spot);
                List.Add(shelve2Spot);
            }
            List.Add(horShelve);
            List.Add(verShelve);
        }
    }
}
