@extends('adminlte::page')
@section('title','Kategorije')

@section('content_header')
<h1 class="m-0 text-dark">Kategorije</h1>
<div class="create_button">
    <a href="{{ URL::route('admin/categories-create') }}" class="btn btn-default">{{ Lang::get('Dodaj novu kategoriju') }}</a>
</div>
@stop

@section('content')
<table id="data-table" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>{!! Lang::get('common.id') !!}</th>
            <th>{!! Lang::get('common.name') !!}</th>
            <th>{!! Lang::get('common.parent') !!}</th>
            <th>{!! Lang::get('common.status') !!}</th>
            <th>{!! Lang::get('common.actions') !!}</th>
        </tr>
    </thead>

    <tbody>
        @foreach($categories as $item)
        <tr>
            <td>{!! $item->id !!}</td>
            <td>{!! $item->name !!}</a></td>
            <td>{!! ($item->getMainCategory != null) ? $item->getMainCategory->name : '' !!}</td>
            <td>{!! $item->getStatusName->name !!}</a></td>
            <td>
                <div class="btn-group post-category">
                    <button id="action-secondary-btn" data-toggle="dropdown" class="btn btn-warning dropdown-toggle"
                        data-original-title="" title="">
                        {{ Lang::get('Izaberi') }} <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                                <a href="{{ URL::route('admin/categories-edit', [$item->id]) }}">{{ Lang::get('Izmijeni') }}</a>
                        </li>
                        <li>
                            <form method="post" class="delete_form" action="{{route('admin/categories.destroy', [$item->id])}}">
                                @method('DELETE')
                                @csrf
                                @if($item->id > 1)
                                    <button type="submit">{!! Lang::get('Obriši') !!}</button>
                                @endif
                            </form>                            
                        </li>
                    </ul>
                </div>
            </td>
        </tr>
        @endforeach
    </tbody>
</table>
{{ $categories->links() }}
@endsection
@section('js')
@section('plugins.Datatables', true)
<script>
    $(document).ready(function() {

            $('#data-table').DataTable({
                "paging": false,
                "lengthChange": false,
                "searching": true,
                "ordering": true,
                "info": false,
                "autoWidth": false
            });
    } );


</script>
<style>
    .create_button{
        padding: 10px 0;
        margin-top: -40px;
        float: right;
        display: inline-block;
    }
    .create_button a{
        background: #48a2e8;
        color: #ffffff;
    }
</style>
@endsection