@extends('admin.layouts.app')

@section('title', __('admin/provisioning-logs.title') . ' #' . $log->id)

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/provisioning-logs.title') . ' #' . $log->id"
        icon="fas fa-tasks"
        :buttons="[['label' => __('admin/common.back'), 'route' => route('admin.provisioning-logs.index'),
                     'icon' => 'fas fa-arrow-left', 'color' => 'outline-secondary']]"
    />

    <x-admin.alert />

    <x-admin.card>
        <dl class="row">
            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_entity') }}</dt>
            <dd class="col-sm-9"><code>{{ $log->entity_type }}</code> #{{ $log->entity_id }}</dd>

            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_family') }} / {{ __('admin/provisioning-logs.fields_module') }}</dt>
            <dd class="col-sm-9">{{ $log->module_family }} / {{ $log->module_name ?? '—' }}</dd>

            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_action') }}</dt>
            <dd class="col-sm-9"><code>{{ $log->action }}</code></dd>

            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_status') }}</dt>
            <dd class="col-sm-9"><span class="badge bg-secondary">{{ __('admin/provisioning-logs.status_'.$log->status) }}</span></dd>

            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_attempts') }}</dt>
            <dd class="col-sm-9">{{ $log->attempts }}</dd>

            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_last_attempt') }}</dt>
            <dd class="col-sm-9">{{ optional($log->last_attempt_at)->format('Y-m-d H:i:s') ?? '—' }}</dd>

            <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_next_retry') }}</dt>
            <dd class="col-sm-9">{{ optional($log->next_retry_at)->format('Y-m-d H:i:s') ?? '—' }}</dd>

            @if($log->error_message)
                <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_error') }}</dt>
                <dd class="col-sm-9"><pre class="text-danger small mb-0">{{ $log->error_message }}</pre></dd>
            @endif

            @if($log->payload)
                <dt class="col-sm-3">{{ __('admin/provisioning-logs.fields_payload') }}</dt>
                <dd class="col-sm-9"><pre class="bg-dark text-light p-2 small">{{ json_encode($log->payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) }}</pre></dd>
            @endif

            @if($log->error_details)
                <dt class="col-sm-3">Stack</dt>
                <dd class="col-sm-9"><pre class="bg-dark text-light p-2 small" style="max-height:300px; overflow:auto;">{{ json_encode($log->error_details, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) }}</pre></dd>
            @endif
        </dl>

        <x-slot:footer>
            <div class="d-flex justify-content-end gap-2">
                @if($log->canRetry())
                    <form action="{{ route('admin.provisioning-logs.retry', $log) }}" method="POST">
                        @csrf
                        <button type="submit" class="btn btn-warning"><i class="fas fa-redo me-1"></i>{{ __('admin/provisioning-logs.action_retry') }}</button>
                    </form>
                @endif
                @if($log->isFailed())
                    <form action="{{ route('admin.provisioning-logs.dismiss', $log) }}" method="POST"
                          onsubmit="return confirm('{{ __('admin/provisioning-logs.dismiss_confirm') }}');">
                        @csrf
                        <button type="submit" class="btn btn-outline-danger"><i class="fas fa-ban me-1"></i>{{ __('admin/provisioning-logs.action_dismiss') }}</button>
                    </form>
                @endif
            </div>
        </x-slot:footer>
    </x-admin.card>
</div>
@endsection
