<?php

namespace App\Http\Livewire;

use LaravelViews\Views\DetailView;
use App\Models\Appointments;
use App\Models\Patients;
use DateTime;
use LaravelViews\Facades\UI;


class AppointmentDetailView extends DetailView
{


    protected $modelClass = Appointments::class;

    /**
     * @param $model Model instance
     * @return Array Array with all the detail data or the components
     */
    public function detail($model)
    {
        $representatives = [];
        $address = [];
        $tags = [];
        $date  = new DateTime($model->date);
        if((int) $model->patient()->first()->age < 18){
            $representatives[__('common-view.view.representatives') ] = Patients::getRepresentatives($model->patient()->first());
        }

        // Obtener las etiquetas de la cita y generar el HTML para mostrarlas
        if ($model->tags && $model->tags->count() > 0) {
            $tagsHtml = '';
            foreach ($model->tags as $tag) {
                $tagsHtml .= '<span class="badge me-2" style="background-color:' . $tag->color . '; color: white; padding: 5px 10px; border-radius: 30px; margin-bottom: 5px; display: inline-block;">' . $tag->name . '</span>';
            }
            $tags[__('appointment-tags.appointment_tags')] = $tagsHtml;
        }

        $address = [
            __('common-view.view.phones') => '<span style="background-color:#4245A4 !important; color:#fff; font-size: 0.90em" class="badge bg-warning">'.implode('</span> <span style="background-color:#db3737 !important; color:#fff; font-size: 0.90em" class="badge bg-warning">', $model->getPhoneAppointment()).'</span>',
            __('common-view.view.emails') =>  '<span style="background-color:#4245A4 !important; color:#fff; font-size: 0.90em" class="badge bg-warning">'.implode('</span> <span style="background-color:#db3737 !important; color:#fff; font-size: 0.90em" class="badge bg-warning">', $model->getEmailAppointment()).'</span>'
        ];
        return array_merge(
            [
                __('common-view.view.date') => $date->format('d/m/Y'),
                __('common-view.view.hour') => $date->format('h:i A'),
                __('common-view.view.reasonAppointment') => $model->summary,
                __('common-view.view.doctor') => $model->user()->first()->profile()->first()->firstname . ' ' . $model->user()->first()->profile()->first()->lastname
            ],
            $tags,
            $representatives,
            $address
        );
    }
}
