{{define "content"}}
<section class="space-y-6">
  <div class="flex flex-wrap items-center justify-between gap-3">
    <div>
      <h1 class="text-3xl font-bold text-gray-900 dark:text-white" data-i18n="users.title">Users</h1>
      <p class="text-gray-600 dark:text-gray-300" data-i18n="users.subtitle">Ricerca, ordinamento e paging server-side via HTMX.</p>
    </div>
    <button type="button" data-modal-target="newUserModal" data-modal-toggle="newUserModal" class="inline-flex items-center rounded-lg bg-blue-700 px-5 py-2.5 text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300" data-i18n="users.new_user">
      Nuovo Utente
    </button>
  </div>

  <form id="usersFilters" class="flex gap-4 rounded-lg border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800 md:grid-cols-4" hx-get="/admin/users/table" hx-target="#usersTableContainer" hx-swap="innerHTML">
    <div class="flex-auto">
      <label for="users-q" class="mb-2 block text-sm font-medium text-gray-900 dark:text-white" data-i18n="users.search">Search</label>
      <input id="users-q" type="text" name="q" placeholder="Cerca nome o email" data-i18n-placeholder="users.search_placeholder" value="{{.PageData.Q}}" class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400">
    </div>
    <div style="max-width: 100px;" class="flex-none">
      <label for="users-size" class="mb-2 block text-sm font-medium text-gray-900 dark:text-white" data-i18n="users.page_size">Page size</label>
      <select id="users-size" name="pageSize" class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white" hx-get="/admin/users/table" hx-target="#usersTableContainer" hx-swap="innerHTML" hx-include="#usersFilters" hx-trigger="change">
        <option value="5" {{if eq .PageData.PageSize 5}}selected{{end}}>5</option>
        <option value="10" {{if eq .PageData.PageSize 10}}selected{{end}}>10</option>
        <option value="20" {{if eq .PageData.PageSize 20}}selected{{end}}>20</option>
        <option value="50" {{if eq .PageData.PageSize 50}}selected{{end}}>50</option>
        <option value="100" {{if eq .PageData.PageSize 100}}selected{{end}}>100</option>
        <option value="500" {{if eq .PageData.PageSize 500}}selected{{end}}>500</option>
      </select>
    </div>
    <div style="max-width: 120px;" class="flex-auto self-end">
      <button type="submit" class="w-full rounded-lg bg-blue-700 px-5 py-2.5 text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300" data-i18n="users.search_button">Cerca</button>
    </div>
    <input type="hidden" name="sort" value="{{.PageData.Sort}}">
    <input type="hidden" name="dir" value="{{.PageData.Dir}}">
    <input type="hidden" name="page" value="1">
  </form>

  <div id="usersTableContainer" class="rounded-lg border border-gray-200 bg-white p-2 shadow-sm dark:border-gray-700 dark:bg-gray-800 md:p-4" hx-get="/admin/users/table?q={{.PageData.Q}}&sort={{.PageData.Sort}}&dir={{.PageData.Dir}}&page={{.PageData.Page}}&pageSize={{.PageData.PageSize}}" hx-trigger="load" hx-swap="innerHTML">
    {{template "users_table" .}}
  </div>
</section>

<div id="userModal" tabindex="-1" aria-hidden="true" class="fixed left-0 right-0 top-0 z-50 hidden h-[calc(100%-1rem)] max-h-full w-full items-center justify-center overflow-y-auto overflow-x-hidden p-4 md:inset-0">
  <div class="relative max-h-full w-full max-w-2xl">
    <div class="relative rounded-lg bg-white shadow-sm dark:bg-gray-800">
      <div class="flex items-start justify-between rounded-t border-b p-4 dark:border-gray-700 md:p-5">
        <h3 class="text-xl font-semibold text-gray-900 dark:text-white" data-i18n="users.user_detail">Dettaglio utente</h3>
        <button type="button" class="ms-auto inline-flex h-8 w-8 items-center justify-center rounded-lg bg-transparent text-sm text-gray-400 hover:bg-gray-200 hover:text-gray-900 dark:hover:bg-gray-700 dark:hover:text-white" data-modal-hide="userModal" aria-label="Close modal">
          <span class="sr-only" data-i18n="users.close">Close modal</span>
          <svg class="h-3 w-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
          </svg>
        </button>
      </div>
      <div id="userModalContent" class="space-y-4 p-4 md:p-5"></div>
    </div>
  </div>
</div>

<div id="newUserModal" tabindex="-1" aria-hidden="true" class="fixed left-0 right-0 top-0 z-50 hidden h-[calc(100%-1rem)] max-h-full w-full items-center justify-center overflow-y-auto overflow-x-hidden p-4 md:inset-0">
  <div class="relative max-h-full w-full max-w-xl">
    <div class="relative rounded-lg bg-white shadow-sm dark:bg-gray-800">
      <div class="flex items-start justify-between rounded-t border-b p-4 dark:border-gray-700 md:p-5">
        <h3 class="text-xl font-semibold text-gray-900 dark:text-white" data-i18n="users.new_user_modal_title">Nuovo utente</h3>
        <button type="button" class="ms-auto inline-flex h-8 w-8 items-center justify-center rounded-lg bg-transparent text-sm text-gray-400 hover:bg-gray-200 hover:text-gray-900 dark:hover:bg-gray-700 dark:hover:text-white" data-modal-hide="newUserModal" aria-label="Close modal">
          <span class="sr-only" data-i18n="users.close">Close modal</span>
          <svg class="h-3 w-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
          </svg>
        </button>
      </div>
      <div class="space-y-4 p-4 md:p-5">
        <p class="text-sm text-gray-600 dark:text-gray-300" data-i18n="users.new_user_modal_placeholder">Placeholder UI Flowbite. La creazione utente può essere collegata a una route backend quando disponibile.</p>
        <div>
          <label for="new-user-email" class="mb-2 block text-sm font-medium text-gray-900 dark:text-white" data-i18n="form.email">Email</label>
          <input id="new-user-email" type="email" class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400" placeholder="name@company.com" disabled>
        </div>
      </div>
    </div>
  </div>
</div>
{{end}}
