@model MemberCenter.Web.Areas.Admin.Models.AccountDetailViewModel
@{
    ViewData["Title"] = Model.DisplayName;
    var profile = Model.Profile;
    var avatarText = Model.DisplayName[..1].ToUpperInvariant();
}

@if (TempData["Result"] is string result)
{
  <div class="alert alert-success">@result</div>
}

@if (TempData["Error"] is string error)
{
  <div class="alert alert-danger">@error</div>
}

<div class="account-detail-title">
  <a class="account-detail-back" asp-action="Index" aria-label="@L["Back to member list"]">&lt;</a>
  <h1>@Model.DisplayName</h1>
  <div class="account-detail-actions">
    @if (Model.CanAssignAdmin)
    {
      <form method="post" asp-action="SetAdmin" asp-route-id="@Model.UserId">
        @Html.AntiForgeryToken()
        <input type="hidden" name="enabled" value="@(Model.IsAdmin ? "false" : "true")" />
        <input type="hidden" name="returnTo" value="details" />
        <button type="submit" class="account-action-button">@(Model.IsAdmin ? L["Remove admin role"] : L["Assign admin role"])</button>
      </form>
    }

    @if (Model.CanDisableAccount)
    {
      <form method="post" asp-action="SetDisabled" asp-route-id="@Model.UserId">
        @Html.AntiForgeryToken()
        <input type="hidden" name="disabled" value="@(Model.IsDisabled ? "false" : "true")" />
        <input type="hidden" name="returnTo" value="details" />
        <button type="submit" class="account-action-button is-danger">@(Model.IsDisabled ? L["Unfreeze account"] : L["Freeze account"])</button>
      </form>
    }

    @if (Model.CanResetPassword)
    {
      <a class="account-action-button" href="#reset-password-@Model.UserId">@L["Change Password"]</a>
    }

    @if (Model.CanContact)
    {
      <button type="button" class="account-action-button" disabled>@L["Contact"]</button>
    }
  </div>
</div>

@if (Model.CanResetPassword)
{
  <div id="reset-password-@Model.UserId" class="admin-modal" role="dialog" aria-modal="true" aria-labelledby="reset-password-title-@Model.UserId">
    <a class="admin-modal-backdrop" href="#" aria-label="@L["Close password reset dialog"]"></a>
    <div class="admin-modal-panel">
      <a class="admin-modal-close" href="#" aria-label="@L["Close password reset dialog"]">×</a>
      <h2 id="reset-password-title-@Model.UserId">@L["Change Password"]</h2>
      <p>@Model.Profile.Email</p>
      <form method="post" asp-action="ResetPassword" asp-route-id="@Model.UserId" class="admin-modal-form">
        @Html.AntiForgeryToken()
        <input type="password" name="newPassword" placeholder="@L["Enter new password"]" minlength="8" required />
        <input type="hidden" name="returnTo" value="details" />
        <button type="submit" class="account-action-button">@L["Confirm change"]</button>
      </form>
    </div>
  </div>
}

<div class="account-detail-grid">
  <section class="profile-panel profile-summary-panel account-detail-profile-panel">
    <div class="profile-summary-header">
      <div class="account-detail-avatar-wrap">
        @if (Model.HasProfileImage)
        {
          <img
            class="profile-avatar"
            src="@Url.Action("Avatar", "Accounts", new { area = "Admin", id = Model.UserId, v = Model.ProfileImageVersion })"
            alt="@L["Profile image"]" />
        }
        else
        {
          <div class="profile-avatar" aria-hidden="true">@avatarText</div>
        }
        @if (Model.IsAdmin)
        {
          <span class="account-detail-admin-star" title="@L["Administrator"]" aria-label="@L["Administrator"]"></span>
        }
      </div>
      <div>
        <p>@L["Member ID"]</p>
        @if (Model.IsAdmin)
        {
          <p class="account-detail-role-label">@L["Administrator"]</p>
        }
        <p>@Model.UserId</p>
      </div>
    </div>

    <dl class="profile-detail-list">
      <div>
        <dt>@L["Last name"]</dt>
        <dd>@(profile.LastName ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["First name"]</dt>
        <dd>@(profile.FirstName ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["Nickname"]</dt>
        <dd>@(profile.NickName ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["Email"]</dt>
        <dd>
          @profile.Email
          <span class="profile-status @(profile.EmailConfirmed ? "is-ok" : "is-pending")">
            @(profile.EmailConfirmed ? L["Verified"] : L["Unverified"])
          </span>
        </dd>
      </div>
      <div>
        <dt>@L["Date of birth"]</dt>
        <dd>@(profile.DateOfBirth?.ToString("yyyy/MM/dd") ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["Mobile phone"]</dt>
        <dd>@(profile.MobilePhone ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["Company name"]</dt>
        <dd>@(profile.CompanyName ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["Job title"]</dt>
        <dd>@(profile.JobTitle ?? L["Not set"].Value)</dd>
      </div>
      <div>
        <dt>@L["Account status"]</dt>
        <dd>@(Model.IsDisabled ? L["Frozen"] : Model.IsBlacklisted ? L["Blacklist"] : L["Normal"])</dd>
      </div>
      <div>
        <dt>@L["Created"]</dt>
        <dd>@Model.CreatedAt.ToString("yyyy/MM/dd HH:mm")</dd>
      </div>
      <div>
        <dt>@L["Last login"]</dt>
        <dd>@(Model.LastLoginAt?.ToString("yyyy/MM/dd HH:mm") ?? "-")</dd>
      </div>
    </dl>
  </section>

  <aside class="account-detail-subscriptions">
    <div class="account-detail-subscription-count">
      <span>@L["Newsletter subscription count:"]</span>
      <strong>@Model.Subscriptions.Count</strong>
    </div>

    @if (!Model.Subscriptions.Any())
    {
      <p class="profile-empty">@L["No newsletter subscriptions."]</p>
    }
    else
    {
      <ul class="account-detail-subscription-list">
      @foreach (var subscription in Model.Subscriptions)
      {
        <li>
          <span>@subscription.ListName</span>
          <span>@subscription.Status</span>
        </li>
      }
      </ul>
    }
  </aside>
</div>
