<?php

use App\Models\Address;
use Livewire\Component;
use Illuminate\Support\Collection;
use Livewire\Attributes\Title;
use Illuminate\Support\Facades\Auth;

return new #[Title('Mes adresses')]
class extends Component {

    public function deleteAddress(Address $address): void
    {
        // Sécurité : Vérifier que l'adresse appartient bien à l'utilisateur connecté
        if ($address->user_id !== Auth::id()) {
            abort(403);
        }

        $address->delete();

        $this->success(__('Adresse supprimée avec succès.'));
    }

    public function with(): array
    {
        return [
            'addresses' => Auth::user()->addresses()->with('country')->get(),
        ];
    }


    protected function view($data = [])
    {
        return app('view')->file('E:\laragon\www\shop2\storage\framework\views/livewire/views/1d8b348b.blade.php', $data);
    }
}; 