<?php

namespace App\Datatables\Admin\Shop;

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

class TagGroupsDataTable extends DataTable
{
    public $model_name = 'tag_groups';

    public $sortedColumn = 2;

    public function query(TagGroup $model)
    {
        $model = $model::with('article_family')->withCount('tags');

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

    public function modifier($datatables)
    {
        $datatables
            ->editColumn('visible', function (TagGroup $tag_group) {
                return view('components.form.toggle', [
                    'name' => 'visible',
                    'value' => $tag_group->visible,
                    'on' => __('oui'),
                    'off' => __('non'),
                    'meta' => 'data-id='.$tag_group->id,
                    'size' => 'sm',
                    'class' => 'visible',
                ]);
            })
            ->rawColumns(['visible', 'action']);

        return parent::modifier($datatables);
    }

    protected function getColumns()
    {
        return [
            Column::make('visible')->title('Visible')->width(60)->searchable(false),
            Column::make('code')->title('Code')->width(100),
            Column::make('name')->title('Nom'),
            Column::make('tags_count')->title('#Tags')->searchable(false)->addClass('text-right')->width(60),
            $this->makeColumnButtons(),
        ];
    }
}
