@props([
    'name',
    'label' => null,
    'type' => 'text',
    'value' => null,
    'placeholder' => null,
    'required' => false,
    'optional' => false,
    'id' => null,
])

@php
    $id = $id ?? $name;
    $current = old($name, $value);
    $errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag();
    $hasError = $errorBag->has($name);
@endphp

<x-ui.form.field :name="$name" :label="$label" :required="$required" :optional="$optional" :id="$id">
    <input
        id="{{ $id }}"
        name="{{ $name }}"
        type="{{ $type }}"
        value="{{ $current }}"
        @if ($placeholder) placeholder="{{ $placeholder }}" @endif
        @if ($required) required @endif
        {{ $attributes->class(['form-control', 'is-invalid' => $hasError]) }}
    >
</x-ui.form.field>
