@extends('layout')

@section('title', __('store.products_title'))

@section('content')
<div class="container py-4">
    <h1 class="h3 mb-4">{{ __('store.products_title') }}</h1>

    <div class="row">
        <aside class="col-md-3 mb-3 mb-md-0">
            <div class="list-group">
                @foreach(($groups ?? []) as $group)
                    <a href="{{ lroute('store.products.group', $group->slug) }}"
                       class="list-group-item list-group-item-action @if(isset($selectedGroup) && $selectedGroup->id === $group->id) active @endif">
                        {{ $group->translated_name ?? $group->name }}
                    </a>
                @endforeach
            </div>
        </aside>
        <section class="col-md-9">
            <div class="row g-3">
                @forelse($products as $product)
                    <div class="col-md-6 col-lg-4">
                        <div class="card h-100">
                            <div class="card-body d-flex flex-column">
                                <div class="d-flex align-items-start justify-content-between mb-1">
                                    <h5 class="card-title mb-0">{{ $product->translated_name ?? $product->name }}</h5>
                                    @if(($product->trial_mode ?? 'none') === 'free')
                                        <span class="badge bg-success ms-2 text-nowrap">{{ __('store.trial_free_badge', ['days' => $product->trial_period_days]) }}</span>
                                    @elseif(($product->trial_mode ?? 'none') === 'paid')
                                        <span class="badge bg-warning text-dark ms-2 text-nowrap">{{ __('store.trial_paid_badge', ['pct' => (int)$product->trial_paid_discount_percent]) }}</span>
                                    @endif
                                </div>
                                @if(! $product->isInStock())
                                    <span class="badge bg-secondary align-self-start mb-2">{{ __('store.product_out_of_stock') }}</span>
                                @endif
                                <p class="card-text text-muted flex-grow-1">{{ Str::limit(strip_tags($product->translated_description ?? $product->description), 130) }}</p>
                                <a href="{{ lroute('store.products.show', $product->slug) }}" class="btn btn-outline-primary mt-2">{{ __('store.products_view') }}</a>
                            </div>
                        </div>
                    </div>
                @empty
                    <div class="col-12">
                        <div class="alert alert-info mb-0">{{ __('store.products_empty') }}</div>
                    </div>
                @endforelse
            </div>
        </section>
    </div>
</div>
@endsection


