using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppLibs.Libs
{
    public class WSNavigation
    {
        private static List<NavItem> list;

        private static Task t;

        public static void LoadJson()
        {
            t = Task.Run(() => LoadNavItem());
        }

        static async Task LoadNavItem()
        {
            list = new List<NavItem>();
            using (var reader = new StreamReader(Path.GetFullPath("Json/navlist.json")))
            {
                string json = await reader.ReadToEndAsync();
                list = JsonConvert.DeserializeObject<List<NavItem>>(json);
            }
        }
        public static List<NavItem> GetListMenu()
        {
            if (t != null)
            {
                if (t.IsCompleted)
                {
                    return list;
                }
                else
                {
                    t.Wait();
                }
                return list;
            }
            return new List<NavItem>();

        }
    }
}
