<?php

namespace Lightscale\LaralightTables\Columns;

use Illuminate\Database\Eloquent\Model;

use Closure;

class LinkColumn extends ElementColumn
{
    protected string $element = 'a';

    private Closure $urlFn;

    public function url(callable $fn) : static
    {
        $this->urlFn = Closure::fromCallable($fn);
        return $this;
    }

    public function getElemAttributes(Model $row) : array
    {
        return parent::getElemAttributes($row) + [
            'href' => $this->urlFn->call($this, $row),
        ];
    }

}