<?php

namespace App\Http\Livewire;

use Illuminate\Http\Request;
use LaravelViews\Views\TableView;
use App\Models\ControlHistory;
use App\Models\Especiality; 
use App\Actions\DeleteControl;
use App\Http\Livewire\ConfigSearch;

class ControlHistoryTableView extends TableView
{
    use ConfigSearch;
    /**
     * Sets a model class to get the initial data
     */
    protected $model = ControlHistory::class;

    public $history;


    protected function repository()
    {
        return ControlHistory::where("history_id", $this->history->id)->orderBy("created_at", "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.especiality'),
            __('common-table.table.doctor'),
            __('common-table.table.reasonTitle'),
            __("Cie"),
            __('common-table.table.reasonSummary'),
            __('common-table.table.reasonDiagnosis'),
            __('common-table.table.createdAt'),
            __('common-table.table.updatedAt')
        ];
    }

    /**
     * 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_control,
            Especiality::getEspecialities()[$model->especiality],
            $model->user()->first()->name,
            $model->title,
            $model->cie_code,
            $model->summary,
            $model->diagnosis,
            $model->created_at,
            $model->updated_at
        ];
    }

    public function actionsByRow()
    {
        return [
            new DeleteControl()
        ];
    }
}