@props([
    'name',
    'label',
    'type' => 'text',
    'value' => '',
    'required' => false,
    'placeholder' => '',
    'help' => '',
    'validation' => [],
    'options' => [],
    'multiple' => false,
    'rows' => 3,
    'min' => null,
    'max' => null,
    'step' => null,
    'pattern' => null,
    'autocomplete' => null,
    'disabled' => false,
    'readonly' => false,
    'class' => '',
    'wrapperClass' => 'col-md-6'
])

<div class="{{ $wrapperClass }}">
    <div class="form-group">
        @if($label)
            <label for="{{ $name }}" class="form-label">
                {{ $label }}
                @if($required)
                    <span class="text-danger">*</span>
                @endif
            </label>
        @endif

        @if($type === 'select')
            <select
                name="{{ $name }}"
                id="{{ $name }}"
                class="form-select @error($name) is-invalid @enderror {{ $class }}"
                @if($required) required @endif
                @if($multiple) multiple @endif
                @if($disabled) disabled @endif
                @if($readonly) readonly @endif
                @if($autocomplete) autocomplete="{{ $autocomplete }}" @endif
                @foreach($validation as $rule => $value)
                    data-{{ $rule }}="{{ $value }}"
                @endforeach
            >
                @if(!$required)
                    <option value="">— Select {{ $label }} —</option>
                @endif

                @foreach($options as $value => $label)
                    <option value="{{ $value }}" {{ old($name, $value) == $value ? 'selected' : '' }}>
                        {{ $label }}
                    </option>
                @endforeach
            </select>

        @elseif($type === 'textarea')
            <textarea
                name="{{ $name }}"
                id="{{ $name }}"
                rows="{{ $rows }}"
                class="form-control @error($name) is-invalid @enderror {{ $class }}"
                placeholder="{{ $placeholder }}"
                @if($required) required @endif
                @if($disabled) disabled @endif
                @if($readonly) readonly @endif
                @if($autocomplete) autocomplete="{{ $autocomplete }}" @endif
                @foreach($validation as $rule => $value)
                    data-{{ $rule }}="{{ $value }}"
                @endforeach
            >{{ old($name, $value) }}</textarea>

        @elseif($type === 'checkbox')
            <div class="form-check">
                <input
                    type="checkbox"
                    name="{{ $name }}"
                    id="{{ $name }}"
                    class="form-check-input @error($name) is-invalid @enderror {{ $class }}"
                    value="1"
                    {{ old($name, $value) ? 'checked' : '' }}
                    @if($required) required @endif
                    @if($disabled) disabled @endif
                    @if($readonly) readonly @endif
                    @foreach($validation as $rule => $value)
                        data-{{ $rule }}="{{ $value }}"
                    @endforeach
                >
                <label class="form-check-label" for="{{ $name }}">
                    {{ $label }}
                </label>
            </div>

        @elseif($type === 'radio')
            <div class="form-check">
                @foreach($options as $value => $label)
                    <div class="form-check">
                        <input
                            type="radio"
                            name="{{ $name }}"
                            id="{{ $name }}_{{ $value }}"
                            class="form-check-input @error($name) is-invalid @enderror {{ $class }}"
                            value="{{ $value }}"
                            {{ old($name, $value) == $value ? 'checked' : '' }}
                            @if($required) required @endif
                            @if($disabled) disabled @endif
                            @if($readonly) readonly @endif
                            @foreach($validation as $rule => $value)
                                data-{{ $rule }}="{{ $value }}"
                            @endforeach
                        >
                        <label class="form-check-label" for="{{ $name }}_{{ $value }}">
                            {{ $label }}
                        </label>
                    </div>
                @endforeach
            </div>

        @else
            <input
                type="{{ $type }}"
                name="{{ $name }}"
                id="{{ $name }}"
                class="form-control @error($name) is-invalid @enderror {{ $class }}"
                value="{{ old($name, $value) }}"
                placeholder="{{ $placeholder }}"
                @if($required) required @endif
                @if($disabled) disabled @endif
                @if($readonly) readonly @endif
                @if($autocomplete) autocomplete="{{ $autocomplete }}" @endif
                @if($min) min="{{ $min }}" @endif
                @if($max) max="{{ $max }}" @endif
                @if($step) step="{{ $step }}" @endif
                @if($pattern) pattern="{{ $pattern }}" @endif
                @foreach($validation as $rule => $value)
                    data-{{ $rule }}="{{ $value }}"
                @endforeach
            >
        @endif

        @error($name)
            <div class="invalid-feedback">
                <i class="fas fa-exclamation-triangle me-1"></i>
                {{ $message }}
            </div>
        @enderror

        @if($help)
            <div class="form-text">
                <i class="fas fa-info-circle me-1"></i>
                {{ $help }}
            </div>
        @endif
    </div>
</div>
