@php
    use App\Helpers\Template as Template;
    use App\Helpers\Hightlight as Hightlight;
    use App\Models\CategoryProductModel;
@endphp
<div class="x_content">
    <div class="table-responsive">
        <table class="table table-striped jambo_table bulk_action">
            <thead>
                <tr class="headings">
                    <th class="column-title">#</th>
                    <th class="column-title">Name</th>
                    <th class="column-title">Ordering</th>
                    <th class="column-title">Trạng thái</th>
                    <th class="column-title">Hiện thị Home</th>
                    <th class="column-title">Kiểu hiện thị</th>
                    <th class="column-title">Tạo mới</th>
                    <th class="column-title">Chỉnh sửa</th>
                    <th class="column-title">Hành động</th>
                </tr>
            </thead>
            <tbody>
                @if (count($items) > 0)
                    @foreach ($items as $key => $val)
                        @php
                            $index           = $key + 1;
                            $class           = ($index % 2 == 0) ? "even" : "odd";
                            $id              = $val['id'];
                            $name            = str_repeat('|----', $val["depth"]) . $val["name"];
                            $status          = Template::showItemStatus($controllerName, $id, $val['status']);
                            $isHome          = Template::showItemIsHome($controllerName, $id, $val['is_home']);
                            $display         = Template::showItemSelect($controllerName, $id, $val['display'], 'display');
                            $createdHistory  = Template::showItemHistory($val['created_by'], $val['created']);
                            $modifiedHistory = Template::showItemHistory($val['modified_by'], $val['modified']);
                            $listBtnAction   = Template::showButtonAction($controllerName, $id);
                            $node = CategoryProductModel::find($id);
                            $getNextSibling = $node->getNextSibling();
                            $getPrevSibling = $node->getPrevSibling();
                            $upButton = '<a href="'.route('categoryProduct/ordering',['ordering'=>'up','id'=>$id]).'"  data-class="btn-success" class="btn btn-primary">Up</a>';
                            $downButton = '<a href="'.route('categoryProduct/ordering',['ordering'=>'down','id'=>$id]).'"  data-class="btn-success" class="btn btn-primary">Down</a>';
                            if ($getPrevSibling == null) {
                                $upButton = '';
                            }
                            if ($getNextSibling == null) {
                                $downButton = '';
                            }
                            $ordering = $upButton . $downButton;
                        @endphp

                        <tr class="{{ $class }} pointer">
                            <td >{{ $index }}</td>
                            <td width="25%">{!! $name !!}</td>
                            <td>{!! $ordering !!}</td>
                            <td>{!! $status !!}</td>
                            <td>{!! $isHome  !!}</td>
                            <td>{!! $display !!}</td>
                            <td>{!! $createdHistory !!}</td>
                            <td>{!! $modifiedHistory !!}</td>
                            <td class="last">{!! $listBtnAction !!}</td>
                        </tr>
                    @endforeach
                @else
                    @include('admin.templates.list_empty', ['colspan' => 9])
                @endif
            </tbody>
        </table>
    </div>
</div>