@model MemberCenter.Application.Models.Admin.SecuritySettingsDto

<div class="admin-page-title">
  <h1>@L["Security Settings"]</h1>
</div>

@if (ViewData["Result"] is not null)
{
  <div class="admin-notice">@ViewData["Result"]</div>
}

<div class="admin-form-grid">
  <form asp-action="Save" method="post" class="admin-form-panel">
    @Html.AntiForgeryToken()
    <div asp-validation-summary="All"></div>
    <label>@L["Access token minutes"]</label>
    <input asp-for="AccessTokenMinutes" type="number" min="5" max="1440" />

    <label>@L["Refresh token days"]</label>
    <input asp-for="RefreshTokenDays" type="number" min="1" max="365" />

    <label asp-for="PublicBaseUrl">@L["Public base URL"]</label>
    <input asp-for="PublicBaseUrl" />

    <h2>SMTP</h2>
    <label asp-for="SmtpRelayHost">@L["SMTP relay host"]</label>
    <input asp-for="SmtpRelayHost" />

    <label asp-for="SmtpRelayPort">@L["SMTP relay port"]</label>
    <input asp-for="SmtpRelayPort" />

    <div class="admin-checkbox-row">
      <input asp-for="SmtpUseTls" type="checkbox" />
      <label asp-for="SmtpUseTls">@L["Use TLS"]</label>
    </div>

    <div class="admin-checkbox-row">
      <input asp-for="SmtpUseSsl" type="checkbox" />
      <label asp-for="SmtpUseSsl">@L["Use SSL"]</label>
    </div>

    <label asp-for="SmtpTimeoutSeconds">@L["SMTP timeout seconds"]</label>
    <input asp-for="SmtpTimeoutSeconds" />

    <label asp-for="SmtpUsername">@L["SMTP username"]</label>
    <input asp-for="SmtpUsername" />

    <label asp-for="SmtpPassword">@L["SMTP password"]</label>
    <input asp-for="SmtpPassword" type="password" />
    @if (Model.HasSmtpPassword)
    {
      <p class="admin-form-help">@L["Password saved. Leave blank to keep current password."]</p>
    }

    <label asp-for="SenderName">@L["Sender name"]</label>
    <input asp-for="SenderName" />

    <label asp-for="SenderEmail">@L["Sender email"]</label>
    <input asp-for="SenderEmail" />

    @if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.SecuritySave))
    {
      <button type="submit" class="account-action-button">@L["Save"]</button>
    }
  </form>

@if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.SecurityTestEmail))
{
  <form asp-action="TestEmail" method="post" class="admin-form-panel">
    <h2>@L["Test Email"]</h2>
    @Html.AntiForgeryToken()
    <input asp-for="AccessTokenMinutes" type="hidden" />
    <input asp-for="RefreshTokenDays" type="hidden" />
    <input asp-for="PublicBaseUrl" type="hidden" />
    <input asp-for="SmtpRelayHost" type="hidden" />
    <input asp-for="SmtpRelayPort" type="hidden" />
    <input asp-for="SmtpUseTls" type="hidden" />
    <input asp-for="SmtpUseSsl" type="hidden" />
    <input asp-for="SmtpTimeoutSeconds" type="hidden" />
    <input asp-for="SmtpUsername" type="hidden" />
    <input asp-for="SmtpPassword" type="hidden" />
    <input asp-for="HasSmtpPassword" type="hidden" />
    <input asp-for="SenderName" type="hidden" />
    <input asp-for="SenderEmail" type="hidden" />
    <label asp-for="TestToEmail">@L["Test recipient email"]</label>
    <input asp-for="TestToEmail" />
    <button type="submit" class="account-action-button">@L["Send Test Email"]</button>
  </form>
}
</div>
