using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using System.Collections.Generic;
using System.Threading.Tasks;
using YBDevice.Application;
using YBDevice.Entity;

namespace YBDevice.NWeb.Pages.Shared.Components.Menu
{
    public class MenuViewComponent : ViewComponent
    {
        private ISystemService _systemService;
        public MenuViewComponent(ISystemService systemService)
        {
            _systemService = systemService;
        }
        public async Task<IViewComponentResult> InvokeAsync()
        {
            var data = await GetMenu();
            return View(data);
        }
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<YB_nMenu>> GetMenu()
        {
            var currentuser = BaseInfoService.GetUserInfo();
            var menuList = new List<YB_nMenu>();
            menuList = currentuser.IsSuper
                 ? await _systemService.GetMenuListAsync()
                 : await _systemService.GetMenuListAsync(currentuser.RoleId);
            return menuList;
        }
    }
}
