@extends('admin.layouts.app')

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

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/orders.title')"
        icon="fas fa-shopping-cart"
        :buttons="[
            ['label' => __('admin/orders.buttons_create'), 'route' => route('admin.orders.create'), 'icon' => 'fas fa-plus', 'color' => 'primary', 'permission' => 'create orders'],
        ]"
    />

    <x-admin.card>
        <x-admin.data-table
            id="orders"
            :records-url="route('api.admin.orders.records')"
        >
            <th>{{ __('admin/orders.fields_order_number') }}</th>
            <th>{{ __('admin/orders.fields_client_name') }}</th>
            <th>{{ __('admin/orders.fields_client_email') }}</th>
            <th>{{ __('admin/orders.fields_brand') }}</th>
            <th>{{ __('admin/orders.fields_amount') }}</th>
            <th>{{ __('admin/orders.fields_currency_code') }}</th>
            <th>{{ __('admin/orders.fields_status') }}</th>
            <th>{{ __('admin/orders.fields_fraud_status') }}</th>
            <th>{{ __('admin/orders.fields_created_at') }}</th>
            <th>{{ __('admin/orders.fields_actions') }}</th>
        </x-admin.data-table>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    // PRC-1070 — satır-içi aksiyon butonu izin-gating (kanonik izin adları: route can: gate'leriyle birebir)
    window.permissions = {
        orders: {
            view: {{ auth()->user()->can('view orders') ? 'true' : 'false' }},
            update: {{ auth()->user()->can('update orders') ? 'true' : 'false' }},
            delete: {{ auth()->user()->can('delete orders') ? 'true' : 'false' }},
        }
    };

    // Route bilgilerini JavaScript'e aktar
    window.routes = {
        orders: {
            edit: '{{ route("admin.orders.edit", ":id") }}',
            delete: '{{ route("api.admin.orders.destroy", ":id") }}'
        }
    };

    // Çevirileri JavaScript'e aktar
    window.translations = {
        orders: {
            statuses_pending: '{{ __("admin/orders.statuses_pending") }}',
            statuses_paid: '{{ __("admin/orders.statuses_paid") }}',
            statuses_cancelled: '{{ __("admin/orders.statuses_cancelled") }}',
            fraud_approved: '{{ __("admin/orders.fraud_approved") }}',
            fraud_review: '{{ __("admin/orders.fraud_review") }}',
            fraud_rejected: '{{ __("admin/orders.fraud_rejected") }}',
            fraud_checking: '{{ __("admin/orders.fraud_checking") }}',
            fraud_unchecked: '{{ __("admin/orders.fraud_unchecked") }}'
        },
        common: {
            buttons_edit: '{{ __("admin/common.buttons_edit") }}',
            buttons_delete: '{{ __("admin/common.buttons_delete") }}',
            messages_confirm_delete: '{{ __("admin/common.messages_confirm_delete") }}'
        }
    };
</script>
@vite('resources/js/admin/orders/index.js')
@endpush
