<?php

namespace App\Datatables\Admin\Shop;

use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Tag;
use Yajra\DataTables\Html\Column;

class TagsDataTable extends DataTable
{
    public $model_name = 'tags';

    public $rowReorder = ['selector' => 'tr'];

    public function query(Tag $model)
    {
        $model = $model::with('tag_group')->withCount(['articles', 'shelves', 'species', 'varieties']);

        return $this->buildQuery($model);
    }

    public function modifier($datatables)
    {
        $datatables
            ->editColumn('name', function (Tag $tag) {
                return $tag->name;
            })
            ->rawColumns(['active', 'action']);

        return parent::modifier($datatables);
    }

    protected function getColumns()
    {
        return [
            Column::make('tag_group.name')->title('Groupe')->width(200),
            Column::make('name')->title('Nom'),
            Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false)->width(60),
            Column::make('species_count')->title('#Esp')->class('text-right')->searchable(false)->width(60),
            Column::make('varieties_count')->title('#Var')->class('text-right')->searchable(false)->width(60),
            Column::make('shelves_count')->title('#Ray')->class('text-right')->searchable(false)->width(60),
            $this->makeColumnButtons(),
        ];
    }
}
