using AppLibs.Libs;
using Microsoft.AspNetCore.Mvc;

namespace TWA_App.Controllers
{
    public class ServicesController : Controller
    {
        [PageInfor("3000", "Services", "/Services/*")]
        [Layout(LayoutOptions.Default)]
        public async Task<IActionResult> Index(string? id)
        {
            if (id != null)
            {
                NavItem list = (await WSNavigation.GetListMenu())[2];
                if (list.SubItem != null && list.SubItem.Count > 0)
                {
                    NavItem? result = list.SubItem.FirstOrDefault(l => l.Url.Split('/').Last().Equals(id));
                    if (result != null)
                    {
                        ViewData["PageID"] = result.ID;
                        ViewData["Title"] = result.Name;

                        ViewBag.Content = await this.ReadStaticPage(Path.Join("services", result.ID + ".html"));
                        return await this.ViewAsync();
                    }
                }
            }
            return NotFound();
        }

    }
}
