<?php

namespace App\Http\Livewire;

use LaravelViews\Views\TableView;
use App\Models\History;
use App\Actions\ViewDetailHistory;
use App\Actions\EditHistory;
use App\Http\Livewire\ConfigSearch;
use App\Models\Especiality;
class HistoryTableView extends TableView
{
    use ConfigSearch;
   /**
     * Sets a model class to get the initial data
     */
    protected $model = History::class;

    public $searchBy = ['patient.firstname','patient.lastname', 'summary','especiality'];


    protected function repository()
    {
        return History::orderBy("number_history", "asc");
    }


    /**
     * Sets the headers of the table as you want to be displayed
     *
     * @return array<string> Array of headers
     */
    public function headers(): array
    {
        return [
            __('common-table.table.id'), 
            __('common-table.table.firstname'),
            __('common-table.table.lastname'),
            __('common-table.table.especiality')
        ];
    }

    /**
     * Sets the data to every cell of a single row
     *
     * @param $model Current model for each row
     */
    public function row($model): array
    {
        return [
            $model->number_history,
            $model->patient()->get()->first()->firstname,
            $model->patient()->get()->first()->lastname,
            Especiality::getEspecialities()[$model->especiality]
        ];
    }

    /** For actions by item */
    protected function actionsByRow(){
        return [
            new ViewDetailHistory,
            new EditHistory
        ];
    }
}
