@extends('frontend.layout.dash')

@section('content')
    @include('frontend.components.accordion')

    <div class="card mp-20 social-logs-page">
        <div class="social-logs-header">
            <h2 class="title">{{ $title }}</h2>
            <p class="social-logs-desc">Browse and buy account credentials. Balance will be deducted on purchase.</p>
        </div>

        <div class="social-logs-search">
            <form method="GET" action="{{ route('user.accounts.products') }}" class="table-search-form social-logs-search-form">
                <div class="table-search">
                    <input type="text" name="search" class="search-input" placeholder="Search by product name or category..." value="{{ $search ?? '' }}">
                    <i class="ti ti-search"></i>
                </div>
                <button type="submit" class="search-btn"><i class="ti ti-search"></i> Search</button>
            </form>
        </div>

        <div class="social-logs-grid">
            @forelse($products as $p)
                <a href="{{ route('user.accounts.product', $p->id) }}" class="social-logs-card">
                    @if($p->image)
                        <div class="social-logs-card-image">
                            <img src="{{ asset($p->image) }}" alt="">
                        </div>
                    @else
                        <div class="social-logs-card-placeholder">
                            <i class="ti ti-shopping-bag"></i>
                        </div>
                    @endif
                    <div class="social-logs-card-body">
                        <h3 class="social-logs-card-title">{{ $p->name }}</h3>
                        <p class="social-logs-card-category">{{ $p->productCategory->name ?? '-' }}</p>
                        <div class="social-logs-card-meta">
                            <span class="social-logs-card-price">{{ $currency }}{{ number_format($p->price, 2) }}</span>
                            <span class="social-logs-card-stock">In stock: {{ $p->in_stock }}</span>
                        </div>
                        <span class="social-logs-card-cta">View & buy</span>
                    </div>
                </a>
            @empty
                <div class="social-logs-empty">
                    <i class="ti ti-package-off"></i>
                    <p>No products available.</p>
                </div>
            @endforelse
        </div>

        @if($products->hasPages())
            <div class="social-logs-pagination">{{ $products->links('vendor.pagination.default') }}</div>
        @endif
    </div>
@endsection
