{{ define "admin_user_edit.pages.tmpl" }}
{{ template "head" . }}
<div class="columns">
  <!-- Sidebar -->
  {{ template "sidebar" . }}
  <div class="column is-10">
<h2 class="title is-4">Modifier l'utilisateur #{{ .U.ID }}</h2>

<!-- Flash message -->
<div id="userFlash"></div>
<form hx-put="/api/user/update/{{ .U.ID }}" hx-target="#userFlash" hx-swap="outerHTML" class="box">
  <div class="field">
    <label class="label">Email</label>
    <div class="control">
      <input class="input" type="email" name="email" value="{{ .U.Email }}" required>
    </div>
  </div>

  <div class="field">
    <label class="label">Mot de passe (laisser vide pour ne pas changer)</label>
    <div class="control">
      <input class="input" type="password" name="password">
    </div>
  </div>

  <div class="field">
    <label class="label">Role</label>
    <div class="control">
      <div class="select">
        <select name="role">
          <option value="CLIENT" {{ if eq .U.Role "CLIENT" }}selected{{ end }}>Client</option>
          <option value="ADMIN" {{ if eq .U.Role "ADMIN" }}selected{{ end }}>Admin</option>
        </select>
      </div>
    </div>
  </div>

  <div class="field">
    <label class="checkbox">
      <input type="checkbox" name="is_active" {{ if .U.IsActive }}checked{{ end }}> Actif
    </label>
  </div>

  <div class="field">
    <label class="label">Token WhatsApp</label>
    <input class="input" name="whatsapp_token" type="text" value="{{ .U.WhatsappToken }}">
  </div>

  <div class="field">
    <label class="label">Phone Number ID</label>
    <input class="input" name="whatsapp_phone_number_id" type="text" value="{{ .U.WhatsappPhoneNumberID }}">
  </div>

  <div class="field">
    <div class="control">
      <button class="button is-success" type="submit" hx-ext="json-enc">💾 Enregistrer</button>
    </div>
  </div>
</form>
</div>
</div>
{{ end }}
