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

@section('title', 'Блоки')

@section('content_header')
    <div class="d-flex justify-content-between align-items-center">
        <h1 class="m-0">Блоки контента</h1>
        <div class="d-flex gap-2">
            <a href="{{ route('admin.blocks.wizard') }}" class="btn btn-secondary btn-sm">
                <i class="fas fa-magic"></i> Генератор макета
            </a>
            <a href="{{ route('admin.blocks.create') }}" class="btn btn-primary btn-sm">
                <i class="fas fa-plus"></i> Добавить блок
            </a>
        </div>
    </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-primary card-outline">
        <div class="card-body p-0">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Название</th>
                        <th>Системное имя</th>
                        <th>Макет</th>
                        <th>Статус</th>
                        <th class="text-right">Действия</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($blocks as $block)
                        <tr>
                            <td>{{ $block->title }}</td>
                            <td><code>{{ $block->name }}</code></td>
                            <td>
                                @if($block->layout)
                                    <span class="badge badge-info">{{ $block->layoutDefinition()['title'] ?? $block->layout }}</span>
                                @else
                                    <span class="text-muted">—</span>
                                @endif
                            </td>
                            <td>
                                @if($block->is_active)
                                    <span class="badge badge-success">Активен</span>
                                @else
                                    <span class="badge badge-secondary">Отключён</span>
                                @endif
                            </td>
                            <td class="text-right">
                                <a href="{{ route('admin.blocks.edit', $block) }}" class="btn btn-sm btn-primary">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <form action="{{ route('admin.blocks.destroy', $block) }}" method="POST" class="d-inline"
                                      onsubmit="return confirm('Удалить блок «{{ $block->title }}»?')">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-danger">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">Блоков пока нет</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
@stop
