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

@section('title', $poet->name . ' - Details')

@section('body')
<main class="app-content">
    <div class="container-fluid">
        <div class="card">
            <div class="card-header d-flex justify-content-between">
                <h4>{{ $poet->name }} - Details</h4>
                <a href="{{ route('poets.index') }}" class="btn btn-secondary btn-sm">Back to List</a>
            </div>
            <div class="card-body">
                <div class="row">
                    {{-- Poet Profile --}}
                    <div class="col-md-3 text-center">
                        <img src="{{ asset('storage/'.$poet->image) }}" alt="{{ $poet->name }}" class="img-fluid rounded-circle" style="width: 150px; height: 150px; object-fit: cover;">
                        <h5 class="mt-3">{{ $poet->name }}</h5>
                        <p>{{ $poet->centry->title_ps ?? '' }}</p>
                    </div>
                    <div class="col-md-9">
                        <div class="card">
                            <div class="card-body">
                                <h5>Biography</h5>
                                <p>{{ $poet->bio }}</p>
                                <hr>
                                <div class="row">
                                    <div class="col-sm-4"><strong>Father Name:</strong> {{ $poet->father_name ?? '-' }}</div>
                                    <div class="col-sm-4"><strong>Date of Birth:</strong> {{ $poet->dob ?? '-' }}</div>
                                    <div class="col-sm-4"><strong>Phone:</strong> {{ $poet->phone ?? '-' }}</div>
                                    <div class="col-sm-4"><strong>Email:</strong> {{ $poet->email ?? '-' }}</div>
                                    <div class="col-sm-4"><strong>Address:</strong> {{ $poet->address }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                {{-- Categories and Poetries --}}
                <div class="row mt-4">
                    <div class="col-md-3">
                        <div class="card">
                            <div class="card-header">
                                <h5>Categories</h5>
                            </div>
                            <div class="list-group list-group-flush">
                                <a href="{{ route('poets.show', $poet->id) }}" class="list-group-item list-group-item-action {{ $cat_title == 'All' ? 'active' : '' }}">
                                    All Categories
                                </a>
                                @foreach($categories as $cat)
                                    <a href="{{ route('poetries.category', $cat->id . '-' . $poet->id) }}" class="list-group-item list-group-item-action {{ isset($category) && $category->id == $cat->id ? 'active' : '' }}">
                                        {{ $cat->title_ps }}
                                    </a>
                                @endforeach
                            </div>
                        </div>
                    </div>
                    <div class="col-md-9">
                        <div class="card">
                            <div class="card-header d-flex justify-content-between align-items-center">
                                <h5>Poetries - {{ $cat_title }}</h5>
                                @if($cat_title != 'All' && isset($category))
                                    <a href="{{ route('poetries.poetry_create', $category->id . '-' . $poet->id) }}" class="btn btn-primary btn-sm">
                                        <i class="fa fa-plus"></i> Add Poetry
                                    </a>
                                @else
                                    <a href="{{ route('poetries.all_poetry_create', $poet->id) }}" class="btn btn-primary btn-sm">
                                        <i class="fa fa-plus"></i> Add Poetry
                                    </a>
                                @endif
                            </div>
                            <div class="card-body">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Title</th>
                                            <th>Category</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse($poetries as $row)
                                        <tr>
                                            <td>{{ $loop->iteration }}</td>
                                            <td>{{ $row->title }}</td>
                                            <td>{{ $row->category->title_en ?? '-' }}</td>
                                            <td>
                                                <a href="{{ route('poetries.poetry_edit', $row->id) }}" class="btn btn-sm btn-warning" title="Edit">
                                                    <i class="fa fa-edit"></i>
                                                </a>
                                                <a href="#" onclick="event.preventDefault(); if(confirm('Delete this poetry?')) document.getElementById('delete-poetry-{{ $row->id }}').submit();" class="btn btn-sm btn-danger" title="Delete">
                                                    <i class="fa fa-trash"></i>
                                                </a>
                                                <form id="delete-poetry-{{ $row->id }}" action="{{ route('poetries.poetry_delete', $row->id) }}" method="POST" style="display: none;">
                                                    @csrf
                                                    @method('DELETE')
                                                </form>
                                            </td>
                                        </tr>
                                        @empty
                                        <tr>
                                            <td colspan="4" class="text-center">No poetries found.</td>
                                        </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                                {{ $poetries->links('pagination::bootstrap-4') }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
@endsection

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