<?php

namespace App\Http\Livewire;

use LaravelViews\Views\TableView;
use App\Models\User;
use App\Actions\EditPatient;
use App\Actions\DeleteUser;
use App\Actions\ActiveUser;
use App\Actions\ChangeUserPassword;
//use App\Actions\ViewDetailPatient;
use App\Http\Livewire\ConfigSearch;
use DateTime; 

class UsersTableView extends TableView
{
    use ConfigSearch;
    /**
     * Sets a model class to get the initial data
     */
    protected $model = User::class;
    public $searchBy = ['name', 'email'];



    public function repository(){
        return User::where("name",'<>', 'root');
    }

    /**
     * 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.name'), 
            __('common-table.table.email'),
            __('common-table.table.role'),
            __('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->name,
            $model->email,
            $model->getRolName(),
            $model->created_at,
            $model->updated_at
        ];
    }

    /** For actions by item */
    protected function actionsByRow(){
        return [
           new ChangeUserPassword,
           new DeleteUser,
           new ActiveUser
        ];
    }
}

























