'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { tabsNames } from '../edit-resource/edit-resource-constants.js';
import { ResourceList } from '../resource-list/ResourceList.js';
import { useSetTitle } from '../page/use-set-title.js';
import { isResourceListView } from '../resource-list/resource-lists.js';
import { getMultilistResourceListConfig } from '../resource-list/resource-list-configs.js';
import { EditResource } from '../edit-resource/EditResource.js';
import { saveUiResourceMetasToCache } from '../ui-meta-providers.js';
import { useOptionalPromise } from '../../../fd-toolbox/hooks/use-optional-promise.js';
import { logAndNotify } from '../../../fd-toolbox/errors/error-handler.js';
import { metaErrorMessages } from '../constants/meta-error-messages-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function View(t0) {
  const $ = c(24);
  const {
    resourceName,
    resourceId,
    onDeleteComplete,
    onCancelClick,
    onSaveComplete,
    config,
    viewName,
    resources,
    uiResourceMetas: uiResourceMetasProp,
    onRefreshItem
  } = t0;
  const uiResourceMetas = useOptionalPromise(uiResourceMetasProp);
  let uiResourceMeta;
  let result;
  if (uiResourceMetas) {
    let t1;
    if ($[0] !== resourceName || $[1] !== uiResourceMetas) {
      let t2;
      if ($[3] !== resourceName) {
        t2 = meta => meta.resourceMeta.resourceName === resourceName;
        $[3] = resourceName;
        $[4] = t2;
      } else {
        t2 = $[4];
      }
      t1 = uiResourceMetas.find(t2);
      $[0] = resourceName;
      $[1] = uiResourceMetas;
      $[2] = t1;
    } else {
      t1 = $[2];
    }
    uiResourceMeta = t1;
    saveUiResourceMetasToCache(uiResourceMetas);
  }
  useSetTitle(resourceName, uiResourceMeta);
  if (!resourceName) {
    logAndNotify(new Error(metaErrorMessages.resourceNameNotSet));
  } else {
    if ($[5] !== config || $[6] !== onCancelClick || $[7] !== onDeleteComplete || $[8] !== onRefreshItem || $[9] !== onSaveComplete || $[10] !== resourceId || $[11] !== resourceName || $[12] !== resources || $[13] !== uiResourceMeta || $[14] !== viewName) {
      const resourceListConfig = getMultilistResourceListConfig(resourceName);
      if (isResourceListView(viewName, resourceId)) {
        result = jsx(ResourceList, {
          config: resourceListConfig,
          resources
        });
      } else {
        if (uiResourceMeta) {
          let t1;
          if ($[16] !== config || $[17] !== onCancelClick || $[18] !== onDeleteComplete || $[19] !== onRefreshItem || $[20] !== onSaveComplete || $[21] !== resourceId || $[22] !== uiResourceMeta) {
            t1 = jsx(EditResource, {
              resourceId,
              config,
              defaultTab: tabsNames.overview,
              onDeleteComplete,
              onCancelClick,
              onSaveComplete,
              onRefreshResource: onRefreshItem,
              uiResourceMeta
            });
            $[16] = config;
            $[17] = onCancelClick;
            $[18] = onDeleteComplete;
            $[19] = onRefreshItem;
            $[20] = onSaveComplete;
            $[21] = resourceId;
            $[22] = uiResourceMeta;
            $[23] = t1;
          } else {
            t1 = $[23];
          }
          result = t1;
        }
      }
      $[5] = config;
      $[6] = onCancelClick;
      $[7] = onDeleteComplete;
      $[8] = onRefreshItem;
      $[9] = onSaveComplete;
      $[10] = resourceId;
      $[11] = resourceName;
      $[12] = resources;
      $[13] = uiResourceMeta;
      $[14] = viewName;
      $[15] = result;
    } else {
      result = $[15];
    }
  }
  return result;
}
__name(View, "View");

export { View };
