@model MemberCenter.TestSite.Models.TestDashboardViewModel
@{
    ViewData["Title"] = "Member Center Test Site";
    string ShortToken(string? token) => string.IsNullOrWhiteSpace(token)
        ? "not set"
        : $"{token[..Math.Min(18, token.Length)]}...";
}

<div class="test-hero">
  <div>
    <p class="eyebrow">Member Center Integration Test</p>
    <h1>API / Redirect Login Happy Paths</h1>
    <p>This test site stores tokens in its own ASP.NET session and runs the first 10 happy-path checks against Member Center.</p>
  </div>
  <form method="post" asp-action="ClearTokens">
    <button type="submit" class="danger">Clear Session Tokens</button>
  </form>
</div>

<section class="grid">
  <article class="card">
    <h2>Current Settings</h2>
    <dl>
      <dt>API Base URL</dt>
      <dd>@Model.Options.ApiBaseUrl</dd>
      <dt>Web Base URL</dt>
      <dd>@Model.Options.WebBaseUrl</dd>
      <dt>web_login Client ID</dt>
      <dd>@(string.IsNullOrWhiteSpace(Model.Options.WebLoginClientId) ? "not configured" : Model.Options.WebLoginClientId)</dd>
      <dt>Service Client ID</dt>
      <dd>@(string.IsNullOrWhiteSpace(Model.Options.ServiceClientId) ? "not configured" : Model.Options.ServiceClientId)</dd>
      <dt>User token</dt>
      <dd>@ShortToken(Model.UserAccessToken)</dd>
      <dt>Service token</dt>
      <dd>@ShortToken(Model.ServiceAccessToken)</dd>
    </dl>
  </article>

  <article class="card">
    <h2>1. Redirect Login</h2>
    <p>Uses <code>usage=web_login</code>, Authorization Code + PKCE, and this site's <code>/auth/callback</code>.</p>
    <form method="post" asp-action="RedirectLogin">
      <button type="submit">Start Redirect Login</button>
    </form>
    <form method="post" asp-action="Logout">
      <button type="submit">Direct Logout</button>
    </form>
  </article>

  <article class="card">
    <h2>Service Token</h2>
    <p>Uses a registered confidential client. Granted scopes are bounded by its configured usage.</p>
    <form method="post" asp-action="ServiceToken">
      <label>Client ID</label>
      <input name="clientId" value="@Model.Options.ServiceClientId" />
      <label>Client Secret</label>
      <input name="clientSecret" type="password" autocomplete="off" />
      <label>Scopes</label>
      <input name="scopes" value="@Model.Options.ServiceScopes" />
      <button type="submit">Get Service Token</button>
    </form>
  </article>
</section>

<section class="card">
  <h2>User Token Happy Paths</h2>
  <div class="actions">
    <form method="post" asp-action="UserProfileGet">
      <button type="submit">3. GET /user/profile</button>
    </form>
    <form method="post" asp-action="UserProfilePost">
      <button type="submit">4. POST /user/profile</button>
    </form>
    <form method="post" asp-action="UserAddressesGet">
      <button type="submit">5. GET /user/addresses</button>
    </form>
    <form method="post" asp-action="UserAddressesPost">
      <button type="submit">6. POST /user/addresses</button>
    </form>
    <form method="post" asp-action="UserSubscriptionsGet">
      <button type="submit">7. GET /user/subscriptions</button>
    </form>
  </div>
  <form method="post" asp-action="UserSubscriptionsUnsubscribe" class="inline-form">
    <label>Subscription ID</label>
    <input name="subscriptionId" placeholder="00000000-0000-0000-0000-000000000000" />
    <button type="submit">8. POST /user/subscriptions/{id}/unsubscribe</button>
  </form>
</section>

<section class="card response-card">
  <h2>Last Response</h2>
  <h3>@(Model.LastResponseTitle ?? "No request yet")</h3>
  <pre>@(Model.LastResponseBody ?? "Run a happy-path action to see the response here.")</pre>
</section>
