<?php

namespace App\Http\Livewire;

use Illuminate\Http\Request;
use LaravelViews\Views\TableView;
use App\Models\Files;
use App\Models\Especiality;
use App\Actions\ViewDetailFile;
use App\Http\Livewire\ConfigSearch;

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



    protected function repository()
    {
        $model;
        if(isset($_GET["id"]))
            $model = Files::where("history_id",$_GET["id"])->orderBy("created_at", "asc");
        else
         $model = Files::all();
        return $model;
    }



    /**
     * 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'),
            __("com-form-history.idControl"), 
            __('common-table.table.name'),
            __('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->control_history_id,-4),
            $model->friendly_name,
            $model->created_at,
            $model->updated_at
        ];
    }


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