@extends('layouts.app')

@section('title', 'Edit User')
@section('page_title', 'Edit User')
@section('page_pretitle', 'Akses Sistem')

@section('page_actions')
  <a class="btn" href="{{ route('users.index') }}">
    <i class="ti ti-arrow-left me-1"></i>
    Kembali
  </a>
@endsection

@section('content')
  <div class="card">
    <div class="card-header">
      <div>
        <h3 class="card-title">{{ $user->nama }}</h3>
        <p class="card-subtitle">{{ $user->email }}</p>
      </div>
      <span class="user-status-badge {{ $user->aktif ? 'active' : 'inactive' }}">
        {{ $user->aktif ? 'Aktif' : 'Nonaktif' }}
      </span>
    </div>
    <form action="{{ route('users.update', $user) }}" method="POST">
      @csrf
      @method('PUT')
      <div class="card-body">
        <div class="row g-3">
          <div class="col-md-6">
            <label class="form-label">Nama User</label>
            <input class="form-control" name="name" value="{{ old('name', $user->nama) }}" required>
          </div>
          <div class="col-md-6">
            <label class="form-label">Email Login</label>
            <input class="form-control" type="email" name="email" value="{{ old('email', $user->email) }}" required>
          </div>
          <div class="col-md-6">
            <label class="form-label">Tipe Akses</label>
            <select class="form-select" name="role" required>
              @foreach ($roles as $value => $label)
                <option value="{{ $value }}" @selected(old('role', $user->peran) === $value)>{{ $label }}</option>
              @endforeach
            </select>
          </div>
          <div class="col-md-6">
            <label class="form-label">Status Akun</label>
            <input type="hidden" name="is_active" value="0">
            <label class="form-check user-active-check">
              <input class="form-check-input" type="checkbox" name="is_active" value="1" @checked((string) old('is_active', $user->aktif ? '1' : '0') === '1')>
              <span>Aktifkan akses login user ini</span>
            </label>
          </div>
          <div class="col-md-6">
            <label class="form-label">Password Baru</label>
            <input class="form-control" type="password" name="password" placeholder="Kosongkan jika tidak diganti">
          </div>
          <div class="col-md-6">
            <label class="form-label">Konfirmasi Password Baru</label>
            <input class="form-control" type="password" name="password_confirmation" placeholder="Ulangi password baru">
          </div>
        </div>
      </div>
      <div class="card-footer text-end">
        <button class="btn btn-primary" type="submit">
          <i class="ti ti-device-floppy me-1"></i>
          Update User
        </button>
      </div>
    </form>
  </div>
@endsection
