<?php

namespace App\View\Components;

use Illuminate\Support\Str;
use Illuminate\View\Component;

class ModelFormControlGroup extends Component
{
    public $model;

    public $type;

    public $inputType;

    public $required;

    public $attr;

    public $value;

    public $id;

    public $label;

    public $options;

    public $multiple;

    public function __construct($model, $attr, $label = null, $type = 'input', $inputType = 'text', $required = false, $id = null, $value = null,
        $options = [], $multiple = false)
    {
        $this->model = $model;
        $this->type = $type;
        $this->inputType = $inputType;
        $this->required = $required;
        $this->attr = $attr;
        $this->value = $value ? $value : ($model->id ? $model->{$attr} : old($attr));
        $this->id = $id ? $id : $model::class . '-' .  $attr;
        $this->label = $label ? $label : Str::ucfirst($attr);
        $this->options = $options;
        $this->multiple = $multiple;
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('components.model-form-control-group');
    }
}
