@extends('admin.layouts.app')

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

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

    <x-admin.card>
        <x-admin.data-table id="racksTable" :records-url="route('api.admin.racks.records')">
            <th>{{ __('admin/racks.fields_name') }}</th>
            <th>{{ __('admin/racks.fields_datacenter') }}</th>
            <th>{{ __('admin/racks.fields_row') }}</th>
            <th>{{ __('admin/racks.fields_total_u') }}</th>
            <th>{{ __('admin/racks.fields_used_u') }}</th>
            <th>{{ __('admin/racks.fields_free_u') }}</th>
            <th>{{ __('admin/racks.fields_actions') }}</th>
        </x-admin.data-table>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    // Yetki kontrolü için permissions nesnesi
    window.permissions = {
        racks: {
            update: {{ json_encode(Auth::user()->can('updateAny', App\Models\Rack::class)) }},
            delete: {{ json_encode(Auth::user()->can('deleteAny', App\Models\Rack::class)) }}
        }
    };

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

    // Çeviriler
    window.translations = {
        buttons: {
            edit: '{{ __("common.buttons_edit") }}',
            delete: '{{ __("common.buttons_delete") }}'
        },
        racks: {
            delete_confirm: '{{ __("admin/racks.messages_delete_confirm") }}'
        }
    };
</script>
@vite('resources/js/admin/racks/index.js')
@endpush
