@extends('layouts.master')
@section('page-title') 
    Admin | {{ $page_title }}
@endsection
@section('page-css')
<link rel="stylesheet" href="{{ url('public/assets/libs/select2/dist/css/select2.css') }}">
<style>
    /* Small visual tweaks */
    .category-badge { font-weight: 600; color: #fff; padding: 0.25rem 0.5rem; border-radius: 0.25rem; font-size: .8rem; }
    .badge-district { background:#f6a623; }   /* amber */
    .badge-regional { background:#17a2b8; }   /* teal */
    .badge-national { background:#1f6feb; }   /* blue */
    .user-row:hover .row-actions { visibility: visible; opacity: 1; }
    .row-actions { visibility: hidden; opacity: 0; transition: .12s ease-in-out; }
    .table-avatar { width:36px; height:36px; object-fit:cover; border-radius:50%; }
    .toolbar { gap:.5rem; display:flex; flex-wrap:wrap; align-items:center; }
    .select-all { margin-right:.5rem; }
    @media (max-width: 767px) {
      .toolbar { flex-direction:column; align-items:stretch; }
    }
  </style>
@endsection
@section('page-content')
<div class="container py-4">
  <div class="d-flex align-items-center mb-3">
    <h3 class="me-auto">Manage Users</h3>
    <div class="text-muted">June 15, 2026</div>
  </div>

  <!-- Tabs -->
  <ul class="nav nav-tabs mb-3" id="userTabs" role="tablist">
    <li class="nav-item" role="presentation">
      <button class="nav-link active" id="district-tab" data-bs-toggle="tab" data-bs-target="#district" type="button" role="tab" aria-controls="district" aria-selected="true">District <span class="badge bg-secondary ms-1" id="count-district">3</span></button>
    </li>
    <li class="nav-item" role="presentation">
      <button class="nav-link" id="regional-tab" data-bs-toggle="tab" data-bs-target="#regional" type="button" role="tab" aria-controls="regional" aria-selected="false">Regional <span class="badge bg-secondary ms-1" id="count-regional">2</span></button>
    </li>
    <li class="nav-item" role="presentation">
      <button class="nav-link" id="national-tab" data-bs-toggle="tab" data-bs-target="#national" type="button" role="tab" aria-controls="national" aria-selected="false">National <span class="badge bg-secondary ms-1" id="count-national">1</span></button>
    </li>
  </ul>

  <!-- Shared toolbar -->
  <div class="card mb-3">
    <div class="card-body">
      <div class="toolbar">
        <!-- <div class="d-flex align-items-center">
          <input type="checkbox" id="globalSelect" class="form-check-input select-all" aria-label="Select all visible users">
          <div class="me-2">Select</div>
        </div> -->

        <div class="input-group" style="max-width:420px;">
          <span class="input-group-text">Search</span>
          <input id="globalSearch" class="form-control" type="search" placeholder="Search name, email or ID (press /)" aria-label="Search users">
        </div>

        <div class="ms-auto d-flex gap-2">
          <div class="dropdown">
            <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Filter</button>
            <ul class="dropdown-menu p-3" style="min-width:220px;">
              <div class="mb-2"><strong>Status</strong></div>
              <div class="form-check"><input class="form-check-input filter-status" type="checkbox" value="Active" id="fActive"><label class="form-check-label" for="fActive">Active</label></div>
              <div class="form-check"><input class="form-check-input filter-status" type="checkbox" value="Suspended" id="fSuspended"><label class="form-check-label" for="fSuspended">Suspended</label></div>
            </ul>
          </div>

          <button id="bulkMoveBtn" class="btn btn-primary" disabled data-bs-toggle="modal" data-bs-target="#moveModal">Move</button>
          <button id="bulkDeactivate" class="btn btn-outline-danger" disabled>Suspend</button>
        </div>
      </div>
    </div>
  </div>

  <!-- Tab content -->
  <div class="tab-content" id="userTabsContent">
    <!-- District -->
    <div class="tab-pane fade show active" id="district" role="tabpanel" aria-labelledby="district-tab">
      <div class="card mb-4">
        <div class="card-body p-0">
          <div class="table-responsive">
            <table class="table table-hover mb-0">
              <thead class="table-light">
                <tr>
                  <th style="width:42px;"></th>
                  <th>Person</th>
                  <th>Email</th>
                  <th>Role</th>
                  <th>Allowed Apps</th>
                  <th style="width:130px;">Actions</th>
                </tr>
              </thead>
              <tbody id="districtBody">
                <!-- Example rows -->
                <tr class="user-row" data-category="District" data-status="Active" data-name="Alice Doe" data-email="alice@example.com" data-id="D001">
                  <td><input class="row-select form-check-input" type="checkbox" aria-label="Select Alice Doe"></td>
                  <td class="align-middle">
                    <div class="d-flex align-items-center">
                      <img src="https://i.pravatar.cc/40?img=5" alt="avatar" class="table-avatar me-2">
                      <div>
                        <div class="fw-semibold">Alice Doe</div>
                        <div class="text-muted small">ID: D001</div>
                      </div>
                    </div>
                  </td>
                  <td class="align-middle">alice@example.com</td>
                  <td class="align-middle"><span class="category-badge badge-district">District</span> &middot; Manager</td>
                  <td class="align-middle">2026-06-10</td>
                  <td class="align-middle">
                    <div class="row-actions d-flex gap-2">
                      <button class="btn btn-sm btn-outline-secondary viewBtn" data-id="D001">View</button>
                      <button class="btn btn-sm btn-primary editBtn" data-id="D001" data-bs-toggle="modal" data-bs-target="#editModal">Edit</button>
                    </div>
                  </td>
                </tr>

                <tr class="user-row" data-category="District" data-status="Pending" data-name="Ben Kyle" data-email="ben@example.com" data-id="D002">
                  <td><input class="row-select form-check-input" type="checkbox" aria-label="Select Ben Kyle"></td>
                  <td class="align-middle">
                    <div class="d-flex align-items-center">
                      <img src="https://i.pravatar.cc/40?img=6" alt="avatar" class="table-avatar me-2">
                      <div>
                        <div class="fw-semibold">Ben Kyle</div>
                        <div class="text-muted small">ID: D002</div>
                      </div>
                    </div>
                  </td>
                  <td class="align-middle">ben@example.com</td>
                  <td class="align-middle"><span class="category-badge badge-district">District</span> &middot; Staff</td>
                  <td class="align-middle">2026-06-12</td>
                  <td class="align-middle">
                    <div class="row-actions d-flex gap-2">
                      <button class="btn btn-sm btn-outline-secondary viewBtn" data-id="D002">View</button>
                      <button class="btn btn-sm btn-primary editBtn" data-id="D002" data-bs-toggle="modal" data-bs-target="#editModal">Edit</button>
                    </div>
                  </td>
                </tr>

                <tr class="user-row" data-category="District" data-status="Suspended" data-name="Clara Park" data-email="clara@example.com" data-id="D003">
                  <td><input class="row-select form-check-input" type="checkbox" aria-label="Select Clara Park"></td>
                  <td class="align-middle">
                    <div class="d-flex align-items-center">
                      <img src="https://i.pravatar.cc/40?img=7" alt="avatar" class="table-avatar me-2">
                      <div>
                        <div class="fw-semibold">Clara Park</div>
                        <div class="text-muted small">ID: D003</div>
                      </div>
                    </div>
                  </td>
                  <td class="align-middle">clara@example.com</td>
                  <td class="align-middle"><span class="category-badge badge-district">District</span> &middot; Supervisor</td>
                  <td class="align-middle">2026-05-30</td>
                  <td class="align-middle">
                    <div class="row-actions d-flex gap-2">
                      <button class="btn btn-sm btn-outline-secondary viewBtn" data-id="D003">View</button>
                      <button class="btn btn-sm btn-primary editBtn" data-id="D003" data-bs-toggle="modal" data-bs-target="#editModal">Edit</button>
                    </div>
                  </td>
                </tr>

              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <!-- Regional -->
    <div class="tab-pane fade" id="regional" role="tabpanel" aria-labelledby="regional-tab">
      <div class="card mb-4">
        <div class="card-body p-0">
          <div class="table-responsive">
            <table class="table table-hover mb-0">
              <thead class="table-light">
                <tr>
                  <th style="width:42px;"></th>
                  <th>Person</th>
                  <th>Email</th>
                  <th>Role</th>
                  <th>Allowed Apps</th>
                  <th style="width:130px;">Actions</th>
                </tr>
              </thead>
              <tbody id="regionalBody">
                <tr class="user-row" data-category="Regional" data-status="Active" data-name="Derek Holt" data-email="derek@example.com" data-id="R001">
                  <td><input class="row-select form-check-input" type="checkbox" aria-label="Select Derek Holt"></td>
                  <td class="align-middle">
                    <div class="d-flex align-items-center">
                      <img src="https://i.pravatar.cc/40?img=8" alt="avatar" class="table-avatar me-2">
                      <div>
                        <div class="fw-semibold">Derek Holt</div>
                        <div class="text-muted small">ID: R001</div>
                      </div>
                    </div>
                  </td>
                  <td class="align-middle">derek@example.com</td>
                  <td class="align-middle"><span class="category-badge badge-regional">Regional</span> &middot; Lead</td>
                  <td class="align-middle">2026-06-13</td>
                  <td class="align-middle">
                    <div class="row-actions d-flex gap-2">
                      <button class="btn btn-sm btn-outline-secondary viewBtn" data-id="R001">View</button>
                      <button class="btn btn-sm btn-primary editBtn" data-id="R001" data-bs-toggle="modal" data-bs-target="#editModal">Edit</button>
                    </div>
                  </td>
                </tr>

                <tr class="user-row" data-category="Regional" data-status="Active" data-name="Eva Stone" data-email="eva@example.com" data-id="R002">
                  <td><input class="row-select form-check-input" type="checkbox" aria-label="Select Eva Stone"></td>
                  <td class="align-middle">
                    <div class="d-flex align-items-center">
                      <img src="https://i.pravatar.cc/40?img=9" alt="avatar" class="table-avatar me-2">
                      <div>
                        <div class="fw-semibold">Eva Stone</div>
                        <div class="text-muted small">ID: R002</div>
                      </div>
                    </div>
                  </td>
                  <td class="align-middle">eva@example.com</td>
                  <td class="align-middle"><span class="category-badge badge-regional">Regional</span> &middot; Coordinator</td>
                  <td class="align-middle">2026-06-11</td>
                  <td class="align-middle">
                    <div class="row-actions d-flex gap-2">
                      <button class="btn btn-sm btn-outline-secondary viewBtn" data-id="R002">View</button>
                      <button class="btn btn-sm btn-primary editBtn" data-id="R002" data-bs-toggle="modal" data-bs-target="#editModal">Edit</button>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <!-- National -->
    <div class="tab-pane fade" id="national" role="tabpanel" aria-labelledby="national-tab">
      <div class="card mb-4">
        <div class="card-body p-0">
          <div class="table-responsive">
            <table class="table table-hover mb-0">
              <thead class="table-light">
                <tr>
                  <th style="width:42px;"></th>
                  <th>Person</th>
                  <th>Email</th>
                  <th>Role</th>
                  <th>Allowed Apps</th>
                  <th style="width:130px;">Actions</th>
                </tr>
              </thead>
              <tbody id="nationalBody">
                <tr class="user-row" data-category="National" data-status="Active" data-name="Frank West" data-email="frank@example.com" data-id="N001">
                  <td><input class="row-select form-check-input" type="checkbox" aria-label="Select Frank West"></td>
                  <td class="align-middle">
                    <div class="d-flex align-items-center">
                      <img src="https://i.pravatar.cc/40?img=10" alt="avatar" class="table-avatar me-2">
                      <div>
                        <div class="fw-semibold">Frank West</div>
                        <div class="text-muted small">ID: N001</div>
                      </div>
                    </div>
                  </td>
                  <td class="align-middle">frank@example.com</td>
                  <td class="align-middle"><span class="category-badge badge-national">National</span> &middot; Director</td>
                  <td class="align-middle">2026-06-05</td>
                  <td class="align-middle">
                    <div class="row-actions d-flex gap-2">
                      <button class="btn btn-sm btn-outline-secondary viewBtn" data-id="N001">View</button>
                      <button class="btn btn-sm btn-primary editBtn" data-id="N001" data-bs-toggle="modal" data-bs-target="#editModal">Edit</button>
                    </div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- Pagination stub -->
  <nav aria-label="User list pages" class="d-flex justify-content-end">
    <ul class="pagination pagination-sm">
      <li class="page-item disabled"><a class="page-link" href="#" tabindex="-1">Prev</a></li>
      <li class="page-item active"><a class="page-link" href="#">1</a></li>
      <li class="page-item"><a class="page-link" href="#">2</a></li>
      <li class="page-item"><a class="page-link" href="#">Next</a></li>
    </ul>
  </nav>
</div>

<!-- Edit modal -->
<div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="editModalLabel">Edit user</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <form id="editForm">
        <div class="modal-body">
          <input type="hidden" id="editId">
          <div class="mb-3"><label class="form-label">Name</label><input id="editName" class="form-control"></div>
          <div class="mb-3"><label class="form-label">Email</label><input id="editEmail" class="form-control" type="email"></div>
          <div class="mb-3">
            <label class="form-label">Category</label>
            <select id="editCategory" class="form-select">
              <option>District</option>
              <option>Regional</option>
              <option>National</option>
            </select>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary">Save</button>
        </div>
      </form>
    </div>
  </div>
</div>

<!-- Move modal (bulk) -->
<div class="modal fade" id="moveModal" tabindex="-1" aria-labelledby="moveModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="moveModalLabel">Move selected users</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <form id="moveForm">
        <div class="modal-body">
          <p id="moveCountText">Move <span id="moveCount">0</span> users to:</p>
          <div class="mb-3">
            <select id="moveTarget" class="form-select" required>
              <option value="">Choose category</option>
              <option value="District">District</option>
              <option value="Regional">Regional</option>
              <option value="National">National</option>
            </select>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary">Move</button>
        </div>
      </form>
    </div>
  </div>
</div>

@endsection
@section('page-js')
  <script src="{{ url('public/assets/libs/select2/dist/js/select2.full.min.js') }}" type="text/javascript" ></script>
  <script src="{{ url('public/assets/js/user_mgt_new.js') }}" type="text/javascript" ></script>


@endsection
