'use strict';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { MultiList } from '../multi-list/MultiList.js';
import { initializeMultiListItems, onRelationUnassign, onViewMultiListRelationChange } from './RelatedResources.funcs.js';
import { getMultiListItemType } from '../multi-list/multi-list-item-type.js';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function RelatedResources(t0) {
  const $ = c(23);
  const {
    multiListConfig,
    uiResourceMeta,
    setActiveSaveOperations,
    multiListItems: multiListItemsFromProps,
    resource,
    commentList
  } = t0;
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = [];
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const [multiListItems, setMultiListItems] = useState(t1);
  let t2;
  if ($[1] !== uiResourceMeta.resourceMeta) {
    t2 = getMultiListItemType(uiResourceMeta.resourceMeta);
    $[1] = uiResourceMeta.resourceMeta;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  const multiListItemType = t2;
  let t3;
  let t4;
  if ($[3] !== multiListItemType || $[4] !== multiListItemsFromProps || $[5] !== resource || $[6] !== uiResourceMeta) {
    t3 = async () => {
      await initializeMultiListItems(uiResourceMeta, setMultiListItems, resource, multiListItemType, multiListItemsFromProps);
    };
    t4 = [multiListItemsFromProps, uiResourceMeta, resource, multiListItemType];
    $[3] = multiListItemType;
    $[4] = multiListItemsFromProps;
    $[5] = resource;
    $[6] = uiResourceMeta;
    $[7] = t3;
    $[8] = t4;
  } else {
    t3 = $[7];
    t4 = $[8];
  }
  useAsyncEffect(t3, t4);
  let t5;
  if ($[9] !== commentList || $[10] !== multiListConfig || $[11] !== multiListItems || $[12] !== resource || $[13] !== setActiveSaveOperations || $[14] !== uiResourceMeta.resourceMeta) {
    let t6;
    let t7;
    if ($[16] !== resource || $[17] !== uiResourceMeta.resourceMeta) {
      t6 = (context, multiListItem) => onRelationUnassign(context, multiListItem, uiResourceMeta.resourceMeta, resource);
      t7 = (multiListItem_0, newRelatedResource) => onViewMultiListRelationChange(multiListItem_0, uiResourceMeta.resourceMeta, resource, newRelatedResource);
      $[16] = resource;
      $[17] = uiResourceMeta.resourceMeta;
      $[18] = t6;
      $[19] = t7;
    } else {
      t6 = $[18];
      t7 = $[19];
    }
    let t8;
    let t9;
    if ($[20] !== setActiveSaveOperations) {
      t8 = () => setActiveSaveOperations(_temp);
      t9 = () => setActiveSaveOperations(_temp2);
      $[20] = setActiveSaveOperations;
      $[21] = t8;
      $[22] = t9;
    } else {
      t8 = $[21];
      t9 = $[22];
    }
    t5 = jsx("div", {
      className: "flex w-full grow-0 basis-full flex-col gap-y-10 overflow-x-hidden overflow-y-auto",
      children: jsx(MultiList, {
        multiListConfig,
        multiListItems,
        onCustomAction: t6,
        onMultiListResourceRelationChange: t7,
        commentList,
        onSavingStarting: t8,
        onSavingEnding: t9
      })
    });
    $[9] = commentList;
    $[10] = multiListConfig;
    $[11] = multiListItems;
    $[12] = resource;
    $[13] = setActiveSaveOperations;
    $[14] = uiResourceMeta.resourceMeta;
    $[15] = t5;
  } else {
    t5 = $[15];
  }
  return t5;
}
function _temp2(prev_0) {
  return prev_0 - 1;
}
function _temp(prev) {
  return prev + 1;
}
__name(RelatedResources, "RelatedResources");

export { RelatedResources };
