@extends('layouts.admin')

@section('title', 'News Management')

@section('content')
<div class="dashboard-header" style="margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center;">
    <div>
        <h1 style="font-family:'Oswald',sans-serif; font-size:2rem; color:var(--primary); margin:0;">News Management</h1>
    </div>
    <div style="display:flex; gap:10px;">
        <a href="{{ route('admin.news.categories') }}" class="btn btn-outline">
            <i class="fas fa-tags"></i> Categories
        </a>
        <a href="{{ route('admin.news.create') }}" class="btn btn-primary">
            <i class="fas fa-plus"></i> Create Article
        </a>
    </div>
</div>

<div class="admin-card">
    <div class="admin-card-body" style="padding:0;">
        @if($news->count())
        <div class="table-responsive">
            <table class="admin-table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Title</th>
                        <th>Category</th>
                        <th>Author</th>
                        <th>Status</th>
                        <th>Featured</th>
                        <th style="text-align:right;">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($news as $item)
                    <tr>
                        <td>{{ $item->id }}</td>
                        <td>
                            <div style="font-weight:600; color:var(--primary);">{{ Str::limit($item->title, 50) }}</div>
                        </td>
                        <td>
                            @if($item->category)
                            <span class="badge badge-info">{{ $item->category->name }}</span>
                            @else
                            <span style="color:var(--text-muted);">-</span>
                            @endif
                        </td>
                        <td>{{ $item->author->name ?? '-' }}</td>
                        <td>
                            @if($item->status === 'published')
                                <span class="badge badge-success">Published</span>
                            @else
                                <span class="badge badge-warning">Draft</span>
                            @endif
                        </td>
                        <td>
                            @if($item->is_featured)
                                <span class="badge badge-success"><i class="fas fa-star"></i> Yes</span>
                            @else
                                <span style="color:var(--text-muted); font-size:0.8rem;">No</span>
                            @endif
                        </td>
                        <td style="text-align:right;">
                            <a href="{{ route('news.show', $item->slug) }}" class="btn btn-outline btn-sm" target="_blank" title="View on site">
                                <i class="fas fa-external-link-alt"></i>
                            </a>
                            <a href="{{ route('admin.news.edit', $item->id) }}" class="btn btn-primary btn-sm">
                                <i class="fas fa-edit"></i>
                            </a>
                            <form action="{{ route('admin.news.destroy', $item->id) }}" method="POST" style="display:inline-block;" onsubmit="return confirm('Delete this article?');">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-danger btn-sm">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div style="padding: 20px;">
            {{ $news->links() }}
        </div>
        @else
        <div style="padding: 60px; text-align: center; color: var(--text-muted);">
            <i class="fas fa-newspaper" style="font-size: 3rem; opacity: 0.5; margin-bottom: 16px; display:block;"></i>
            <p style="margin-bottom:16px;">No news articles found.</p>
            <a href="{{ route('admin.news.create') }}" class="btn btn-primary">
                <i class="fas fa-plus"></i> Create First Article
            </a>
        </div>
        @endif
    </div>
</div>
@endsection
