@if (count($logs) > 0)
    @php
        // Mapping log descriptions and status values to icons and labels
        $descriptionIcons = [
            'created' => ['bg-success', 'feather icon-plus-circle', 'Создан'],
            'updated' => ['bg-primary', 'feather icon-refresh-ccw', 'Изменено'],
        ];

        $statusLabels = [
            'processing' => 'В обработке',
            'collected' => 'Собран',
            'waiting_buyer' => 'Ожидает покупателя',
            'in_way' => 'В пути',
            'closed' => 'Закрыт',
            'cancelled' => 'Отменен',
            'replacement' => 'Замена',
        ];

        $paymentStatuses = [
            'waiting' => 'Ожидается оплата',
            'cancelled' => 'Отказано оплата',
            'payed' => $order->payment_type == 'credit' ? 'Кредит одобрен' : 'Оплачено',
            'cash' => 'Наличный расчет',
            'review' => 'Кредит на рассмотрение',
        ];
    @endphp

    <h2>@lang('admin.logs.title')</h2>
    <ul class="activity-timeline timeline-left list-unstyled mt-2">
        @foreach ($logs->reverse() as $log)
            <li>
                @if (!empty($log->properties['old']['payment_status']))
                    <div class="timeline-icon bg-success">
                        <i class="feather icon-credit-card font-medium-2 align-middle"></i>
                    </div>
                @else
                    @php
                        $iconData = $descriptionIcons[$log->description] ?? ['bg-secondary', 'feather icon-info'];
                    @endphp
                    <div class="timeline-icon {{ $iconData[0] }}">
                        <i class="{{ $iconData[1] }} font-medium-2 align-middle"></i>
                    </div>
                @endif

                <div class="timeline-info">
                    <p class="font-weight-bold mb-0">
                        @if (!empty($log->properties['old']['payment_status']))
                            Статус оплаты
                        @else
                            {{ $iconData[2] ?? '' }}
                        @endif
                    </p>
                    <span class="font-small-3">
                        @if ($log->description == 'updated')
                            @if (!empty($log->properties['old']['status']))
                                @lang('admin.orders.status'):
                                <span
                                    class="text-danger">{{ $statusLabels[$log->properties['old']['status']] ?? '' }}</span>
                                изменено на
                                <span
                                    class="text-success">{{ $statusLabels[$log->properties['attributes']['status']] ?? '' }}</span>
                            @endif

                            @if (!empty($log->properties['old']['payment_status']))
                                @lang('admin.orders.status'):
                                <span
                                    class="text-danger">{{ $paymentStatuses[$log->properties['old']['payment_status']] ?? '' }}</span>
                                изменено на
                                <span
                                    class="text-success">{{ $paymentStatuses[$log->properties['attributes']['payment_status']] ?? '' }}</span>
                            @endif

                            @if (!empty($log->properties['old']['archived']) || !empty($log->properties['attributes']['archived']))
                                @if ($log->properties['old']['archived'])
                                    @lang('admin.unarchived')
                                @else
                                    @lang('admin.archived')
                                @endif
                            @endif
                        @endif
                    </span>
                </div>
                <small class="text-muted">
                    {{ date('H:i, d.m.Y', strtotime($log->created_at)) }} |
                    @lang('admin.orders.user'):
                    <b>
                        @if ($log->description == 'created')
                            {{ $log->causer->phone ?? 'без авторизации' }}
                        @else
                            {{ $log->causer->username ?? '' }}
                        @endif
                    </b>
                </small>
            </li>
        @endforeach
    </ul>
@endif
