@extends('admin.layouts.app')

@section('title', 'Content Sections')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3">Content Sections</h1>
                <a href="{{ route('admin.content-sections.create') }}" class="btn btn-primary">
                    <i class="bi bi-plus"></i> Add New Section
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    @if($contentSections->count() > 0)
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Section Key</th>
                                        <th>Title</th>
                                        <th>Content Preview</th>
                                        <th>Status</th>
                                        <th>Sort Order</th>
                                        <th>Image</th>
                                        <th>Last Updated</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($contentSections as $section)
                                        <tr>
                                            <td>
                                                <span class="badge bg-secondary">{{ $section->section_key }}</span>
                                            </td>
                                            <td>
                                                <strong>{{ Str::limit($section->title, 30) }}</strong>
                                            </td>
                                            <td>
                                                <small class="text-muted">
                                                    {{ Str::limit(strip_tags($section->content), 50) }}
                                                </small>
                                            </td>
                                            <td>
                                                @if($section->is_active)
                                                    <span class="badge bg-success">Active</span>
                                                @else
                                                    <span class="badge bg-secondary">Inactive</span>
                                                @endif
                                            </td>
                                            <td>
                                                <span class="badge bg-light text-dark">{{ $section->sort_order }}</span>
                                            </td>
                                            <td>
                                                @if($section->image_path)
                                                    <i class="bi bi-image text-success" title="Has image"></i>
                                                @else
                                                    <i class="bi bi-image text-muted" title="No image"></i>
                                                @endif
                                            </td>
                                            <td>
                                                <small>{{ $section->updated_at->format('M d, Y') }}</small>
                                            </td>
                                            <td>
                                                <div class="btn-group btn-group-sm" role="group">
                                                    <a href="{{ route('admin.content-sections.show', $section) }}" 
                                                       class="btn btn-outline-primary" title="View">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                    <a href="{{ route('admin.content-sections.edit', $section) }}" 
                                                       class="btn btn-outline-secondary" title="Edit">
                                                        <i class="bi bi-pencil"></i>
                                                    </a>
                                                    <form action="{{ route('admin.content-sections.destroy', $section) }}" 
                                                          method="POST" class="d-inline" 
                                                          onsubmit="return confirm('Are you sure you want to delete this content section?')">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="btn btn-outline-danger" title="Delete">
                                                            <i class="bi bi-trash"></i>
                                                        </button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>

                        <!-- Pagination -->
                        @if($contentSections->hasPages())
                            <div class="d-flex justify-content-center mt-4">
                                {{ $contentSections->links() }}
                            </div>
                        @endif
                    @else
                        <div class="text-center py-5">
                            <i class="bi bi-file-text text-muted" style="font-size: 4rem;"></i>
                            <h4 class="text-muted mt-3">No Content Sections Found</h4>
                            <p class="text-muted">Start by creating your first content section to manage your website content.</p>
                            <a href="{{ route('admin.content-sections.create') }}" class="btn btn-primary mt-3">
                                <i class="bi bi-plus"></i> Create First Section
                            </a>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection