<?php

namespace App\View\Components;

use Illuminate\View\Component;
use App\Models\Especiality;
use App\Models\RoleUser;


class PaymentForm extends Component
{

    private  const URL_CREATE_PAYMENT = '/admin/create-payment';
    private  const URL_UPDATE_PAYMENT = '/admin/update-payment';
    private  const NAME_FORM = "Payment";
    public $action = self::URL_CREATE_PAYMENT;
    public $name = self::NAME_FORM;
    public $new;
    public $optionsEspeciality;
    public $paymentMethods;
    public $currencies;
    public $doctors;
    public $payment;
    public $placeHolderAmount = "0,00";

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($currencies,$paymentMethods,$doctors,$payment,$isUpdate = false)
    {
        $this->new = (!$isUpdate);
        if($isUpdate)
            $this->action =  self::URL_UPDATE_PAYMENT;
        $this->optionsEspeciality = Especiality::getEspecialities();
        $this->currencies = $currencies;
        $this->paymentMethods  = $paymentMethods;
        $this->doctors = [];

        foreach($doctors as $doctor){
            if(!(strtoupper(RoleUser::getRolShortname($doctor)) === "ADMIN" OR strtoupper(RoleUser::getRolShortname($doctor)) === "ROOT"))
                array_push($this->doctors,$doctor);
        }
        $this->payment  = $payment;
    }


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