@php
    $currentFormMode = $currentFormMode ?? request()->input('__form_mode', 'create');
    $resourceCandidates = [];

    if (! empty($entityCrudView ?? null)) {
        $resourceCandidates[] = resource_path('views/' . str_replace('.', '/', $entityCrudView) . '/recursos-formulario.php');
    }

    if (! empty($entity ?? null)) {
        $resourceCandidates[] = resource_path('views/administracion/crud/entities/' . $entity . '/recursos-formulario.php');
    }

    $resourceCandidates[] = resource_path('views/administracion/crud/partials/comun/formulario/recursos.php');

    $formResources = null;

    foreach (array_unique($resourceCandidates) as $resourceFile) {
        if (! is_file($resourceFile)) {
            continue;
        }

        $resolvedResources = require $resourceFile;

        if (is_array($resolvedResources)) {
            $formResources = $resolvedResources;
            break;
        }
    }

    if (! is_array($formResources)) {
        throw new RuntimeException('Unable to resolve CRUD form resources for entity [' . ($entity ?? 'unknown') . '].');
    }

    extract($formResources, EXTR_SKIP);
@endphp

@if ($isPersonalEntity)
    @include('administracion.crud.partials.comun.formulario.dominios-modal.personal')
@elseif ($isBienesEntity)
    @includeFirst([
        ($entityCrudView ?? '') . '.form-fields',
        'administracion.crud.partials.comun.formulario.dominios-modal.bienes',
    ])
@elseif ($isSitiosEntity || $isEmbarcacionesEntity)
    @include('administracion.crud.partials.comun.formulario.dominios-modal.ubicaciones')
@elseif ($isRegistroStockEntity)
    @include('administracion.crud.partials.comun.formulario.dominios-modal.inventario')
@elseif ($isTallasUniformesEntity)
    @include('administracion.crud.partials.comun.formulario.dominios-modal.uniformes')
@else
    @include('administracion.crud.partials.comun.formulario.dominios-modal.generico')
@endif
