@extends('admin.layouts.app')

@section('title', __('dashboard.member_qr_scan_details'))

@section('content')
<x-admin.page-header
    title="{{ __('dashboard.member_qr_scan_details') }}"
    :breadcrumbs="[
        __('dashboard.qr_codes') => route('admin.qr-codes.index'),
        __('dashboard.member_qr_scans') => route('admin.qr-codes.member-scans.index'),
        __('dashboard.details') => '',
    ]"
/>

@php
    $granted = $scan->result === 'granted';
@endphp

<div class="row justify-content-center">
    <div class="col-xl-12">
        <div class="card bg-primary bg-gradient mb-4">
            <div class="card-body">
                <div class="d-flex align-items-center flex-wrap gap-3">
                    <div class="avatar-lg bg-white bg-opacity-25 rounded d-flex align-items-center justify-content-center" style="width: 80px; height: 80px;">
                        <i class="ri-scan-line text-white fs-1"></i>
                    </div>
                    <div class="flex-grow-1">
                        <h3 class="mb-1 text-white">
                            @if ($scan->member_id && $scan->member)
                                <a href="{{ route('admin.members.show', $scan->member_id) }}" class="text-white text-decoration-underline">{{ $scan->member->name }}</a>
                            @elseif ($scan->member)
                                {{ $scan->member->name }}
                            @else
                                {{ __('dashboard.member') }} #{{ $scan->member_id ?? '—' }}
                            @endif
                        </h3>
                        <p class="text-white-50 mb-0">{{ __('dashboard.scanned_at') }}: {{ $scan->scanned_at?->format('Y-m-d H:i:s') ?? '—' }}</p>
                    </div>
                    <div class="ms-md-auto">
                        @if ($granted)
                            <span class="badge bg-success-subtle text-success fs-6">{{ __('dashboard.granted') }}</span>
                        @else
                            <span class="badge bg-danger-subtle text-danger fs-6">{{ __('dashboard.denied') }}</span>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">{{ __('dashboard.general_info') }}</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <x-view-col label="{{ __('dashboard.id') }}" :value="$scan->id" />
                    <x-view-col label="{{ __('dashboard.action') }}" :value="$scan->action" />
                    <x-view-col label="{{ __('dashboard.member') }}" :value="$scan->member?->name ?? '—'" />
                    <x-view-col label="{{ __('dashboard.phone') }}" :value="$scan->member?->phone ?? '—'" />
                    <x-view-col label="{{ __('dashboard.guard') }}" :value="$scan->scannedBy?->name ?? '—'" />
                    <x-view-col label="{{ __('dashboard.scan_result') }}" :value="$granted ? __('dashboard.granted') : __('dashboard.denied')" />
                    <x-view-col label="{{ __('dashboard.deny_reason') }}" :value="$scan->deny_reason ?? '—'" />
                    <x-view-col label="{{ __('dashboard.token') }}" :value="$scan->token ?? '—'" />
                    <x-view-col label="{{ __('dashboard.scanned_at') }}" :value="$scan->scanned_at?->format('Y-m-d H:i:s') ?? '—'" />
                    <x-view-col label="{{ __('dashboard.created_at') }}" :value="$scan->created_at" />
                    <x-view-col label="{{ __('dashboard.updated_at') }}" :value="$scan->updated_at" />
                </div>
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">{{ __('dashboard.note') }}</h5>
            </div>
            <div class="card-body">
                @if ($scan->note)
                    <div class="border rounded p-3 bg-light text-break" style="white-space: pre-wrap;">{{ $scan->note }}</div>
                @else
                    <p class="text-muted mb-0">—</p>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
