<?php

namespace App\Http\Livewire;

use LaravelViews\Views\TableView;
use App\Models\UserProfile;
use DateTime;
use App\Actions\EditDoctor;
use App\Http\Livewire\ConfigSearch;

class DoctorsTableView extends TableView
{
    use ConfigSearch;
    protected $model = UserProfile::class;

    public $searchBy = ['id', 'firstname', 'lastname'];

    public function headers(): array
    {
        return [
            __('common-table.table.id'),
            __('common-table.table.firstname'),
            __('common-table.table.lastname'),
            __('common-table.table.age'),
            __('common-table.table.birthday'),
            __('common-table.table.createdAt'),
            __('common-table.table.updatedAt'),
            __('common-table.table.specialities'), // Asegúrate de traducir esto si usas lang
        ];
    }

    public function row($model): array
    {
        $date = new DateTime($model->birthday);

        // Obtiene los nombres de especialidades como string separados por coma
        $specialities = $model->especialities->pluck('name')->implode(', ');

        return [
            substr($model->id, -4),
            $model->firstname,
            $model->lastname,
            $model->age,
            $date->format("d/m/Y"),
            $model->created_at,
            $model->updated_at,
            $specialities,
        ];
    }

    protected function actionsByRow(){
        return [
            new EditDoctor
        ];
    }
}
