<?php

namespace App\Actions;

use LaravelViews\Actions\Action;
use LaravelViews\Views\View;

class ViewContactInfoAction extends Action
{


    /**
     * Any title you want to be displayed
     * @var String
     * */
    public $title;

    /**
     * This should be a valid Feather icon string
     * @var String
     */
    public $icon = "phone";


    public function __construct(){
        parent::__construct();
        $this->title = __("common-table.table.contact");
    }

    /**
     * Execute the action when the user clicked on the button
     *
     * @param $model Model object of the list where the user has clicked
     * @param $view Current view where the action was executed from
     */
    public function handle($model, View $view)
    {
        $representantivesData = "";
        foreach($model->patient()->get() as $patient){
            $relationships = $patient->relationships()->get();
            foreach($relationships as $relationship){
                foreach($relationship->representative()->get() as $representative){
                  $representantivesData .= $representative->phone .",";
                }
              }
        }
         $this->success("Numeros de contacto: ".$representantivesData);
    }
}
