@extends('layouts.app')

@section('title', 'Prompt Library | SEF Solution')

@section('content')
<div class="admin-page">
    <div class="admin-card">
        <div class="admin-top">
            <div>
                <span class="brand-badge">SEF Solution</span>
                <h1>Prompt Library</h1>
                <p>এখানে যত prompt save করবে, active prompt গুলো chatbot-এর learning context হিসেবে কাজ করবে।</p>
            </div>
            <div class="top-actions">
                <a href="{{ route('admin.dashboard') }}" class="admin-link">Dashboard</a>
                <a href="{{ route('admin.prompts.create') }}" class="admin-link">Add Prompt</a>
                <form method="POST" action="{{ route('admin.logout') }}">@csrf<button class="admin-link admin-link-btn">Logout</button></form>
            </div>
        </div>

        @if(session('success'))
            <div class="flash-box">{{ session('success') }}</div>
        @endif

        <div class="table-wrap">
            <table class="lead-table">
                <thead>
                <tr>
                    <th>Title</th>
                    <th>Category</th>
                    <th>Status</th>
                    <th>Created By</th>
                    <th>Updated</th>
                    <th>Actions</th>
                </tr>
                </thead>
                <tbody>
                @forelse($prompts as $prompt)
                    <tr>
                        <td>
                            <strong>{{ $prompt->title }}</strong>
                            <div class="table-subtext">{{ \Illuminate\Support\Str::limit($prompt->normalized_prompt_text, 110) }}</div>
                        </td>
                        <td>{{ $prompt->category }}</td>
                        <td><span class="status-chip">{{ ucfirst($prompt->status) }}</span></td>
                        <td>{{ $prompt->created_by ?: 'Admin' }}</td>
                        <td>{{ $prompt->updated_at?->format('d M Y h:i A') }}</td>
                        <td>
                            <div class="action-stack">
                                <a href="{{ route('admin.prompts.edit', $prompt) }}">Edit</a>
                                <form method="POST" action="{{ route('admin.prompts.delete', $prompt) }}" onsubmit="return confirm('এই prompt delete করতে চান?')">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="link-btn-danger">Delete</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="empty-state">কোন prompt এখনো save হয়নি।</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <div class="pagination-wrap">{{ $prompts->links() }}</div>
    </div>
</div>
@endsection
