@extends('admin.layouts.app')

@section('title', __('admin/baskets.singular') . ' #' . $basket->id)

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/baskets.singular') . ' #' . $basket->id"
        icon="fas fa-shopping-cart"
        :buttons="[
            ['label' => __('admin/baskets.buttons_edit'), 'route' => route('admin.baskets.edit', $basket), 'icon' => 'fas fa-edit', 'color' => 'outline-primary'],
            ['label' => __('admin/common.back'), 'route' => route('admin.baskets.index'), 'icon' => 'fas fa-arrow-left', 'color' => 'outline-secondary'],
        ]"
    />

    <!-- Basket Details -->
    <div class="row mb-4">
        <div class="col-md-6">
            <x-admin.card :title="__('admin/baskets.tabs_details')" icon="fas fa-info-circle">
                <table class="table table-borderless">
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_id') }}:</strong></td>
                        <td>{{ $basket->id }}</td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_session_id') }}:</strong></td>
                        <td><code>{{ $basket->session_id }}</code></td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_ip_address') }}:</strong></td>
                        <td>{{ $basket->ip_address }}</td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_client') }}:</strong></td>
                        <td>
                            @if($basket->client)
                                <a href="{{ route('admin.clients.edit', $basket->client) }}">
                                    {{ $basket->client->name }} ({{ $basket->client->email }})
                                </a>
                            @else
                                <span class="text-muted">{{ __('admin/baskets.fields_anonymous') }}</span>
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_status') }}:</strong></td>
                        <td>
                            @if($basket->isExpired)
                                <span class="badge bg-danger">{{ __('admin/baskets.statuses_expired') }}</span>
                            @else
                                <span class="badge bg-success">{{ __('admin/baskets.statuses_active') }}</span>
                            @endif
                        </td>
                    </tr>
                </table>
            </x-admin.card>
        </div>
        <div class="col-md-6">
            <x-admin.card :title="__('admin/baskets.tabs_activity')" icon="fas fa-clock">
                <table class="table table-borderless">
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_last_activity') }}:</strong></td>
                        <td>{{ $basket->last_activity_at ? $basket->last_activity_at->format($dateTimeSecFormat) : '-' }}</td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_expires_at') }}:</strong></td>
                        <td>{{ $basket->expires_at ? $basket->expires_at->format($dateTimeSecFormat) : '-' }}</td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_created_at') }}:</strong></td>
                        <td>{{ $basket->created_at->format($dateTimeSecFormat) }}</td>
                    </tr>
                    <tr>
                        <td><strong>{{ __('admin/baskets.fields_updated_at') }}:</strong></td>
                        <td>{{ $basket->updated_at->format($dateTimeSecFormat) }}</td>
                    </tr>
                </table>
            </x-admin.card>
        </div>
    </div>

    <!-- Basket Summary -->
    <div class="row g-3 mb-4">
        <div class="col-md-3">
            <x-admin.stat-card :title="__('admin/baskets.fields_item_count')" :value="(string)$basket->itemCount" icon="fas fa-hashtag" color="primary" />
        </div>
        <div class="col-md-3">
            <x-admin.stat-card :title="__('admin/baskets.fields_total')" :value="number_format($basket->total, 2)" icon="fas fa-money-bill" color="success" />
        </div>
        <div class="col-md-3">
            <x-admin.stat-card :title="__('admin/baskets.item_types_product')" :value="(string)count(array_filter($basket->items, fn($item) => $item['type'] === 'product'))" icon="fas fa-box" color="info" />
        </div>
        <div class="col-md-3">
            <x-admin.stat-card :title="__('admin/baskets.item_types_domain')" :value="(string)count(array_filter($basket->items, fn($item) => $item['type'] === 'domain'))" icon="fas fa-globe" color="warning" />
        </div>
    </div>

    <!-- Basket Items -->
    <x-admin.card :title="__('admin/baskets.tabs_items')" icon="fas fa-box">
        @if($basket->isEmpty)
            <div class="alert alert-info">
                {{ __('admin/baskets.messages_basket_empty') }}
            </div>
        @else
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>{{ __('admin/baskets.fields_id') }}</th>
                            <th>{{ __('admin/baskets.fields_items') }}</th>
                            <th>{{ __('admin/baskets.fields_description') }}</th>
                            <th>{{ __('admin/baskets.fields_quantity') }}</th>
                            <th>{{ __('admin/baskets.fields_amount') }}</th>
                            <th>{{ __('admin/baskets.fields_setup_amount') }}</th>
                            <th>{{ __('admin/baskets.fields_period') }}</th>
                            <th>{{ __('admin/baskets.fields_period_type') }}</th>
                            <th>{{ __('admin/baskets.fields_added_at') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($basket->items as $index => $item)
                            <tr>
                                <td>{{ $index + 1 }}</td>
                                <td>
                                    <strong>{{ $item['name'] ?? '-' }}</strong>
                                    <br>
                                    <small class="text-muted">
                                        {{ __('admin/baskets.item_types.' . ($item['type'] ?? 'unknown')) }}
                                    </small>
                                </td>
                                <td>{{ $item['description'] ?? '-' }}</td>
                                <td>{{ $item['quantity'] ?? 1 }}</td>
                                <td>{{ number_format($item['price'] ?? 0, 2) }}</td>
                                <td>{{ number_format($item['setup_amount'] ?? 0, 2) }}</td>
                                <td>{{ $item['period'] ?? '-' }}</td>
                                <td>
                                    @if(isset($item['period_type']))
                                        {{ __('admin/baskets.period_types_' . $item['period_type']) }}
                                    @else
                                        -
                                    @endif
                                </td>
                                <td>
                                    @if(isset($item['added_at']))
                                        {{ \Carbon\Carbon::parse($item['added_at'])->format($dateTimeFormat) }}
                                    @else
                                        -
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="4" class="text-end"><strong>{{ __('admin/baskets.fields_subtotal') }}:</strong></td>
                            <td><strong>{{ number_format($basket->total, 2) }}</strong></td>
                            <td colspan="4"></td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        @endif
    </x-admin.card>

    <!-- Basket Data (JSON) -->
    <x-admin.card :title="__('admin/baskets.fields_basket_data')" icon="fas fa-code" class="mt-3">
        <pre class="mb-0"><code>{{ json_encode($basket->basket_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}</code></pre>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    // Sepet detay sayfası için gerekli JavaScript kodları buraya eklenebilir
</script>
@endpush
