@extends('layouts.frontend')

@section('title', 'Profil Saya')

@section('content')
    <div class="container py-5 mt-5">
        <div class="row justify-content-center">
            <div class="col-lg-8">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-white py-3">
                        <h4 class="mb-0 fw-bold">Edit Profil</h4>
                    </div>
                    <div class="card-body p-4">
                        @if (session('success'))
                            <div class="alert alert-success">{{ session('success') }}</div>
                        @endif

                        <form action="{{ route('pembeli.profile.update') }}" method="POST" enctype="multipart/form-data">
                            @csrf
                            @method('PUT')

                            <div class="row">
                                <div class="col-md-4 text-center mb-4">
                                    <img src="{{ $user->foto ? asset('storage/' . $user->foto) : asset('template/frontend/img/avatar.jpg') }}"
                                        class="rounded-circle img-thumbnail mb-3"
                                        style="width: 150px; height: 150px; object-fit: cover;">
                                    <div>
                                        <label class="btn btn-sm btn-outline-secondary">
                                            <i class="fas fa-camera me-1"></i> Ubah Foto
                                            <input type="file" name="foto" hidden accept="image/*">
                                        </label>
                                    </div>
                                </div>

                                <div class="col-md-8">
                                    <div class="mb-3">
                                        <label class="form-label fw-bold">Nama Lengkap</label>
                                        <input type="text" name="nama_lengkap" class="form-control"
                                            value="{{ $user->nama_lengkap }}" required>
                                    </div>
                                    <div class="mb-3">
                                        <label class="form-label fw-bold">Email</label>
                                        <input type="email" name="email" class="form-control"
                                            value="{{ $user->email }}" required>
                                    </div>
                                    <div class="mb-3">
                                        <label class="form-label fw-bold">Nomor HP</label>
                                        <input type="text" name="no_hp" class="form-control"
                                            value="{{ $user->no_hp }}" required>
                                    </div>
                                    <div class="mb-3">
                                        <label class="form-label fw-bold">Alamat Pengiriman Default</label>
                                        <textarea name="alamat" class="form-control" rows="3" required>{{ $user->alamat }}</textarea>
                                    </div>

                                    <hr>
                                    <p class="text-muted small">Isi kolom di bawah HANYA jika ingin mengganti password.</p>

                                    <div class="row">
                                        <div class="col-md-6 mb-3">
                                            <label class="form-label">Password Baru</label>
                                            <input type="password" name="password" class="form-control">
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <label class="form-label">Ulangi Password</label>
                                            <input type="password" name="password_confirmation" class="form-control">
                                        </div>
                                    </div>

                                    <div class="d-grid mt-3">
                                        <button type="submit" class="btn btn-primary rounded-pill py-2">Simpan
                                            Perubahan</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
