@extends('layouts.app')
@section('title', __('clinicSite::lang.pages'))

@section('content')
<section class="content-header">
    <h1><i class="fas fa-file-lines"></i> {{ __('clinicSite::lang.pages') }}
        <small>Build pages from drag-and-drop sections</small></h1>
</section>

<section class="content">
    @include('clinicSite::admin._flash')
    <div class="row">
        <div class="col-md-9">
            @component('components.widget', ['title' => 'Your pages', 'class' => 'box-primary'])
                <table class="table table-hover">
                    <thead><tr><th>Title</th><th>URL</th><th>Sections</th><th>Status</th><th class="text-right">Actions</th></tr></thead>
                    <tbody>
                    @forelse($pages as $p)
                        <tr>
                            <td><strong>{{ $p->title }}</strong>
                                @if($p->is_home)<span class="label label-info"><i class="fa fa-home"></i> Home</span>@endif</td>
                            <td><code>/{{ $p->is_home ? '' : $p->slug }}</code></td>
                            <td>{{ count($p->orderedBlocks()) }}</td>
                            <td>
                                @if($p->status==='published')<span class="label label-success">Published</span>
                                @else<span class="label label-default">Draft</span>@endif
                            </td>
                            <td class="text-right">
                                <a href="{{ route('cs.preview', $p->id) }}" target="_blank" class="btn btn-xs btn-default"><i class="fa fa-eye"></i></a>
                                <a href="{{ route('cs.pages.edit', $p->id) }}" class="btn btn-xs btn-primary"><i class="fa fa-pen"></i> Edit</a>
                                @if(!$p->is_home)
                                    <form method="POST" action="{{ route('cs.pages.home', $p->id) }}" style="display:inline">@csrf
                                        <button class="btn btn-xs btn-default" title="Set as home"><i class="fa fa-home"></i></button></form>
                                    <form method="POST" action="{{ route('cs.pages.destroy', $p->id) }}" style="display:inline"
                                          onsubmit="return confirm('Delete this page?')">@csrf @method('DELETE')
                                        <button class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button></form>
                                @endif
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="5" class="text-center text-muted" style="padding:24px;">No pages yet — create your first one.</td></tr>
                    @endforelse
                    </tbody>
                </table>
            @endcomponent
        </div>
        <div class="col-md-3">
            @component('components.widget', ['title' => 'Add a page'])
                <form method="POST" action="{{ route('cs.pages.store') }}">@csrf
                    <div class="form-group">
                        <input type="text" name="title" class="form-control" placeholder="Page title, e.g. About us" required>
                    </div>
                    <button class="btn btn-primary btn-block"><i class="fa fa-plus"></i> Create page</button>
                </form>
            @endcomponent
        </div>
    </div>
</section>
@endsection
