<?php

namespace App\Datatables\Admin\Shop;

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

class VariationsDataTable extends DataTable
{
    public $model_name = 'variations';

    public function query(Variation $model)
    {
        $model = $model->with(['package', 'unity'])->withCount('offers');

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

    public function modifier($datatables)
    {
        $datatables
            ->editColumn('unity_value', function (Variation $variation) {
                return $variation->unity ? $variation->unity->value : '';
            })
            ->rawColumns(['description', 'action']);

        return parent::modifier($datatables);
    }

    protected function getColumns()
    {
        return [
            Column::make('package.value')->title('Package'),
            Column::make('quantity')->title('Quantité')->class('text-right')->with(80),
            Column::make('unity_value')->title('Unité')->searchable(false)->with(80),
            Column::make('description')->title('Description'),
            Column::make('offers_count')->title('#Ofr')->searchable(false)->class('text-right'),
            $this->makeColumnButtons(),
        ];
    }
}
