<?php

namespace App\Http\Livewire;

use LaravelViews\Views\TableView;
use App\Models\MedicalReport;
use App\Actions\DeleteMedicalReport;
use App\Actions\EditMedicalReport;
use App\Actions\ViewDetailMedicalReport;
use Illuminate\Support\Facades\Auth;
use DateTime; 
use App\Http\Livewire\ConfigSearch;

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

    protected function repository()
    {
       return $this->model::getMedicalReportsForPatientSelected();
    }



    /**
     * 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.description'),
            __('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 [
            substr($model->id,-4),
            substr($model->description,0,20) . "...",
            $model->created_at,
            $model->updated_at
        ];
    }

    /** For actions by item */
    protected function actionsByRow(){
        $actions = [new ViewDetailMedicalReport];
        if(Auth::user()->isAbleTo('create-medical-report')){
            $actions = array_merge($actions,[new EditMedicalReport,new DeleteMedicalReport]);
        }
        return $actions;
    }
}
