{{-- Вьюха: список услуг в административной панели --}}
@extends('admin.layout')

@section('title', 'Услуги')

@section('content_header')
    <div class="d-flex justify-content-between align-items-center">
        <h1 class="m-0">Услуги</h1>
        <a href="{{ route('admin.services.create') }}" class="btn btn-primary btn-sm">
            <i class="fas fa-plus"></i> Добавить услугу
        </a>
    </div>
@stop

@section('breadcrumb')
    <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">Главная</a></li>
    <li class="breadcrumb-item active">Услуги</li>
@stop

@section('content')
    @if(session('success'))
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            {{ session('success') }}
        </div>
    @endif

    <div class="card card-outline card-primary">
        <div class="card-body p-0">
            @if($services->isEmpty())
                <div class="p-4 text-muted text-center">
                    Услуг пока нет. <a href="{{ route('admin.services.create') }}">Добавить первую</a>
                </div>
            @else
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th style="width:50px">#</th>
                            <th style="width:40px"></th>
                            <th>Название</th>
                            <th>Slug</th>
                            <th style="width:70px">Статус</th>
                            <th style="width:110px"></th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($services as $svc)
                            <tr>
                                <td class="text-muted">{{ $svc->sort_order }}</td>
                                <td style="font-size:20px;line-height:1">{{ $svc->icon ?: '—' }}</td>
                                <td>
                                    <strong>{{ $svc->title }}</strong>
                                    @if($svc->excerpt)
                                        <div class="text-muted small text-truncate" style="max-width:420px">
                                            {{ $svc->excerpt }}
                                        </div>
                                    @endif
                                </td>
                                <td><code class="small">{{ $svc->slug }}</code></td>
                                <td>
                                    @if($svc->is_active)
                                        <span class="badge badge-success">активна</span>
                                    @else
                                        <span class="badge badge-secondary">скрыта</span>
                                    @endif
                                </td>
                                <td>
                                    <a href="{{ route('admin.services.edit', $svc) }}"
                                       class="btn btn-xs btn-default" title="Редактировать">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <form action="{{ route('admin.services.destroy', $svc) }}"
                                          method="POST" class="d-inline"
                                          onsubmit="return confirm('Удалить услугу «{{ addslashes($svc->title) }}»?')">
                                        @csrf @method('DELETE')
                                        <button class="btn btn-xs btn-outline-danger" title="Удалить">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            @endif
        </div>
    </div>
@stop
