@props([
    'name',
    'label' => null,
    'type' => 'text',
    'value' => null,
    'options' => [],
    'placeholder' => '',
    'required' => false,
    'rows' => 4,
])
@php
    $label = $label ?? \Illuminate\Support\Str::headline($name);
    $current = old($name, $value);
    $base = 'mt-1 block w-full rounded-xl border-slate-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500';
@endphp
<div {{ $attributes->only('class') }}>
    <label for="{{ $name }}" class="block text-sm font-medium text-slate-700">
        {{ $label }} @if($required)<span class="text-red-500">*</span>@endif
    </label>

    @if ($type === 'textarea')
        <textarea id="{{ $name }}" name="{{ $name }}" rows="{{ $rows }}" placeholder="{{ $placeholder }}"
                  class="{{ $base }}">{{ $current }}</textarea>
    @elseif ($type === 'select')
        <select id="{{ $name }}" name="{{ $name }}" class="{{ $base }}">
            @foreach ($options as $optValue => $optLabel)
                <option value="{{ $optValue }}" @selected((string) $current === (string) $optValue)>{{ $optLabel }}</option>
            @endforeach
        </select>
    @else
        <input type="{{ $type }}" id="{{ $name }}" name="{{ $name }}" value="{{ $current }}"
               placeholder="{{ $placeholder }}" @if($type==='number') step="0.01" min="0" @endif
               class="{{ $base }}">
    @endif

    @error($name)<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
</div>
