@extends('layouts.admin')

@section('title', 'مدیریت محتوا')

@section('content')
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    لیست محتواها
                </h2>
                <ul class="header-dropdown m-r--5">
                    <li>
                        <a href="{{ route('admin.contents.create') }}" class="btn btn-primary waves-effect">
                            <i class="material-icons">add</i>
                            <span>افزودن محتوا</span>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="body">
                <form action="{{ route('admin.contents.index') }}" method="GET" class="m-b-20">
                    <div class="row clearfix">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" name="search" class="form-control" placeholder="جستجو..." value="{{ request('search') }}">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <select class="form-control show-tick" name="category_id">
                                    <option value="">همه دسته‌بندی‌ها</option>
                                    @foreach($categories as $cat)
                                        <option value="{{ $cat->id }}" {{ request('category_id') == $cat->id ? 'selected' : '' }}>{{ $cat->name_fa }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <button type="submit" class="btn btn-info waves-effect">جستجو</button>
                        </div>
                    </div>
                </form>

                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>عنوان</th>
                                <th>دسته‌بندی</th>
                                <th>نوع</th>
                                <th>وضعیت</th>
                                <th>تاریخ انتشار</th>
                                <th>عملیات</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($contents as $content)
                            <tr>
                                <th scope="row">{{ $content->id }}</th>
                                <td>{{ $content->title }}</td>
                                <td>{{ $content->category ? $content->category->name_fa : '-' }}</td>
                                <td>
                                    @if($content->content_type == 'video') <i class="material-icons">videocam</i>
                                    @elseif($content->content_type == 'audio') <i class="material-icons">audiotrack</i>
                                    @elseif($content->content_type == 'image') <i class="material-icons">image</i>
                                    @else <i class="material-icons">description</i>
                                    @endif
                                </td>
                                <td>
                                    @if($content->status == 'published')
                                        <span class="label label-success">منتشر شده</span>
                                    @elseif($content->status == 'draft')
                                        <span class="label label-warning">پیش‌نویس</span>
                                    @else
                                        <span class="label label-default">آرشیو</span>
                                    @endif
                                </td>
                                <td>{{ $content->published_at ? $content->published_at->format('Y/m/d H:i') : '-' }}</td>
                                <td>
                                    <a href="{{ route('admin.contents.edit', $content->id) }}" class="btn btn-info btn-circle waves-effect waves-circle waves-float">
                                        <i class="material-icons">edit</i>
                                    </a>
                                    <form action="{{ route('admin.contents.destroy', $content->id) }}" method="POST" style="display:inline-block">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger btn-circle waves-effect waves-circle waves-float" onclick="return confirm('آیا از حذف این آیتم مطمئن هستید؟')">
                                            <i class="material-icons">delete</i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="7" class="text-center">هیچ محتوایی یافت نشد.</td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                    {{ $contents->links('pagination::bootstrap-4') }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
