@extends('admin.layouts.app')

@section('title', __('admin/baskets.title'))

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/baskets.title')"
        :subtitle="__('admin/baskets.subtitle')"
        icon="fas fa-shopping-cart"
    >
        <button type="button" class="btn btn-outline-secondary btn-sm" id="refreshBtn">
            <i class="fas fa-sync-alt me-1"></i>{{ __('admin/baskets.buttons_refresh') }}
        </button>
    </x-admin.page-header>

    <!-- Statistics Cards -->
    <div class="row mb-3" id="statisticsRow">
        <div class="col-md-2 col-sm-4 col-6 mb-2">
            <x-admin.stat-card :title="__('admin/baskets.stats_total')" value="-" id="totalBaskets" icon="fas fa-shopping-cart" color="primary" />
        </div>
        <div class="col-md-2 col-sm-4 col-6 mb-2">
            <x-admin.stat-card :title="__('admin/baskets.stats_with_items')" value="-" id="activeBaskets" icon="fas fa-box" color="success" />
        </div>
        <div class="col-md-2 col-sm-4 col-6 mb-2">
            <x-admin.stat-card :title="__('admin/baskets.stats_redis')" value="-" id="redisBaskets" icon="fas fa-database" color="info" />
        </div>
        <div class="col-md-2 col-sm-4 col-6 mb-2">
            <x-admin.stat-card :title="__('admin/baskets.stats_anonymous')" value="-" id="anonymousBaskets" icon="fas fa-user-secret" color="warning" />
        </div>
        <div class="col-md-2 col-sm-4 col-6 mb-2">
            <x-admin.stat-card :title="__('admin/baskets.stats_with_client')" value="-" id="clientBaskets" icon="fas fa-user" color="secondary" />
        </div>
        <div class="col-md-2 col-sm-4 col-6 mb-2">
            <x-admin.stat-card :title="__('admin/baskets.stats_mysql')" value="-" id="mysqlBaskets" icon="fas fa-server" color="danger" />
        </div>
    </div>

    <!-- Main Card -->
    <x-admin.card>
        <x-admin.data-table id="basketsTable" :records-url="route('api.admin.baskets.records')">
            <th>{{ __('admin/baskets.column_visitor') }}</th>
            <th>{{ __('admin/baskets.column_ip') }}</th>
            <th>{{ __('admin/baskets.column_location') }}</th>
            <th>{{ __('admin/baskets.column_client') }}</th>
            <th>{{ __('admin/baskets.column_items') }}</th>
            <th>{{ __('admin/baskets.column_total') }}</th>
            <th>{{ __('admin/baskets.column_status') }}</th>
            <th>{{ __('admin/baskets.column_last_seen') }}</th>
            <th class="text-end">{{ __('admin/common.actions') }}</th>
        </x-admin.data-table>
    </x-admin.card>
</div>

<!-- Basket Detail Modal -->
<x-admin.modal id="basketDetailModal" :title="__('admin/baskets.modal_title')" size="lg">
    <div id="basketDetailContent">
        <div class="text-center py-4">
            <div class="spinner-border text-primary" role="status">
                <span class="visually-hidden">{{ __('admin/common.loading') }}</span>
            </div>
        </div>
    </div>
</x-admin.modal>
@endsection

@push('scripts')
<script>
    window.pageConfig = window.pageConfig || {};
    window.pageConfig.permissions = {
        canDelete: {{ auth()->user()->can('delete baskets') ? 'true' : 'false' }},
    };

    // PRC-1070: satır-içi aksiyon butonu izin-gating (kanonik route izinleri)
    window.permissions = window.permissions || {};
    window.permissions.baskets = {
        view: {{ auth()->user()->can('view baskets') ? 'true' : 'false' }},
        delete: {{ auth()->user()->can('delete baskets') ? 'true' : 'false' }},
    };

    window.routes = window.routes || {};
    window.routes.baskets_records = '{{ route("api.admin.baskets.records") }}';
    window.routes.baskets_statistics = '{{ route("api.admin.baskets.statistics") }}';
    window.routes.baskets_details = '{{ route("api.admin.baskets.details", ":visitorId") }}';
    window.routes.baskets_delete = '{{ route("api.admin.baskets.destroy", ":id") }}';
    window.routes.clients_overview = '{{ route("admin.clients.overview", ":id") }}';

    window.translations = window.translations || {};
    window.translations.baskets_anonymous = '{{ __("admin/baskets.anonymous") }}';
    window.translations.baskets_status_active = '{{ __("admin/baskets.status_active") }}';
    window.translations.baskets_status_empty = '{{ __("admin/baskets.status_empty") }}';
    window.translations.baskets_source_redis = '{{ __("admin/baskets.source_redis") }}';
    window.translations.baskets_source_mysql = '{{ __("admin/baskets.source_mysql") }}';
    window.translations.baskets_confirm_delete = '{{ __("admin/baskets.confirm_delete") }}';
    window.translations.baskets_view = '{{ __("admin/baskets.button_view") }}';
    window.translations.baskets_delete = '{{ __("admin/baskets.button_delete") }}';
    window.translations.common_no_data = '{{ __("admin/common.no_data") }}';
    window.translations.baskets_detail_visitor_info = '{{ __("admin/baskets.detail_visitor_info") }}';
    window.translations.baskets_detail_client_info = '{{ __("admin/baskets.detail_client_info") }}';
    window.translations.baskets_detail_basket_items = '{{ __("admin/baskets.detail_basket_items") }}';
    window.translations.baskets_detail_ip_address = '{{ __("admin/baskets.detail_ip_address") }}';
    window.translations.baskets_detail_country = '{{ __("admin/baskets.detail_country") }}';
    window.translations.baskets_detail_city = '{{ __("admin/baskets.detail_city") }}';
    window.translations.baskets_detail_timezone = '{{ __("admin/baskets.detail_timezone") }}';
    window.translations.baskets_detail_browser_language = '{{ __("admin/baskets.detail_browser_language") }}';
    window.translations.baskets_detail_preferred_language = '{{ __("admin/baskets.detail_preferred_language") }}';
    window.translations.baskets_detail_preferred_currency = '{{ __("admin/baskets.detail_preferred_currency") }}';
    window.translations.baskets_detail_created_at = '{{ __("admin/baskets.detail_created_at") }}';
    window.translations.baskets_detail_last_seen = '{{ __("admin/baskets.detail_last_seen") }}';
    window.translations.baskets_detail_name = '{{ __("admin/baskets.detail_name") }}';
    window.translations.baskets_detail_email = '{{ __("admin/baskets.detail_email") }}';
    window.translations.baskets_detail_company = '{{ __("admin/baskets.detail_company") }}';
    window.translations.baskets_detail_no_client = '{{ __("admin/baskets.detail_no_client") }}';
    window.translations.baskets_detail_product = '{{ __("admin/baskets.detail_product") }}';
    window.translations.baskets_detail_price = '{{ __("admin/baskets.detail_price") }}';
    window.translations.baskets_detail_quantity = '{{ __("admin/baskets.detail_quantity") }}';
    window.translations.baskets_detail_period = '{{ __("admin/baskets.detail_period") }}';
    window.translations.baskets_detail_subtotal = '{{ __("admin/baskets.detail_subtotal") }}';
    window.translations.baskets_detail_total = '{{ __("admin/baskets.detail_total") }}';
    window.translations.baskets_detail_coupon = '{{ __("admin/baskets.detail_coupon") }}';
    window.translations.baskets_detail_no_items = '{{ __("admin/baskets.detail_no_items") }}';
    window.translations.baskets_detail_source = '{{ __("admin/baskets.detail_source") }}';
    window.translations.baskets_detail_domain = '{{ __("admin/baskets.detail_domain") }}';
    window.translations.baskets_detail_type_domain = '{{ __("admin/baskets.detail_type_domain") }}';
    window.translations.baskets_detail_type_product = '{{ __("admin/baskets.detail_type_product") }}';
    window.translations.baskets_detail_domain_action = '{{ __("admin/baskets.detail_domain_action") }}';
    window.translations.common_not_available = '{{ __("admin/common.not_available") }}';
</script>
@vite('resources/js/admin/baskets/index.js')
@endpush
