@extends('layouts.app')

@section('title', "My Wishlist - MJ's Bikes")

@section('content')

<!-- BREADCRUMBS -->
<div class="bg-light py-3 border-bottom mb-4">
    <div class="container">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item"><a href="{{ route('home') }}" class="text-danger text-decoration-none">Home</a></li>
                <li class="breadcrumb-item"><a href="{{ route('marketplace.index') }}" class="text-danger text-decoration-none">Showroom</a></li>
                <li class="breadcrumb-item active" aria-current="page">Wishlist</li>
            </ol>
        </nav>
    </div>
</div>

<div class="container mb-5">
    <h2 class="brand-font text-uppercase text-secondary mb-4"><i class="bi bi-heart-fill text-danger me-2"></i>My <span class="text-danger">Wishlist</span></h2>

    @if(count($wishlist) > 0)
        <!-- Desktop Grid -->
        <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4 d-none d-sm-flex mb-4">
            @foreach($wishlist as $id => $item)
                @php
                    $itemImg = mjs_image($item['image'] ?? null, $id);
                @endphp
                <div class="col">
                    <div class="card product-card h-100">
                        <div class="card-img-wrap">
                            <form action="{{ route('wishlist.toggle', $id) }}" method="POST" class="position-absolute" style="top: 12px; right: 12px; z-index: 10;">
                                @csrf
                                <button type="submit" class="btn btn-white rounded-circle shadow-sm p-2 d-flex align-items-center justify-content-center" style="width: 35px; height: 35px; background: white; border: none;">
                                    <i class="bi bi-heart-fill text-danger fs-5"></i>
                                </button>
                            </form>
                            <a href="{{ route('marketplace.show', $item['slug']) }}">
                                <img src="{{ $itemImg }}" alt="{{ $item['name'] }}">
                            </a>
                        </div>
                        <div class="card-body d-flex flex-column p-3">
                            <h6 class="card-title fw-bold mb-2 flex-grow-1">
                                <a href="{{ route('marketplace.show', $item['slug']) }}" class="text-decoration-none text-dark hover-text-danger">
                                    {{ $item['name'] }}
                                </a>
                            </h6>
                            <div class="fw-bold text-danger mb-3">KSh {{ number_format($item['price']) }}</div>
                            
                            <form action="{{ route('cart.add', $id) }}" method="POST">
                                @csrf
                                <button type="submit" class="btn btn-primary-mj w-100 rounded-pill py-2 text-center d-flex align-items-center justify-content-center gap-1" style="font-size: 13px;">
                                    <i class="bi bi-cart-plus"></i> Buy Now
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            @endforeach
        </div>

        <!-- Mobile Grid -->
        <div class="mobile-grid-2 d-sm-none mb-4" style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: 100%;">
            @foreach($wishlist as $id => $item)
                @php
                    $itemImg = mjs_image($item['image'] ?? null, $id);
                @endphp
                <div style="width: 100%;">
                    <div class="card product-card h-100">
                        <div class="card-img-wrap">
                            <form action="{{ route('wishlist.toggle', $id) }}" method="POST" class="position-absolute" style="top: 12px; right: 12px; z-index: 10;">
                                @csrf
                                <button type="submit" class="btn btn-white rounded-circle shadow-sm p-2 d-flex align-items-center justify-content-center" style="width: 35px; height: 35px; background: white; border: none;">
                                    <i class="bi bi-heart-fill text-danger fs-5"></i>
                                </button>
                            </form>
                            <a href="{{ route('marketplace.show', $item['slug']) }}">
                                <img src="{{ $itemImg }}" alt="{{ $item['name'] }}">
                            </a>
                        </div>
                        <div class="card-body d-flex flex-column p-3">
                            <h6 class="card-title fw-bold mb-2 flex-grow-1" style="font-size: 0.875rem;">
                                <a href="{{ route('marketplace.show', $item['slug']) }}" class="text-decoration-none text-dark hover-text-danger">
                                    {{ $item['name'] }}
                                </a>
                            </h6>
                            <div class="fw-bold text-danger mb-3" style="font-size: 0.95rem;">KSh {{ number_format($item['price']) }}</div>
                            
                            <form action="{{ route('cart.add', $id) }}" method="POST">
                                @csrf
                                <button type="submit" class="btn btn-primary-mj w-100 rounded-pill py-2 text-center d-flex align-items-center justify-content-center gap-1" style="font-size: 0.75rem;">
                                    <i class="bi bi-cart-plus"></i> Buy Now
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            @endforeach
        </div>
    @else
        <!-- EMPTY STATE -->
        <div class="card border-0 shadow-sm rounded-4 p-5 text-center my-5 bg-white">
            <div class="text-danger fs-1 mb-3"><i class="bi bi-heart"></i></div>
            <h3 class="fw-bold text-secondary mb-2">Your Wishlist is Empty</h3>
            <p class="text-muted mb-4">Save your favorite bikes and accessories here to view them later.</p>
            <div class="d-flex justify-content-center">
                <a href="{{ route('marketplace.index') }}" class="btn btn-primary-mj rounded-pill px-5">Browse Showroom Catalog</a>
            </div>
        </div>
    @endif
</div>

@endsection
