using Elternbeirat.Contracts;
using Elternbeirat.Web.Features.Layout;
using Elternbeirat.Web.Shared;
namespace Elternbeirat.Web.Features.Home;
///
/// One tile on the home page, leading to a section of the site.
///
/// Target URL of the page.
/// The page's title.
///
/// The first sentence of the page's body, or an empty string, in which case the
/// tile shows only the title.
///
/// The icon name, see .
public sealed record HomeTile(string Href, string Title, string Description, string Icon)
{
///
/// Builds one tile per header page except the home page itself.
///
/// All public pages.
/// The tiles, in menu order.
///
/// The tiles mirror the header menu (), so a
/// page an editor puts into the header appears here too, without any code. The
/// home page is left out: a tile leading to the page it sits on would be useless.
///
public static IReadOnlyList From(IReadOnlyList pages) =>
[
.. NavBuilder.HeaderPages(pages)
.Where(page => !Page.IsHomeSlug(page.Slug))
.Select(page => new HomeTile(
NavBuilder.HrefFor(page.Slug),
page.Title,
Markdown.FirstSentence(page.Body),
TileIcons.For(page.Slug))),
];
}