<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Security &amp; Profile &bull; <%= appName %></title>
  <%- headAssets %>
</head>
<body>

  <%- topNav %>

  <main class="admin-container">

    <div class="page-header">
      <div>
        <h1 class="page-title">Security &amp; Infrastructure Profile</h1>
        <p class="page-subtitle">Manage administrative credentials, session tokens, and hosting diagnostics</p>
      </div>
    </div>

    <% if (mustChangePassword) { %>
      <div class="flash-alert error">
        <span><strong>Action required.</strong> This account still uses a password that is published in the project files. The console stays locked until you set a new one below.</span>
      </div>
    <% } %>

    <% if (success) { %>
      <div class="flash-alert success">
        <span><%= success %></span>
      </div>
    <% } %>

    <% if (error) { %>
      <div class="flash-alert error">
        <span><%= error %></span>
      </div>
    <% } %>

    <div class="grid-1-1">

      <div class="form-card">
        <h2 class="card-heading card-heading-tight">Update Master Password</h2>
        <p class="help-line help-line-lg">
          Use at least 12 characters. A passphrase of several unrelated words works well.
        </p>

        <form method="POST" action="<%= url('admin/profile') %>" autocomplete="off">
          <%- csrfField %>

          <div class="form-group">
            <label class="form-label" for="current_password">Current Password <span class="required">*</span></label>
            <input type="password" id="current_password" name="current_password" class="form-control" required placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;">
          </div>

          <div class="form-group">
            <label class="form-label" for="new_password">New Password <span class="required">*</span></label>
            <input type="password" id="new_password" name="new_password" class="form-control" required minlength="12" placeholder="Minimum 12 characters">
          </div>

          <div class="form-group form-group-last">
            <label class="form-label" for="confirm_password">Confirm New Password <span class="required">*</span></label>
            <input type="password" id="confirm_password" name="confirm_password" class="form-control" required minlength="12" placeholder="Re-type new password">
          </div>

          <button type="submit" class="btn btn-primary btn-block">
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2">
              <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path>
            </svg>
            Save New Password
          </button>
        </form>
      </div>

      <div>
        <div class="form-card card-gap">
          <h2 class="card-heading">Active Administrator Account</h2>
          <table class="kv-table">
            <tr>
              <td class="kv-key kv-key-wide">Username</td>
              <td class="kv-val kv-strong"><%= currentAdmin.username || 'admin' %></td>
            </tr>
            <tr>
              <td class="kv-key">Email Address</td>
              <td class="kv-val kv-soft"><%= currentAdmin.email || '' %></td>
            </tr>
            <tr>
              <td class="kv-key">Account ID</td>
              <td class="kv-val">#<%= Number(currentAdmin.id || 1) %></td>
            </tr>
            <tr>
              <td class="kv-key">Session Lifetime</td>
              <td class="kv-val"><%= Math.floor(sessionLifetime / 3600) %> h maximum, <%= Number(adminIdleMinutes) %> min idle</td>
            </tr>
          </table>
        </div>

        <div class="form-card">
          <h2 class="card-heading">System Diagnostics &amp; Hosting</h2>
          <table class="kv-table">
            <tr>
              <td class="kv-key kv-key-wide">Database Engine</td>
              <td class="kv-val">
                <span class="badge-status <%= dbCheck.success ? 'active' : 'draft' %>">
                  <%= dbCheck.success ? 'Connected' : 'Connection Failed' %>
                </span>
                <span class="kv-note">
                  <%= dbCheck.driver || 'mysql' %> (<%= dbCheck.version || 'N/A' %>)
                </span>
              </td>
            </tr>
            <tr>
              <td class="kv-key">Node.js Runtime</td>
              <td class="kv-val"><%= nodeVersion %></td>
            </tr>
            <tr>
              <td class="kv-key">Upload Directory</td>
              <td class="kv-val">
                <span class="badge-status <%= isUploadWritable ? 'active' : 'draft' %>">
                  <%= isUploadWritable ? 'Writable' : 'Check Permissions' %>
                </span>
              </td>
            </tr>
            <tr>
              <td class="kv-key">Client IP Address</td>
              <td class="kv-val kv-soft"><%= clientIp %></td>
            </tr>
          </table>
        </div>
      </div>

    </div>

  </main>

  <%- shellEnd %>

</body>
</html>

