'use strict';
import { c } from 'react/compiler-runtime';
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { initSearchResult } from './SearchResult.funcs.js';
import { Icon, iconSizes } from '../../../fd-component-toolbox/icon/Icon.js';
import { tableDisplayModes } from '../../../../fd-toolbox/enums/enums.js';
import { Link } from '../../../fd-component-toolbox/link/Link.js';
import { getResourceViewUrl } from '../../../meta/services/meta-navigations.js';
import { Table } from '../../../meta/table/Table.js';
import { SubHeading } from '../../../fd-component-toolbox/subheading/SubHeading.js';
import { getSearchDialogTableConfig } from '../search-dialog-table-config.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function SearchResults(t0) {
  const $ = c(11);
  const {
    resourceName,
    items,
    onClose,
    onRefreshSearchResults
  } = t0;
  const [uiResourceMeta, setUiResourceMeta] = useState();
  const [readonly, setReadonly] = useState(false);
  const [iconResource, setIconResource] = useState("");
  let t1;
  if ($[0] !== resourceName) {
    t1 = async () => {
      await initSearchResult(resourceName, setUiResourceMeta, setReadonly, setIconResource);
    };
    $[0] = resourceName;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = [];
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  useAsyncEffect(t1, t2);
  let t3;
  if ($[3] !== iconResource || $[4] !== items || $[5] !== onClose || $[6] !== onRefreshSearchResults || $[7] !== readonly || $[8] !== resourceName || $[9] !== uiResourceMeta) {
    t3 = jsxs(Fragment, {
      children: [jsxs("div", {
        className: "mb-4 ml-4 flex items-center space-x-2",
        children: [jsx(Icon, {
          name: iconResource,
          size: iconSizes.medium
        }), jsx(Link, {
          href: getResourceViewUrl(resourceName),
          onClick: onClose,
          children: jsx(SubHeading, {
            children: uiResourceMeta?.resourceMeta.display.pluralName ?? resourceName
          })
        })]
      }), jsx("div", {
        children: jsx(Table, {
          items,
          uiResourceMeta,
          tableConfig: {
            ...getSearchDialogTableConfig(),
            readonly,
            displayMode: tableDisplayModes.minimal
          },
          onItemDeleted: onRefreshSearchResults
        })
      })]
    });
    $[3] = iconResource;
    $[4] = items;
    $[5] = onClose;
    $[6] = onRefreshSearchResults;
    $[7] = readonly;
    $[8] = resourceName;
    $[9] = uiResourceMeta;
    $[10] = t3;
  } else {
    t3 = $[10];
  }
  return t3;
}
__name(SearchResults, "SearchResults");

export { SearchResults };
