@extends('admin.layouts.app')

@section('title', __('admin/logs.mail_logs'))

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header :title="__('admin/logs.mail_logs')" icon="fas fa-envelope">
        <button type="button" class="btn btn-outline-secondary btn-sm" id="refreshLogs">
            <i class="fas fa-sync-alt"></i> {{ __('admin/logs.buttons_refresh') }}
        </button>
    </x-admin.page-header>

    <x-admin.card>
        <!-- Filtreler -->
        <div class="row mb-3">
            <div class="col-md-2">
                <label for="filterModule" class="form-label">{{ __('admin/logs.filters_module') }}</label>
                <select class="form-select" id="filterModule">
                    <option value="">{{ __('admin/logs.filters_title') }}</option>
                    @foreach($modules as $module)
                        <option value="{{ $module }}">{{ $module }}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-md-2">
                <label for="filterStartDate" class="form-label">{{ __('admin/logs.filters_start_date') }}</label>
                <input type="date" class="form-control" id="filterStartDate">
            </div>
            <div class="col-md-2">
                <label for="filterEndDate" class="form-label">{{ __('admin/logs.filters_end_date') }}</label>
                <input type="date" class="form-control" id="filterEndDate">
            </div>
            <div class="col-md-2">
                <label for="filterIpAddress" class="form-label">{{ __('admin/logs.filters_ip_address') }}</label>
                <input type="text" class="form-control" id="filterIpAddress" placeholder="192.168.1.1">
            </div>
            <div class="col-md-2">
                <label for="filterSearch" class="form-label">{{ __('admin/logs.filters_search') }}</label>
                <input type="text" class="form-control" id="filterSearch" placeholder="{{ __('admin/logs.filters_search_placeholder') }}">
            </div>
            <div class="col-md-2">
                <label for="filterObserver" class="form-label">{{ __('admin/logs.fields_observer') }}</label>
                <input type="text" class="form-control" id="filterObserver" placeholder="Observer adı">
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12">
                <button type="button" class="btn btn-primary btn-sm" id="applyFilters">
                    <i class="fas fa-filter"></i> {{ __('admin/logs.filters_apply_filters') }}
                </button>
                <button type="button" class="btn btn-outline-secondary btn-sm" id="clearFilters">
                    <i class="fas fa-times"></i> {{ __('admin/logs.filters_clear_filters') }}
                </button>
            </div>
        </div>

        <!-- Log Tablosu -->
        <div class="table-responsive">
            <table id="mailLogsTable" class="table table-bordered table-striped"
                   data-records-url="{{ route('api.admin.logs.records') }}"
                   data-log-type="mail">
                <thead>
                    <tr>
                        <th>{{ __('admin/logs.fields_id') }}</th>
                        <th>{{ __('admin/logs.fields_module') }}</th>
                        <th>{{ __('admin/logs.fields_observer') }}</th>
                        <th>{{ __('admin/logs.fields_ip_address') }}</th>
                        <th>{{ __('admin/logs.fields_method') }}</th>
                        <th>{{ __('admin/logs.fields_description') }}</th>
                        <th>{{ __('admin/logs.fields_elapsed_ms') }}</th>
                        <th>{{ __('admin/logs.fields_user_info') }}</th>
                        <th>{{ __('admin/logs.fields_created_at') }}</th>
                        <th>{{ __('admin/logs.fields_actions') }}</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    // Yetki kontrolü için permissions nesnesi
    window.permissions = {
        logs: {
            view: {{ json_encode(Auth::user()->can('viewAny', App\Models\Log::class)) }}
        }
    };

    // Route bilgilerini JavaScript'e aktar
    window.routes = {
        logs: {
            view: '{{ route("admin.logs.show", ":id") }}',
        }
    };

    // Dil çevirileri
    window.translations = {
        logs: {
            buttons: {
                view: '{{ __("admin/logs.buttons_view") }}'
            },
            messages: {
                filters_applied: '{{ __("admin/logs.messages_filters_applied") }}',
                filters_cleared: '{{ __("admin/logs.messages_filters_cleared") }}'
            }
        }
    };

    // Mail logları için özel ayarlar
    window.logSettings = {
        type: 'mail',
        pageTitle: '{{ __("admin/logs.mail_logs") }}'
    };
</script>
@vite('resources/js/admin/logs/mail.js')
@endpush
