@php
    $title = 'Кабинет гостя — Hotel Pineta';
    $heading = 'Кабинет гостя';
    $subheading = '';
@endphp

@extends('layouts.guest')
@section('i18n_page', 'guest_dashboard')

@section('content')
    <div class="stats" style="margin-bottom:18px;">
        <div class="card">
            <div class="stat-label" data-i18n="statTotal">Всего броней</div>
            <div class="stat-value">{{ $stats['total'] }}</div>
        </div>
        <div class="card">
            <div class="stat-label" data-i18n="statAwaiting">Ожидают предоплату</div>
            <div class="stat-value">{{ $stats['awaiting'] }}</div>
        </div>
        <div class="card">
            <div class="stat-label" data-i18n="statConfirmed">Подтверждены</div>
            <div class="stat-value">{{ $stats['confirmed'] }}</div>
        </div>
    </div>

    <div class="grid">
        <div class="card">
            <div class="actions-row" style="justify-content:space-between; margin-bottom:12px;">
                <div>
                    <h3 style="margin:0;" data-i18n="profileTitle">Профиль</h3>
                    <div class="help" style="margin-top:6px;" data-i18n="profileHelp">Ваши данные видны только вам и администратору.</div>
                </div>
                <div class="actions-row">
                    <a href="{{ route('guest.bookings.create_discount') }}" class="primary" data-i18n="newBooking">Новая бронь</a>
                </div>
            </div>
            <div class="meta-grid">
                <div class="meta-row"><div class="k" data-i18n="guestField">Гость</div><div class="v">{{ $guest->full_name }}</div></div>
                <div class="meta-row"><div class="k" data-i18n="phoneField">Телефон</div><div class="v">{{ $guest->phone }}</div></div>
                <div class="meta-row"><div class="k" data-i18n="emailField">E-mail</div><div class="v">{{ $guest->email ?: '—' }}</div></div>
                <div class="meta-row"><div class="k" data-i18n="languageField">Язык</div><div class="v">{{ strtoupper($guest->language) }}</div></div>
                <div class="meta-row"><div class="k" data-i18n="discountField">Скидка</div><div class="v">{{ $guest->discount_percent ? $guest->discount_percent.'%' : 'Пока нет' }}</div></div>
                <div class="meta-row"><div class="k" data-i18n="discountCodeField">Скидочный код</div><div class="v">{{ $guest->discount_code ?: '—' }}</div></div>
            </div>
        </div>

        <div class="card">
            <div class="actions-row" style="justify-content:space-between; margin-bottom:12px;">
                <div>
                    <h3 style="margin:0;" data-i18n="latestTitle">Последние брони</h3>
                    
                </div>
                <a href="{{ route('guest.bookings.index') }}" class="secondary" data-i18n="allBookings">Все брони</a>
            </div>
            @if ($latestBookings->isEmpty())
                <div class="help" data-i18n="empty">Пока броней нет. Создайте первую через кнопку «Новая бронь».</div>
            @else
                <div class="table-scroll">
                <table>
                    <thead>
                    <tr>
                        <th data-i18n="colBooking">Бронь</th>
                        <th data-i18n="colRoom">Комната</th>
                        <th data-i18n="colDates">Даты</th>
                        <th data-i18n="colStatus">Статус</th>
                        <th data-i18n="colAmount">Сумма</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach ($latestBookings as $booking)
                        <tr>
                            <td><a href="{{ route('guest.bookings.show', $booking) }}">{{ $booking->booking_number }}</a></td>
                            <td><span class="js-booking-room" data-room-code="{{ $booking->room?->code }}">№ {{ $booking->room?->code }} — {{ $booking->room?->title }}</span></td>
                            <td>{{ $booking->arrival_date?->format('d.m.Y') }} — {{ $booking->departure_date?->format('d.m.Y') }}</td>
                            <td><span class="badge {{ $booking->status }} js-status" data-status="{{ $booking->status }}">{{ \App\Models\Booking::statusOptions()[$booking->status] ?? $booking->status }}</span></td>
                            <td>{{ number_format((float) $booking->full_amount, 2, '.', ' ') }} €</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
                </div>
            @endif
        </div>
    </div>
@endsection
