<?php

namespace App\View\Components\Table\Columns;

use Illuminate\Database\Eloquent\Model;
use App\View\Components\Table\Column;
use App\View\Components\Table\Traits\Configuration\ButtonGroupColumnConfiguration;
use App\View\Components\Table\Traits\Helpers\ButtonGroupColumnHelpers;

class ButtonGroupColumn extends Column
{
    use ButtonGroupColumnConfiguration,
        ButtonGroupColumnHelpers;

    protected array $buttons = [];
    protected string $view = 'components.includes.columns.button-group';
    protected $attributesCallback;

    public function __construct(string $title, string $from = null)
    {
        parent::__construct($title, $from);

        $this->label(fn () => null);
    }

    public function getContents(Model $row)
    {
        return view($this->getView())
            ->withColumn($this)
            ->withRow($row)
            ->withButtons($this->getButtons())
            ->withAttributes($this->hasAttributesCallback() ? app()->call($this->getAttributesCallback(), ['row' => $row]) : []);
    }
}
