@extends('admin.layouts.app')

@section('title', __('admin/server-groups.create'))

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

    <x-admin.alert />

    <x-admin.card>
        <form id="serverGroupForm" method="POST" action="{{ route('admin.server-groups.store') }}">
            @csrf

            <div class="row">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="create_name" class="form-label">{{ __('admin/server-groups.fields_name') }} <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="create_name" name="name" required
                               placeholder="{{ __('admin/server-groups.form_name_placeholder') }}">
                               @error('name') <div class="invalid-feedback">{{ $message }}</div> @enderror
                        <div class="invalid-feedback"></div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="mb-3">
                        <label for="create_fill_strategy" class="form-label">{{ __('admin/server-groups.fields_fill_strategy') }} <span class="text-danger">*</span></label>
                        <select class="form-select" id="create_fill_strategy" name="fill_strategy" required>
                            <option value="">{{ __('admin/server-groups.form_select_fill_strategy') }}</option>
                            <option value="random">{{ __('admin/server-groups.fill_strategies_random') }}</option>
                            <option value="fill_first">{{ __('admin/server-groups.fill_strategies_fill_first') }}</option>
                            <option value="balanced">{{ __('admin/server-groups.fill_strategies_balanced') }}</option>
                        </select>
                        @error('fill_strategy') <div class="invalid-feedback">{{ $message }}</div> @enderror
                        <div class="invalid-feedback"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-12">
                    <div class="mb-3">
                        <label class="form-label">{{ __('admin/server-groups.fields_servers') }}</label>
                        <div class="form-text mb-2">{{ __('admin/server-groups.messages_select_servers') }}</div>
                        <div class="border rounded p-3" style="max-height: 300px; overflow-y: auto;">
                            @if($servers->isEmpty())
                                <p class="text-muted mb-0">{{ __('admin/server-groups.messages_no_servers_selected') }}</p>
                            @else
                                @foreach($servers as $server)
                                    <div class="form-check mb-2">
                                        <input class="form-check-input" type="checkbox" value="{{ $server->id }}"
                                               id="server_{{ $server->id }}" name="servers[]">
                                        <label class="form-check-label" for="server_{{ $server->id }}">
                                            <strong>{{ $server->name }}</strong> - {{ $server->hostname }} ({{ $server->ip_address }})
                                        </label>
                                    </div>
                                @endforeach
                            @endif
                        </div>
                    </div>
                </div>
            </div>

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

@push('scripts')
<script>
    // Route bilgilerini JavaScript'e aktar
    window.routes = {
        serverGroups: {
            store: '{{ route("api.admin.server-groups.store") }}',
            index: '{{ route("admin.server-groups.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/server-groups/create.js')
@endpush