Загрузка данных


@extends('layouts.app')

@section('title', 'Велосипеды')

@section('content')
<div class="container">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>Велосипеды</h1>
        <a href="{{ route('bikes.create') }}" class="btn btn-success">+ Добавить велосипед</a>
    </div>
    
    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif
    
    @if(session('error'))
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif
    
    <div class="table-responsive">
        <table class="table table-bordered table-striped table-hover text-center align-middle">
            <thead class="table-dark">
                <tr>
                    <th>ID</th>
                    <th>Модель</th>
                    <th>Тип</th>
                    <th>Фирма</th>
                    <th>Цена/мин (руб)</th>
                    <th>Статус</th>
                    <th>Действия</th>
                </tr>
            </thead>
            <tbody>
                @foreach($bikes as $bike)
                <tr>
                    <td>{{ $bike->id }}</td>
                    <td class="text-start"><strong>{{ $bike->bikeModel->model ?? '—' }}</strong></td>
                    <td>
                        @php
                            $types = [
                                'city' => 'Городской',
                                'mountain' => 'Горный',
                                'road' => 'Шоссейный',
                                'kid' => 'Детский',
                                'electric' => 'Электрический'
                            ];
                        @endphp
                        {{ $types[$bike->type] ?? $bike->type }}
                    </td>
                    <td>{{ $bike->bikeModel->firm->name ?? '—' }}</td>
                    <td class="fw-bold">{{ number_format($bike->price_per_minute, 2) }} руб.</td>
                    <td>
                        @if($bike->status == 'available')
                            <span class="badge bg-success" style="font-size: 0.9rem;">Доступен</span>
                        @elseif($bike->status == 'rented')
                            <span class="badge bg-warning text-dark" style="font-size: 0.9rem;">В аренде</span>
                        @else
                            <span class="badge bg-danger" style="font-size: 0.9rem;">Обслуживание</span>
                        @endif
                    </td>
                    <td>
                        <div class="btn-group btn-group-sm" role="group">
                            <a href="{{ route('bikes.show', $bike->id) }}" class="btn btn-primary">Подробнее</a>
                            <a href="{{ route('bikes.edit', $bike->id) }}" class="btn btn-warning">Ред.</a>
                            <button type="button" class="btn btn-danger" onclick="confirmDelete({{ $bike->id }})">Удалить</button>
                        </div>
                        
                        <form id="delete-form-{{ $bike->id }}" action="{{ route('bikes.destroy', $bike->id) }}" method="POST" style="display: none;">
                            @csrf
                            @method('DELETE')
                        </form>
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
    
    <div class="d-flex justify-content-center mt-4">
        {{ $bikes->links() }}
    </div>
</div>

<script>
function confirmDelete(id) {
    if (confirm('Вы уверены, что хотите удалить этот велосипед?')) {
        document.getElementById('delete-form-' + id).submit();
    }
}
</script>
@endsection