@extends('admin.layouts.app')

@section('title', __('admin/datacenters.edit'))

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/datacenters.edit')"
        icon="fas fa-warehouse"
        :buttons="[
            ['label' => __('common.buttons_back'), 'route' => route('admin.datacenters.index'), 'icon' => 'fas fa-arrow-left', 'color' => 'secondary'],
        ]"
    />

    <x-admin.alert />

    <x-admin.card>
        <form id="datacenterForm" method="POST" action="{{ route('admin.datacenters.update', $datacenter) }}">
            @csrf
            @method('PUT')

            <div class="row">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="edit_name" class="form-label">{{ __('admin/datacenters.fields_name') }} <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="edit_name" name="name" required
                               value="{{ old('name', $datacenter->name) }}"
                               placeholder="{{ __('admin/datacenters.form_name_placeholder') }}">
                        <div class="invalid-feedback"></div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="edit_code" class="form-label">{{ __('admin/datacenters.fields_code') }} <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="edit_code" name="code" required
                               value="{{ old('code', $datacenter->code) }}"
                               placeholder="{{ __('admin/datacenters.form_code_placeholder') }}">
                        <div class="form-text small">{{ __('admin/datacenters.fields_code_help') }}</div>
                        <div class="invalid-feedback"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="edit_city" class="form-label">{{ __('admin/datacenters.fields_city') }}</label>
                        <input type="text" class="form-control" id="edit_city" name="city"
                               value="{{ old('city', $datacenter->city) }}"
                               placeholder="{{ __('admin/datacenters.form_city_placeholder') }}">
                        <div class="invalid-feedback"></div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="edit_country_code" class="form-label">{{ __('admin/datacenters.fields_country_code') }}</label>
                        <input type="text" class="form-control" id="edit_country_code" name="country_code" maxlength="2"
                               value="{{ old('country_code', $datacenter->country_code) }}"
                               placeholder="{{ __('admin/datacenters.form_country_code_placeholder') }}">
                        <div class="form-text small">{{ __('admin/datacenters.fields_country_code_help') }}</div>
                        <div class="invalid-feedback"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="edit_address" class="form-label">{{ __('admin/datacenters.fields_address') }}</label>
                        <textarea class="form-control" id="edit_address" name="address" rows="3"
                                  placeholder="{{ __('admin/datacenters.form_address_placeholder') }}">{{ old('address', $datacenter->address) }}</textarea>
                        <div class="invalid-feedback"></div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="edit_notes" class="form-label">{{ __('admin/datacenters.fields_notes') }}</label>
                        <textarea class="form-control" id="edit_notes" name="notes" rows="3"
                                  placeholder="{{ __('admin/datacenters.form_notes_placeholder') }}">{{ old('notes', $datacenter->notes) }}</textarea>
                        <div class="invalid-feedback"></div>
                    </div>
                </div>
            </div>

        <x-slot:footer>
            <x-admin.form-actions :cancel-url="route('admin.datacenters.index')" form-id="datacenterForm" />
        </x-slot:footer>
        </form>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    // Route bilgilerini JavaScript'e aktar
    window.routes = {
        datacenters: {
            update: '{{ route("api.admin.datacenters.update", $datacenter) }}',
            index: '{{ route("admin.datacenters.index") }}'
        }
    };

    // Çeviriler
    window.translations = {
        buttons: {
            save: '{{ __("common.buttons_save") }}',
            cancel: '{{ __("common.buttons_cancel") }}'
        },
        messages: {
            loading: '{{ __("common.messages_loading") }}',
            success: '{{ __("common.messages_success") }}',
            error: '{{ __("common.messages_error") }}'
        }
    };
</script>
@vite('resources/js/admin/datacenters/edit.js')
@endpush
