@extends('layouts.app')

@section('title', 'My Addresses')

@section('content')
<div class="container py-5">
    <div class="row g-4">
        <div class="col-lg-3">
            @include('partials.account-sidebar')
        </div>
        <div class="col-lg-9">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h5 class="font-serif mb-0">My Addresses</h5>
                <a href="{{ route('account.addresses.create') }}" class="btn btn-terracotta btn-sm"><i class="bi bi-plus-lg me-1"></i>Add Address</a>
            </div>

            @if($addresses->isEmpty())
                <div class="border rounded p-4 bg-white text-center text-muted-soft">
                    No saved addresses yet.
                </div>
            @else
                <div class="row g-3">
                    @foreach($addresses as $address)
                        <div class="col-md-6">
                            <div class="border rounded p-3 bg-white h-100">
                                <div class="d-flex justify-content-between">
                                    <span class="fw-semibold">{{ $address->label }}</span>
                                    @if($address->is_default)
                                        <span class="badge bg-sage-subtle text-sage border">Default</span>
                                    @endif
                                </div>
                                <p class="mb-1 mt-2">{{ $address->full_name }} &middot; {{ $address->phone }}</p>
                                <p class="mb-1 small text-muted-soft">{{ $address->address_line1 }}{{ $address->address_line2 ? ', '.$address->address_line2 : '' }}</p>
                                <p class="mb-3 small text-muted-soft">{{ $address->city }}{{ $address->state ? ', '.$address->state : '' }} {{ $address->postal_code }}</p>
                                <div class="d-flex gap-2">
                                    <a href="{{ route('account.addresses.edit', $address) }}" class="btn btn-sm btn-outline-terracotta">Edit</a>
                                    <form action="{{ route('account.addresses.destroy', $address) }}" method="POST" onsubmit="return confirm('Delete this address?')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
