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

@php
    $id = $id ?? $name ?? 'field-'.uniqid();
    $errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag();
    $errorMessage = $name ? $errorBag->first($name) : null;
    $showOptional = $optional && ! $required;
@endphp

<div>
    @if ($label)
        <label for="{{ $id }}" class="form-label">
            {{ $label }}
            @if ($required)<span class="text-danger">*</span>@endif
            @if ($showOptional)<span class="text-muted fw-normal">{{ __('common.optional') }}</span>@endif
        </label>
    @endif

    {{ $slot }}

    @if ($errorMessage)
        <div class="invalid-feedback d-block">{{ $errorMessage }}</div>
    @endif
</div>
