using System;
using System.Collections.Generic;
using System.ComponentModel;
using Windows.UI.Xaml.Controls;

namespace TreeViewSamples
{
    public class Data
    {
        public static List<CompanyItem> LoadData(Uri baseUri)
        {
            List<CompanyItem> data = new List<CompanyItem>()
            {
                new CompanyItem()
                {
                    Name = "Council of Directors",
                    Icon = new Uri(baseUri, "../../Resources/company/group.png"),
                    Children = new List<CompanyItem>()
                    {
                        new CompanyItem()
                        {
                            Name = "Principal: Alex Vera",
                            Icon = new Uri(baseUri, "../../Resources/company/director.png"),
                            Children = new List<CompanyItem>()
                            {
                                new CompanyItem()
                                {
                                    Name = "Director Of Finance & Admin: Bruno Maxtor",
                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                    Children = new List<CompanyItem>()
                                    {
                                        new CompanyItem()
                                        {
                                            Name = "Finance Office",
                                            Icon = new Uri(baseUri, "../../Resources/company/group.png"),
                                            Children = new List<CompanyItem>()
                                            {
                                                new CompanyItem()
                                                {
                                                    Name = "Manager: Bruno Gates",
                                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                                    Children = new List<CompanyItem>() {}
                                                },
                                                new CompanyItem()
                                                {
                                                    Name = "Assistant Manager: Michael Vera",
                                                    Icon = new Uri(baseUri, "../../Resources/company/assistant.png"),
                                                    Children = new List<CompanyItem>() {}
                                                }
                                            }
                                        },
                                        new CompanyItem()
                                        {
                                            Name = "Legal & Property",
                                            Icon = new Uri(baseUri, "../../Resources/company/group.png"),
                                            Children = new List<CompanyItem>()
                                            {
                                                 new CompanyItem()
                                                {
                                                    Name = "Manager: Noela Johnson",
                                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                                    Children = new List<CompanyItem>() {}
                                                },
                                                new CompanyItem()
                                                {
                                                    Name = "Assistant Manager: Martin Days",
                                                    Icon = new Uri(baseUri, "../../Resources/company/assistant.png"),
                                                    Children = new List<CompanyItem>() {}
                                                }
                                            }
                                        },
                                        new CompanyItem()
                                        {
                                            Name = "Travel Office",
                                            Icon = new Uri(baseUri, "../../Resources/company/group.png"),
                                            Children = new List<CompanyItem>()
                                            {
                                                 new CompanyItem()
                                                {
                                                    Name = "Manager: Leonard Jhonson",
                                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                                    Children = new List<CompanyItem>() {}
                                                },
                                                new CompanyItem()
                                                {
                                                    Name = "Assistant Manager: Rodrigo Beckham",
                                                    Icon = new Uri(baseUri, "../../Resources/company/assistant.png"),
                                                    Children = new List<CompanyItem>() {}
                                                }
                                            }
                                        }
                                    }
                                },
                                new CompanyItem()
                                {
                                    Name = "Dean Of Students: Ben Smith",
                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                    Children = new List<CompanyItem>()
                                    {
                                        new CompanyItem()
                                        {
                                            Name = "Assistant Dean: Max Days",
                                            Icon = new Uri(baseUri, "../../Resources/company/assistant.png"),
                                            Children = new List<CompanyItem>() {}
                                        },
                                        new CompanyItem()
                                        {
                                            Name = "Counselling",
                                            Icon = new Uri(baseUri, "../../Resources/company/group.png"),
                                            Children = new List<CompanyItem>()
                                            {
                                                 new CompanyItem()
                                                {
                                                    Name = "Counselor: Sheela Alvarez",
                                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                                    Children = new List<CompanyItem>() {}
                                                },
                                                new CompanyItem()
                                                {
                                                    Name = "Assistant Counselor: John Maxtor",
                                                    Icon = new Uri(baseUri, "../../Resources/company/assistant.png"),
                                                    Children = new List<CompanyItem>() {}
                                                }
                                            }
                                        },
                                        new CompanyItem()
                                        {
                                            Name = "Student Services",
                                            Icon = new Uri(baseUri, "../../Resources/company/group.png"),
                                            Children = new List<CompanyItem>()
                                            {
                                                 new CompanyItem()
                                                {
                                                    Name = "Manager: Peter Meredith",
                                                    Icon = new Uri(baseUri, "../../Resources/company/manager.png"),
                                                    Children = new List<CompanyItem>() {}
                                                },
                                                new CompanyItem()
                                                {
                                                    Name = "Assistant Manager: Jean Jobs",
                                                    Icon = new Uri(baseUri, "../../Resources/company/assistant.png"),
                                                    Children = new List<CompanyItem>() {}
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            return data;
        }
    }

    public class CompanyItem : INotifyPropertyChanged, IEditableObject
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private string _name;
        private string _previousName;

        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Name"));
                }
            }
        }

        public Uri Icon { get; set; }
        public List<CompanyItem> Children { get; set; }

        public void BeginEdit()
        {
            _previousName = Name;
        }

        public void CancelEdit()
        {
            Name = _previousName;
        }

        public void EndEdit()
        {
            _previousName = null;
        }
    }

}
