'use strict';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { fetchUiResourceMeta } from '../../ui-meta-providers.js';
import { useState } from 'react';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { EditResource } from '../../edit-resource/EditResource.js';
import { useMultiListEditResourceConfig } from './use-multi-list-edit-resource-config.js';
import { getEmptyEditResourceConfig } from '../../edit-resource/config/internal-edit-resource-configs.js';
import { first } from '../../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function MultiListEditResource(t0) {
  const $ = c(9);
  const {
    multiListItem,
    onSavingStarting,
    onSavingEnding
  } = t0;
  const [uiResourceMeta, setUiResourceMeta] = useState();
  useMultiListEditResourceConfig(multiListItem.resourceName);
  let t1;
  if ($[0] !== multiListItem.filters || $[1] !== multiListItem.resourceName) {
    t1 = async () => {
      const firstFilter = first(Object.values(multiListItem.filters));
      if (firstFilter.rightSide) {
        setUiResourceMeta(await fetchUiResourceMeta(multiListItem.resourceName));
      }
    };
    $[0] = multiListItem.filters;
    $[1] = multiListItem.resourceName;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = [];
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  useAsyncEffect(t1, t2);
  let t3;
  if ($[4] !== multiListItem.resourceId || $[5] !== onSavingEnding || $[6] !== onSavingStarting || $[7] !== uiResourceMeta) {
    const config = getEmptyEditResourceConfig();
    t3 = jsx("div", {
      id: multiListItem.resourceId || "",
      children: uiResourceMeta ? jsx("div", {
        className: "w-[calc(100%-1rem)] px-4",
        children: jsx(EditResource, {
          uiResourceMeta,
          resourceId: multiListItem.resourceId,
          config,
          isNew: false,
          onSavingStarting,
          onSavingEnding
        })
      }) : ""
    });
    $[4] = multiListItem.resourceId;
    $[5] = onSavingEnding;
    $[6] = onSavingStarting;
    $[7] = uiResourceMeta;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  return t3;
}
__name(MultiListEditResource, "MultiListEditResource");

export { MultiListEditResource as default };
