<?php

namespace App\Http\Livewire;

use LaravelViews\Views\TableView;
use App\Models\Patients;
use App\Actions\EditPatient;
use App\Actions\ViewDetailPatient;
use App\Actions\ViewHistory;
use App\Actions\CreateHistory;
use LaravelViews\Data\Contracts\Filterable;
use LaravelViews\Data\Contracts\Searchable;
use LaravelViews\Data\Contracts\Sortable;
use Illuminate\Database\Eloquent\Builder;
use DateTime; 
use App\Http\Livewire\ConfigSearch;

class PatientsTableView extends TableView
{
    use ConfigSearch;

    /**
     * Sets a model class to get the initial data
     */
    protected $model = Patients::class;

    public $searchBy = ["firstname", "lastname", "identification"];

    


    /**
     * 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.identification'),
            __('common-table.table.firstname'),
            __('common-table.table.lastname'),
            __('common-table.table.age'),
            __('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
    {
        $relationships = $model->relationships()->get();
        $date  = new DateTime($model->birthday);

        return [
            $model->identification,
            $model->firstname,
            $model->lastname,
            $model->age,
            $model->created_at,
            $model->updated_at
        ];
    }

    /** For actions by item */
    protected function actionsByRow(){
        return [
            new ViewDetailPatient,
           new EditPatient,
           new ViewHistory,
           new CreateHistory
        ];
    }
}
