<%- include("partials/layout-top", { title }) %>
<section class="card">
  <h1>Discord setup wizard</h1>
  <p>Follow the steps below. We will verify your details before saving anything.</p>
  <ol class="wizard-steps">
    <li>Create a Discord application and bot in the Discord Developer Portal.</li>
    <li>Copy the Client ID, Client Secret, Bot Token, and your Server (Guild) ID.</li>
    <li>Paste them here and click <strong>Verify and save</strong>.</li>
  </ol>

  <% if (errors && errors.length) { %>
  <div class="flash error">
    <strong>We could not verify your Discord settings:</strong>
    <ul class="wizard-list">
      <% errors.forEach((error) => { %>
      <li><%= error %></li>
      <% }) %>
    </ul>
  </div>
  <% } %>

  <% if (checks && checks.length) { %>
  <div class="flash success">
    <strong>Verification checks passed:</strong>
    <ul class="wizard-list">
      <% checks.forEach((check) => { %>
      <li><%= check %></li>
      <% }) %>
    </ul>
  </div>
  <% } %>

  <form method="post" action="<%= actionBase %>/verify" class="form-grid">
    <div class="field">
      <label>Client ID</label>
      <input name="discord_client_id" value="<%= form.discord_client_id || '' %>" required />
      <span class="hint">Find this in Discord Developer Portal → OAuth2 → General.</span>
    </div>
    <div class="field">
      <label>Client Secret</label>
      <input name="discord_client_secret" type="password" placeholder="Leave blank to keep existing" />
      <span class="hint">Create or copy it from OAuth2 → General.</span>
    </div>
    <div class="field">
      <label>Bot Token</label>
      <input name="discord_bot_token" type="password" placeholder="Leave blank to keep existing" />
      <span class="hint">Find this in the Bot tab (Reset Token if needed).</span>
    </div>
    <div class="field">
      <label>Server (Guild) ID</label>
      <input name="discord_guild_id" value="<%= form.discord_guild_id || '' %>" required />
      <span class="hint">Enable Developer Mode in Discord, then right-click your server to copy the ID.</span>
    </div>
    <div class="field">
      <label>Admin role ID</label>
      <input name="discord_admin_role_id" value="<%= form.discord_admin_role_id || '' %>" />
    </div>
    <div class="field">
      <label>Moderator role ID</label>
      <input name="discord_mod_role_id" value="<%= form.discord_mod_role_id || '' %>" />
    </div>
    <div class="field full">
      <label>Redirect URI</label>
      <input
        name="discord_redirect_uri"
        value="<%= form.discord_redirect_uri || '' %>"
        placeholder="https://your-domain.com/auth/discord/callback"
      />
      <span class="hint">Use the same redirect URI in the Discord app settings.</span>
    </div>
    <div class="field full">
      <span class="hint">Required OAuth scopes: identify, guilds, guilds.members.read.</span>
    </div>
    <button type="submit" class="button">Verify and save</button>
    <button
      type="submit"
      formaction="<%= actionBase %>/cancel"
      formnovalidate
      class="button subtle"
    >
      Cancel
    </button>
  </form>
</section>
<%- include("partials/layout-bottom") %>
