@php
$itemCount = count($settingsInGroup);
$groupContentClasses = 'p-6';
if ($itemCount === 2) {
$groupContentClasses .= ' grid grid-cols-1 md:grid-cols-2 gap-6';
} else {
$groupContentClasses .= ' space-y-6'; // Default for 1 or 3+ items
}
@endphp
@foreach($settingsInGroup as $setting)
@php
$settingKey = 'webpilotai.' . $setting['key'];
$currentValueForField = $settingsData[$settingKey] ?? $setting['default'] ?? null;
$inputId = 'setting_' . Str::slug($setting['key'], '_');
$isDisabled = false;
if (isset($setting['depends_on']) && is_array($setting['depends_on'])) {
foreach ($setting['depends_on'] as $dependencySimpleKey => $expectedValueFromSchema) {
// $dependencySimpleKey is like 'enable_feature_x'
// $expectedValueFromSchema is like true, 'active', '1'
$dependencyFullKey = 'webpilotai.' . $dependencySimpleKey;
// Find the schema for the dependency to get its default if not in $settingsData
$dependencySettingSchema = null;
foreach ($settingsSchema as $s_item) { // Iterate to find the dependency's schema
if ($s_item['key'] === $dependencySimpleKey) {
$dependencySettingSchema = $s_item;
break;
}
}
// The default value for the *dependency* field
$dependencyDefaultValue = $dependencySettingSchema['default'] ?? null;
// The actual current value of the *dependency* field (already cast by controller)
$actualDependencyValue = $settingsData[$dependencyFullKey] ?? $dependencyDefaultValue;
// Normalize $expectedValueFromSchema for comparison against $actualDependencyValue
$normalizedExpectedValue = $expectedValueFromSchema;
if (is_bool($actualDependencyValue)) {
if (is_string($expectedValueFromSchema)) {
$testVal = strtolower($expectedValueFromSchema);
if ($testVal === 'true' || $testVal === '1') {
$normalizedExpectedValue = true;
} elseif ($testVal === 'false' || $testVal === '0') {
$normalizedExpectedValue = false;
}
}
} else {
$actualDependencyValue = (string) $actualDependencyValue;
$normalizedExpectedValue = (string) $normalizedExpectedValue;
}
if ($actualDependencyValue != $normalizedExpectedValue) {
$isDisabled = true;
break;
}
}
}
@endphp
{{-- Individual Setting Item --}}
@if($setting['type'] === 'boolean' || $setting['type'] === 'checkbox')
@if(isset($setting['description']))
{{ $setting['description'] }}
@endif
@else
@if($setting['type'] === 'text' || $setting['type'] === 'number' || $setting['type'] === 'password')
@elseif($setting['type'] === 'textarea')
@elseif($setting['type'] === 'select' && isset($setting['options']))
@endif
@if(isset($setting['description']))
{{ $setting['description'] }}
@endif
@endif
@error($settingKey)
{{ $message }}
@enderror
@endforeach