<div class="card">
    @if($post->blocks->count())
        <div class="card-header card-header-rose">
            <div class="nav-tabs-navigation">
                <div class="nav-tabs-wrapper">
                    <ul class="nav nav-tabs sortable" data-tabs="tabs" data-href="{{ route('backend.posts.order') }}">
                        @foreach($post->blocks->sortBy('post.order') as $block)
                            <li class="nav-item" id="post_{{ $block->post->id }}">
                                <a class="handle nav-link {{ $loop->last && session()->get('new') || $loop->first && !session()->get('new') ? 'active' : null }}" data-toggle="tab" href="#tab-{{ $block->post->id }}">{{ $block->post->title ?? $block->selector_name ?? 'Bloque '.$loop->iteration }}</a>
                            </li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
        <div class="card-body">
            <div class="tab-content">
                @foreach($post->blocks->sortBy('post.order') as $block)
                    <div class="tab-pane {{ $loop->last && session()->get('new') || $loop->first && !session()->get('new') ? 'active' : null }}" id="tab-{{ $block->post->id }}">
                        {!! Form::model($block, [
                            'route' => ['backend.blocks.update', $block->id],
                            'files' => true,
                            'class' => 'block-update-form'
                        ]) !!}
                        <div class="block">
                            @include('backend.partials.block')
                        </div>
                        <div class="form-group">
                            {!! Form::submit('Guardar', ['class' => 'btn btn-success']) !!}
                            <a href="{{ route('backend.blocks.delete', $block->id) }}" class="btn btn-danger btn-confirm">Eliminar</a>
                            <a href="{{ route('backend.blocks.create', $post->id) }}" class="btn btn-primary">Crear otro bloque</a>
                        </div>
                        {!! Form::close() !!}
                    </div>
                @endforeach
            </div>
        </div>
    @else
        <div class="card-body">
            <a href="{{ route('backend.blocks.create', $post->id) }}" class="btn btn-primary">Crear bloque</a>
        </div>
    @endif
</div>