<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile - Bakorwil III Malang</title>
<link rel="icon" href="{{ asset('images/pustaka.jpeg') }}" type="image/png">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700;800&display=swap" rel="stylesheet">

<style>
  /* Menghilangkan scrollbar untuk IE, Edge, dan Firefox */
html, body {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}
body {
  font-family: 'Inter', sans-serif;
  background: #f7f9fc;
  color: #212529;
  margin: 0;
  min-height: 100vh;
}
.navbar-custom {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.navbar-brand {
  font-weight: 700;
  color: #007bff;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.navbar-brand img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.nav-link {
  color: #495057;
  font-weight: 500;
  transition: 0.3s;
}
.nav-link:hover {
  color: #007bff;
}
.navbar-buttons .btn {
  margin-left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  border-radius: 6px;
  transition: all 0.3s ease;
}
.btn-primary-modern {
  background-color: #007bff;
  color: #fff;
  border: none;
}
.btn-primary-modern:hover {
  background-color: #0056b3;
}
.btn-danger-modern {
  background-color: #f8f9fa;
  color: #dc3545;
  border: 1px solid #dc3545;
}
.btn-danger-modern:hover {
  background-color: #dc3545;
  color: #fff;
}
.btn-warning-modern {
  background-color: #ffc107;
  color: #212529;
  border: none;
}
.btn-warning-modern:hover {
  background-color: #e0a800;
  color: #fff;
}
.profile-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 60px 20px;
}
.profile-card {
  background: #fff;
  border-radius: 20px;
  width: 100%;
  max-width: 430px;
  padding: 40px 30px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.08);
  text-align: center;
  transition: transform 0.3s, box-shadow 0.3s;
}
.profile-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 15px 35px rgba(0,0,0,0.12);
}
.avatar-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 20px;
}
.avatar-wrapper img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0,123,255,0.3);
}
.avatar-wrapper input[type="file"] {
  display: none;
}
.edit-avatar-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  background: #007bff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  cursor: pointer;
  transition: 0.3s;
  border: 2px solid #fff;
}
.edit-avatar-btn:hover {
  background: #0056b3;
}
.profile-card h4 {
  font-weight: 700;
  margin-bottom: 25px;
  color: #212529;
}
.user-info p {
  margin-bottom: 15px;
  text-align: left;
  font-size: 0.95rem;
  padding: 12px 15px;
  background: #f1f3f6;
  border-radius: 12px;
}
.user-info strong {
  font-size: 0.75rem;
  color: #007bff;
  margin-bottom: 3px;
  text-transform: uppercase;
  display: block;
}
@media (max-width: 991px) {
  .navbar-custom { padding: 0.6rem 1rem; }
  .navbar-brand { font-size: 1.1rem; }
  .navbar-buttons { flex-direction: column; gap: 10px; }
  .navbar-buttons .btn { width: 100%; justify-content: center; }
  .profile-card { padding: 30px 20px; }
  .avatar-wrapper { width: 100px; height: 100px; }
  .avatar-wrapper img { width: 100px; height: 100px; }
  .edit-avatar-btn { width: 34px; height: 34px; }
  .user-info p { font-size: 0.9rem; }
}
body.force-desktop .navbar-custom {
  flex-direction: row !important;
  justify-content: space-between !important;
}
body.force-desktop .navbar-buttons {
  flex-direction: row !important;
  gap: 10px;
}
body.force-desktop .navbar-buttons .btn {
  width: auto !important;
}
body.force-desktop .profile-container {
  padding: 80px 0 !important;
}

.avatar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    border-radius: 50%;
    display: none;
    justify-content: center;
    align-items: center;
}
.avatar-overlay .overlay-menu {
    width: 75%;
    text-align: center;
}
</style>
</head>
<body>

@php
$fotoPath = ($user->foto && file_exists(public_path('storage/foto/'.$user->foto)))
    ? asset('storage/foto/'.$user->foto)
    : asset('images/default-user.png');
@endphp

<nav class="navbar navbar-expand-lg navbar-custom">
  <div class="container">
    <a class="navbar-brand" href="{{ route('admin.profile') }}">
      <img src="{{ asset('images/kartu.png') }}" alt="Logo">
      PUSTAKA NAWASENA
    </a>

    <button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
      <i class="bi bi-list" style="font-size:1.5rem;"></i>
    </button>

    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav ms-auto align-items-center">
        <li class="nav-item navbar-buttons d-flex flex-wrap">
          <a href="{{ route('admin.security') }}" class="btn btn-warning-modern">
            <i class="bi bi-shield-lock"></i> Keamanan Akun
          </a>

          <form method="POST" action="{{ route('logout') }}">
            @csrf
            <button type="submit" class="btn btn-danger-modern">
              <i class="bi bi-box-arrow-right"></i> Logout
            </button>
          </form>

          <a href="{{ route('admin.dashboard') }}" class="btn btn-primary-modern">
            <i class="bi bi-house-door-fill"></i> Home
          </a>
        </li>
      </ul>
    </div>
  </div>
</nav>

<div class="profile-container">
  <div class="profile-card">

    <div class="avatar-wrapper">

        <img id="preview-avatar" src="{{ $fotoPath }}" alt="Foto Profil">

        <div class="avatar-overlay" id="avatarOverlay">
            <div class="overlay-menu">

                <label for="uploadFoto" class="btn btn-light btn-sm w-100 mb-2">
                    <i class="bi bi-camera"></i> Ganti Foto
                </label>

                @if($user->foto)
                <form action="{{ route('admin.delete_foto') }}" method="POST">
                    @csrf
                    @method('DELETE')
                    <button type="submit" class="btn btn-danger btn-sm w-100">
                        <i class="bi bi-trash"></i> Hapus Foto
                    </button>
                </form>
                @endif

            </div>
        </div>

        <label for="uploadFoto" class="edit-avatar-btn">
            <i class="bi bi-camera-fill"></i>
        </label>

        <form id="formUpdateFoto" action="{{ route('admin.update_foto') }}" method="POST" enctype="multipart/form-data">
            @csrf
            <input type="file" name="foto" id="uploadFoto" accept="image/*">
        </form>

        @if($user->foto)
        <form action="{{ route('admin.delete_foto') }}" method="POST" style="margin-top:10px;">
            @csrf
            @method('DELETE')
            
        </form>
        @endif
    </div>

    <h4>Admin Profile</h4>

    <div class="user-info">
      <p><strong>Nama Lengkap</strong> {{ $user->name }}</p>
      <p><strong>Email</strong> {{ $user->email }}</p>

      @if(isset($user->created_at))
      <p><strong>Terdaftar Sejak</strong> {{ $user->created_at->format('d M Y') }}</p>
      @endif
    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

<script>
document.getElementById("uploadFoto").addEventListener("change", function() {
    const file = this.files[0];
    if (!file) return;

    const reader = new FileReader();
    reader.onload = function(e) {
        document.getElementById("preview-avatar").src = e.target.result;
    };
    reader.readAsDataURL(file);

    document.getElementById("formUpdateFoto").submit();
});
</script>

<script>
document.getElementById("preview-avatar").addEventListener("click", function () {
    document.getElementById("avatarOverlay").style.display = "flex";
});

document.getElementById("avatarOverlay").addEventListener("click", function (e) {
    if (e.target.id === "avatarOverlay") {
        this.style.display = "none";
    }
});
</script>

<script>
document.addEventListener("DOMContentLoaded", function() {
  const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
  const pixelRatio = window.devicePixelRatio;

  if (isMobile && pixelRatio <= 1.3) {
    document.body.classList.add("force-desktop");
  }
});
</script>

</body>
</html>

