<?php

namespace App\Http\Livewire;

use LaravelViews\Views\TableView;
use App\Models\Payments;
use App\Actions\ViewDetailPayment;
use App\Actions\DeletePayment;
use App\Models\Especiality;
use DateTime; 
use App\Http\Livewire\ConfigSearch;

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

    public $searchBy = ['description', 'reference', 'amount','created_at'];
    

     /**
     * Define el repositorio para obtener solo especialidades activas
     */
    public function repository()
    {
        return Payments::where('active', 1);
    }


    /**
     * 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.reference'), 
            __('common-table.table.amount'),
            __('common-table.table.especiality'),
            __('common-table.table.paymentMethod'),
            __('common-table.table.currency'),
            __('common-table.table.createdAt')
        ];
    }

    /**
     * Sets the data to every cell of a single row
     *
     * @param $model Current model for each row
     */
    public function row($model): array
    {
        return [
            $model->reference,
            $model->amount,
            $model->especiality()->first()->name,
            $model->paymentMethod()->first()->title,
            $model->currency()->first()->title,
            $model->created_at
        ];
    }

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