@using FastBlog.Web.Middlewares
@model FastBlog.Web.Controllers.UsersController.UserViewModel

@{
    ViewData["Title"] = $"{Model.User.Username} - Профиль";
    bool isSelf = Context.TryGetUser(out var user) && user.Id == Model.User.Id;
}
<div class="container">
    <div class="grid">
        <article>
            <header>
                <h2>@Model.User.Username</h2>
            </header>
            <div class="grid">
                @if (isSelf)
                {
                    <p>This is your profile, @Model.User.Username</p>
                }
                else
                {
                    <div>
                        <p>Now editing @Model.User.Username's profile</p>
                        @if (!Model.User.Deleted)
                        {
                            <button hx-delete="/users/@Model.User.Id">Delete profile</button>
                        }
                    </div>
                }
            </div>
        </article>
        @if (isSelf)
        {
            <article>
                <header>Password</header>
                <div>
                    <form action="~/users/@Model.User.Id/change-password" method="post">
                        <div>
                            <label for="oldPassword">Old password:</label>
                            <input type="password" id="oldPassword" name="oldPassword" required>
                        </div>
                        <div>
                            <label for="newPassword">New password:</label>
                            <input type="password" id="newPassword" name="newPassword" required>
                        </div>
                        <div>
                            <button type="submit">
                                <span>Update</span>
                            </button>
                        </div>
                    </form>
                    @if (Model.Message is not null)
                    {
                        <div class="alert @(Model.Success ? "alert-tip" : "alert-caution")">
                            <p>@Model.Message</p>
                        </div>
                    }
                </div>
            </article>
        }
        else
        {
            <article>
                <header>Password</header>
                <div>
                    <form action="~/users/@Model.User.Id/set-password" method="post">
                        <div>
                            <label for="newPassword">New password:</label>
                            <input type="password" id="newPassword" name="newPassword" required>
                        </div>
                        <div>
                            <button type="submit">
                                <span>Set</span>
                            </button>
                        </div>
                    </form>
                    @if (Model.Message is not null)
                    {
                        <div class="alert @(Model.Success ? "alert-tip" : "alert-caution")">
                            <p>@Model.Message</p>
                        </div>
                    }
                </div>
            </article>
        }
    </div>
</div>