@foreach ($layout as $node) @php $nodeType = $node['type'] ?? ''; @endphp @if ($nodeType === 'row')
@foreach ($node['columns'] ?? [] as $column) @php $width = (int) ($column['width'] ?? 12); if ($width < 1 || $width > 12) { $width = 12; } $colClass = $width < 12 ? 'col-12 col-lg-' . $width : 'col-12'; @endphp
@include('admin.forms.partials.form-layout', ['layout' => $column['items'] ?? []])
@endforeach
@elseif ($nodeType === 'table') @php $nodeCellWidth = (int) ($node['cellWidth'] ?? 0); $nodeCellHeight = (int) ($node['cellHeight'] ?? 0); @endphp
@foreach ($node['rows'] ?? [] as $row) @foreach ($row as $cell) @php $cellWidth = (int) ($cell['width'] ?? 12); if ($cellWidth < 1 || $cellWidth > 12) { $cellWidth = 12; } $cellWidthPx = (int) ($cell['cellWidth'] ?? 0); $cellHeightPx = (int) ($cell['cellHeight'] ?? 0); $cellStyleParts = []; if ($cellWidth < 12) { $cellStyleParts[] = 'width: ' . round(($cellWidth / 12) * 100, 2) . '%;'; } if ($cellWidthPx > 0) { $cellStyleParts[] = 'min-width: ' . $cellWidthPx . 'px;'; } elseif ($nodeCellWidth > 0) { $cellStyleParts[] = 'min-width: ' . $nodeCellWidth . 'px;'; } if ($cellHeightPx > 0) { $cellStyleParts[] = 'height: ' . $cellHeightPx . 'px;'; } elseif ($nodeCellHeight > 0) { $cellStyleParts[] = 'height: ' . $nodeCellHeight . 'px;'; } $cellStyle = implode(' ', $cellStyleParts); @endphp @endforeach @endforeach
@include('admin.forms.partials.form-layout', ['layout' => $cell['items'] ?? []])
@elseif ($nodeType === 'section')
{{ $node['title'] ?? '' }}
@include('admin.forms.partials.form-layout', ['layout' => $node['items'] ?? []])
@elseif ($nodeType === 'content')
{!! $node['html'] ?? '' !!}
@elseif ($nodeType === 'field') @php $field = $node['field'] ?? []; $fieldKey = $field['key'] ?? ''; $fieldLabel = $field['label'] ?? $fieldKey; $fieldType = $field['type'] ?? 'text'; $fieldRequired = !empty($field['required']); $fieldOptions = $field['options'] ?? []; if ($fieldType === 'selectboxes') { $fieldValue = $fieldKey !== '' ? old($fieldKey, []) : []; } else { $fieldValue = $fieldKey !== '' ? old($fieldKey) : null; } $defaultValue = $field['defaultValue'] ?? null; if (($fieldValue === null || $fieldValue === '') && $defaultValue !== null) { $fieldValue = $defaultValue; } $fieldValueScalar = $fieldValue; if (is_array($fieldValue)) { $flatValues = []; array_walk_recursive($fieldValue, function ($value) use (&$flatValues) { if (is_scalar($value)) { $flatValues[] = (string) $value; } }); $fieldValueScalar = $flatValues[0] ?? ''; } $fieldId = $fieldKey !== '' ? ('field_' . preg_replace('/[^a-z0-9_-]+/i', '_', $fieldKey)) : ''; $labelPosition = strtolower(trim((string) ($field['labelPosition'] ?? 'left'))); if ($labelPosition === '') { $labelPosition = 'left'; } $labelWidth = (int) ($field['labelWidth'] ?? 0); $labelMargin = (int) ($field['labelMargin'] ?? 0); $labelAlign = strtolower(trim((string) ($field['labelAlign'] ?? ''))); $inputAlign = strtolower(trim((string) ($field['inputAlign'] ?? ''))); $hideLabel = !empty($field['hideLabel']) || $labelPosition === 'hidden'; $searchable = !empty($field['searchable']); $inputWidth = (int) ($field['inputWidth'] ?? $field['input_width'] ?? 0); $inputHeight = (int) ($field['inputHeight'] ?? $field['input_height'] ?? 0); if ($inputWidth < 0) { $inputWidth = 0; } if ($inputHeight < 0) { $inputHeight = 0; } $placeholder = trim((string) ($field['placeholder'] ?? '')); $prefix = trim((string) ($field['prefix'] ?? '')); $suffix = trim((string) ($field['suffix'] ?? '')); $description = trim((string) ($field['description'] ?? '')); $tooltip = trim((string) ($field['tooltip'] ?? '')); $disabled = !empty($field['disabled']); $readonly = !empty($field['readonly']); $surveyQuestions = $field['questions'] ?? []; $surveyValues = $field['surveyValues'] ?? []; $labelAfter = in_array($labelPosition, ['right', 'bottom'], true); $rowClasses = ['form-layout-row']; if (in_array($labelPosition, ['top', 'bottom'], true)) { $rowClasses[] = 'form-layout-row-vertical'; } if ($labelPosition === 'right') { $rowClasses[] = 'form-layout-row-right'; } if ($hideLabel) { $rowClasses[] = 'form-layout-row-no-label'; } $rowStyle = ''; if ($labelWidth > 0) { $rowStyle .= '--label-width:' . $labelWidth . 'px;'; } if ($labelMargin > 0) { $rowStyle .= '--label-gap:' . $labelMargin . 'px;'; } if ($inputAlign !== '') { $rowStyle .= '--input-align:' . $inputAlign . ';'; } $inputStyle = ''; if ($inputWidth > 0) { $inputStyle .= 'width:' . $inputWidth . 'px;max-width:100%;'; } if ($inputHeight > 0) { $inputStyle .= 'height:' . $inputHeight . 'px;'; } $inputStyleAttr = $inputStyle !== '' ? 'style="' . $inputStyle . '"' : ''; $inputClass = $disabled ? 'disabled' : ''; @endphp @if ($fieldKey !== '')
@if (!$labelAfter) @endif
@php $hasAddon = $prefix !== '' || $suffix !== ''; @endphp @if ($fieldType === 'checkbox')
@elseif ($fieldType === 'textarea') @if ($hasAddon)
@if ($prefix !== '') {{ $prefix }} @endif @if ($suffix !== '') {{ $suffix }} @endif
@else @endif @elseif ($fieldType === 'select') @php $placeholderText = $placeholder !== '' ? $placeholder : "Se\u{00e7}iniz"; $selectedLabel = ''; if ($fieldValue !== null && $fieldValue !== '') { foreach ($fieldOptions as $option) { if ((string) $fieldValue === (string) ($option['value'] ?? '')) { $selectedLabel = (string) ($option['label'] ?? $fieldValue); break; } } if ($selectedLabel === '') { $selectedLabel = (string) $fieldValue; } } @endphp @if ($searchable && $fieldId !== '')
@if ($hasAddon)
@if ($prefix !== '') {{ $prefix }} @endif @if ($suffix !== '') {{ $suffix }} @endif
@else @endif
@else @if ($hasAddon)
@if ($prefix !== '') {{ $prefix }} @endif @if ($suffix !== '') {{ $suffix }} @endif
@else @endif @endif @elseif ($fieldType === 'selectboxes')
@foreach ($fieldOptions as $option) @php $checked = is_array($fieldValue) && in_array((string) $option['value'], array_map('strval', $fieldValue), true); $optionId = $fieldId . '_' . preg_replace('/[^a-z0-9_-]+/i', '_', (string) $option['value']); @endphp
@endforeach
@elseif ($fieldType === 'radio')
@foreach ($fieldOptions as $option) @php $optionId = $fieldId . '_' . preg_replace('/[^a-z0-9_-]+/i', '_', (string) $option['value']); @endphp
@endforeach
@elseif ($fieldType === 'number') @if ($hasAddon)
@if ($prefix !== '') {{ $prefix }} @endif @if ($suffix !== '') {{ $suffix }} @endif
@else @endif @elseif ($fieldType === 'date') @elseif ($fieldType === 'datetime') @elseif ($fieldType === 'time') @elseif ($fieldType === 'email') @elseif ($fieldType === 'tel') @elseif ($fieldType === 'url') @elseif ($fieldType === 'password') @elseif ($fieldType === 'file') @elseif ($fieldType === 'signature') @elseif ($fieldType === 'survey') @php $questions = is_array($surveyQuestions) ? $surveyQuestions : []; $values = is_array($surveyValues) ? $surveyValues : []; $answers = is_array($fieldValue) ? $fieldValue : []; @endphp
@foreach ($questions as $question) @php $questionLabel = (string) ($question['label'] ?? $question['value'] ?? ''); $questionKey = (string) ($question['value'] ?? $question['label'] ?? ''); $questionKey = $questionKey !== '' ? $questionKey : ('q_' . $loop->index); $answerValue = $answers[$questionKey] ?? ''; $inputName = $fieldKey . '[' . $questionKey . ']'; @endphp
{{ $questionLabel }}
@if ($values)
@foreach ($values as $option) @php $optionValue = (string) ($option['value'] ?? $option['label'] ?? ''); $optionLabel = (string) ($option['label'] ?? $optionValue); $optionId = $fieldId . '_' . preg_replace('/[^a-z0-9_-]+/i', '_', $questionKey . '_' . $optionValue); @endphp
@endforeach
@else @endif
@endforeach
@elseif ($fieldType === 'address') @php $addressValue = $fieldValue; if (is_array($addressValue)) { $addressValue = implode(' ', array_filter(array_map('trim', $addressValue))); } @endphp @elseif ($fieldType === 'resource') @if ($fieldOptions) @php $placeholderText = $placeholder !== '' ? $placeholder : "Se\u{00e7}iniz"; $selectedLabel = ''; if ($fieldValue !== null && $fieldValue !== '') { foreach ($fieldOptions as $option) { if ((string) $fieldValue === (string) ($option['value'] ?? '')) { $selectedLabel = (string) ($option['label'] ?? $fieldValue); break; } } if ($selectedLabel === '') { $selectedLabel = (string) $fieldValue; } } @endphp @if ($searchable && $fieldId !== '')
@else @endif @else @endif @else @if ($hasAddon)
@if ($prefix !== '') {{ $prefix }} @endif @if ($suffix !== '') {{ $suffix }} @endif
@else @endif @endif
@if ($description !== '')
{{ $description }}
@endif @if ($labelAfter) @endif
@endif @endif @endforeach