<?php

namespace App\Datatables\Botanic;

use App\Datatables\ParentDataTable as DataTable;
use App\Models\Botanic\Family;
use Yajra\DataTables\Html\Column;

class FamiliesDataTable extends DataTable
{
    public $model_name = 'families';

    public function query(Family $model)
    {
        $model = $model::withCount(['genres', 'species', 'varieties']);

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

    protected function getColumns()
    {
        return [
            Column::make('name')->title('Nom'),
            Column::make('alias'),
            Column::make('latin'),
            Column::make('genres_count')->title('Nb genres')->searchable(false)->addClass('text-right'),
            Column::make('species_count')->title('Nb espèces')->searchable(false)->addClass('text-right'),
            Column::make('varieties_count')->title('Nb variétés')->searchable(false)->addClass('text-right'),
            $this->makeColumnButtons(),
        ];
    }
}
