@extends('back-end.master.app')

@section('title', 'Folk Poetries')

@section('body')
<main class="app-content">
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4>Folk Poetries</h4>
            <a href="{{ route('publicPoetries.create') }}" class="btn btn-primary btn-sm">
                <i class="fa fa-plus"></i> Add New
            </a>
        </div>
        <div class="card-body">

            {{-- Filter Form --}}
            <form method="GET" action="{{ route('publicPoetries.index') }}" class="row g-3 mb-4">
                <div class="col-md-4">
                    <input type="text" name="title" class="form-control" placeholder="Search by title" value="{{ request('title') }}">
                </div>
                <div class="col-md-3">
                    <select name="cat_id" class="form-control">
                        <option value="">All Categories</option>
                        @foreach($categories as $cat)
                            <option value="{{ $cat->id }}" {{ request('cat_id') == $cat->id ? 'selected' : '' }}>{{ $cat->name_en }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-info">Filter</button>
                    <a href="{{ route('publicPoetries.index') }}" class="btn btn-secondary">Reset</a>
                </div>
            </form>

            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Title</th>
                        <th>Category</th>
                        <th>Date</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($data as $row)
                    <tr>
                        <td>{{ $loop->iteration }}</td>
                        <td>{{ $row->title }}</td>
                        <td>{{ $row->category->name_en ?? '-' }}</td>
                        <td>{{ $row->date }}</td>
                        <td>
                            <a href="{{ route('publicPoetries.show', $row->id) }}" class="btn btn-sm btn-info" title="View">
                                <i class="fa fa-eye"></i>
                            </a>
                            <a href="{{ route('publicPoetries.edit', $row->id) }}" class="btn btn-sm btn-warning" title="Edit">
                                <i class="fa fa-edit"></i>
                            </a>
                            <form action="{{ route('publicPoetries.delete', $row->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Delete this poetry?')">
                                @csrf
                                @method('DELETE')
                                <button class="btn btn-sm btn-danger" title="Delete"><i class="fa fa-trash"></i></button>
                            </form>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="5" class="text-center">No poetries found.</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>

            {{ $data->links('pagination::bootstrap-4') }}
        </div>
    </div>
</main>
@endsection

@section('pageJs')
<script>
    $(".app-menu").removeClass("active");
    $("#nav_plpoetries").addClass("active");
    $("#plpoetries").addClass("is-expanded");
    $("#plpoetries_history").addClass("active");
</script>
@endsection
