@page
@using Models;
@model WebApp.Pages.EditAnnouncementModel
@{
    ViewData["Title"] = "Edit announcement";
    Model.Announcement = (Announcement)ViewData["announcement"];
}

<h1>@ViewData["Title"]</h1>

@if (Model.Announcement == null)
{
    <div class="alert alert-danger" role="alert">
        Unable to find announcement! Do you have permission?
    </div>
    <a type="button" class="btn btn-primary" asp-page="Announcements">Return to all announcements</a>
}
else
{
    <form method="post">
        <div class="mb-3">
            <label asp-for="Announcement.Title" class="form-label">Title: </label>
            <input asp-for="Announcement.Title" class="form-control" />
        </div>
        @if (HttpContext.User.IsInRole("ADMIN") || HttpContext.User.IsInRole("MANAGER"))
        {
            <div class="mb-3">
                <label asp-for="Announcement.IsImportant" class="form-label">Important: </label>
                @Html.CheckBoxFor(model => model.Announcement.IsImportant)
            </div>
            <div class="mb-3">
                <label asp-for="Announcement.IsSticky" class="form-label">Pinned: </label>
                @Html.CheckBoxFor(model => model.Announcement.IsSticky)
            </div>
        }
        <div class="mb-3">
            <label asp-for="Announcement.Description" class="form-label">Description: </label>
            <textarea asp-for="Announcement.Description" class="form-control" rows="5"></textarea>
        </div>
        <input type="hidden" asp-for="Announcement.ID" />
        <input type="submit" value="Save" class="btn btn-primary" />
    </form>
}