@extends('layout.app')

@section('content')
<div class="pagetitle">
  <h1>Profile</h1>
  <nav>
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="{{ route('admindash') }}">Home</a></li>
      <li class="breadcrumb-item"><a href="{{ route('admin.profile') }}">Profile</a></li>
    </ol>
  </nav>
</div>

<section class="section profile">
  <div class="row">
    <!-- Kartu info ringkas -->
    <div class="col-xl-4">
      <div class="card">
        <div class="card-body pt-4 text-center">
          <h2>{{ $user->name }}</h2>
          <h5 class="text-muted mb-0">{{ $user->role->name ?? '-' }}</h5>
        </div>
      </div>
    </div>

    <!-- Tabs -->
    <div class="col-xl-8">
      <div class="card">
        <div class="card-body pt-3">
          <ul class="nav nav-tabs nav-tabs-bordered">
            <li class="nav-item">
              <button class="nav-link active" data-bs-toggle="tab"
                      data-bs-target="#tab-overview">Overview</button>
            </li>
            <li class="nav-item">
              <button class="nav-link" data-bs-toggle="tab"
                      data-bs-target="#tab-edit">Edit Profile</button>
            </li>
            <li class="nav-item">
              <button class="nav-link" data-bs-toggle="tab"
                      data-bs-target="#tab-password">Change Password</button>
            </li>
          </ul>

          <div class="tab-content pt-2">

            <!-- ========= Overview ========= -->
            <div class="tab-pane fade show active profile-overview" id="tab-overview">
              <h5 class="card-title">Profile Details</h5>

              <div class="row mb-3">
                <div class="col-lg-3 col-md-4 label">Name</div>
                <div class="col-lg-9 col-md-8">{{ $user->name }}</div>
              </div>

              <div class="row mb-3">
                <div class="col-lg-3 col-md-4 label">Email</div>
                <div class="col-lg-9 col-md-8">{{ $user->email }}</div>
              </div>

              <div class="row mb-3">
                <div class="col-lg-3 col-md-4 label">Phone</div>
                <div class="col-lg-9 col-md-8">{{ $user->no_telp }}</div>
              </div>


              <div class="row mb-3">
                <div class="col-lg-3 col-md-4 label">Role</div>
                <div class="col-lg-9 col-md-8">{{ $user->role->name ?? '-' }}</div>
              </div>
            </div>

            <!-- ========= Edit profile ===== -->
                <div class="tab-pane fade profile-edit pt-3" id="tab-edit">
                <form action="{{ route('profile.update') }}" method="POST">
                    @csrf @method('PATCH')

                    <div class="row mb-3">
                    <label class="col-md-4 col-lg-3 col-form-label">Name</label>
                    <div class="col-md-8 col-lg-9">
                        <input name="name" type="text" class="form-control"
                            value="{{ old('name', $user->name) }}" required>
                    </div>
                    </div>

                    <div class="row mb-3">
                    <label class="col-md-4 col-lg-3 col-form-label">Email</label>
                    <div class="col-md-8 col-lg-9">
                        <input name="email" type="email" class="form-control"
                            value="{{ old('email', $user->email) }}" required>
                    </div>
                    </div>

                    <div class="row mb-3">
                    <label class="col-md-4 col-lg-3 col-form-label">Phone</label>
                    <div class="col-md-8 col-lg-9">
                        <input name="no_telp" type="phone" class="form-control"
                            value="{{ old('no_telp', $user->no_telp) }}" required>
                    </div>
                    </div>

                    <div class="row mb-3">
                        <label class="col-md-4 col-lg-3 col-form-label">Role</label>
                        <div class="col-md-8 col-lg-9">
                            <select name="role_id" class="form-control" required>
                                @foreach (\App\Models\Role::all() as $role)
                                <option value="{{ $role->id }}" {{ $user->role_id == $role->id ? 'selected' : '' }}>
                                    {{ $role->name }}
                                </option>
                                @endforeach
                            </select>
                        </div>
                    </div>


                    <div class="text-center">
                    <button type="submit" class="btn btn-primary">Save Changes</button>
                    </div>
                </form>
                </div>

            <!-- ======== Change password ==== -->
            <div class="tab-pane fade pt-3" id="tab-password">
              <form action="{{ route('profile.password') }}" method="POST">
                @csrf @method('PUT')

                <div class="row mb-3">
                  <label class="col-md-4 col-lg-3 col-form-label">Current Password</label>
                  <div class="col-md-8 col-lg-9">
                    <input name="current_password" type="password" class="form-control" required>
                  </div>
                </div>

                <div class="row mb-3">
                  <label class="col-md-4 col-lg-3 col-form-label">New Password</label>
                  <div class="col-md-8 col-lg-9">
                    <input name="password" type="password" class="form-control" required>
                  </div>
                </div>

                <div class="row mb-3">
                  <label class="col-md-4 col-lg-3 col-form-label">Confirm Password</label>
                  <div class="col-md-8 col-lg-9">
                    <input name="password_confirmation" type="password" class="form-control" required>
                  </div>
                </div>

                <div class="text-center">
                  <button type="submit" class="btn btn-primary">Change Password</button>
                </div>
              </form>
            </div>

          </div><!-- tab-content -->
        </div>
      </div>
    </div>
  </div>
</section>
@endsection
