{{--
 * Blade Template
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Views
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
--}}

@props(['field', 'wireModelPrefix'])

@php
    $isSpacer    = isset($field->type) && $field->type === 'spacer';
    $isFullwidth = ($field->fullwidth ?? false) === true;
    $wireModel   = $isSpacer ? '' : $wireModelPrefix . '.' . $field->name;
    $hasInfo     = !empty($field->info ?? null);
@endphp

@if ($isSpacer)

    <div @class(['sm:col-span-2' => $isFullwidth])></div>

@else

    <div @class(['sm:col-span-2' => $isFullwidth])>
        <label for="dff-{{ $field->name }}" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
            {{ $field->label ?? $field->name }}
            @if ($field->mandatory === true)
                <x-globals::global.input-required-hint />
            @endif
            @if ($hasInfo)
                {{-- TODO: (i)-Icon mit Tooltip --}}
            @endif
        </label>

        @if (isset($field->type) && $field->type === 'select' && isset($field->options))
            <x-globals::dynamic-form.fields.select :field="$field" :wire-model="$wireModel" />
        @elseif (isset($field->type) && $field->type === 'number')
            <x-globals::dynamic-form.fields.number :field="$field" :wire-model="$wireModel" />
        @elseif (isset($field->type) && $field->type === 'toggle')
            <x-globals::dynamic-form.fields.toggle :field="$field" :wire-model="$wireModel" />
        @elseif (isset($field->type) && $field->type === 'textarea')
            <x-globals::dynamic-form.fields.textarea :field="$field" :wire-model="$wireModel" />
        @else
            <x-globals::dynamic-form.fields.text :field="$field" :wire-model="$wireModel" />
        @endif

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

@endif
