<?php

namespace App\View\Components;

use Illuminate\View\Component;
use App\Models\User;
use App\Models\UserProfile;
use App\Models\Especiality;


class UserForm extends Component
{
    private  const URL_CREATE_PATIENT = '/admin/create-user';
    private  const URL_UPDATE_PATIENT = '/admin/update-user';
    private  const NAME_FORM = "User";
    public $user;
    public $userProfile;
    public $especialities;
    public $action = self::URL_CREATE_PATIENT;
    public $name = self::NAME_FORM;
    public $new;
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct(User $user, UserProfile $userProfile, array $especialities, $isUpdate = false)
    {
        $this->user = $user;
        $this->userProfile = $userProfile;
        $this->especialities = $especialities;
        $this->new = (!$isUpdate);
        if($isUpdate)
            $this->action =  self::URL_UPDATE_PATIENT;
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('components.user-form',[
            "user"=>$this->user,
            "name"=>$this->name,
            "action"=>$this->action,
            "id"=>$this->name,
            "new"=>$this->new,
            "people"=> $this->userProfile,
            "especialities"=>$this->especialities
        ]);
    }
}
