'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { tableDisplayModes } from '../../../../fd-toolbox/enums/enums.js';
import { Icon, iconSizes } from '../../../fd-component-toolbox/icon/Icon.js';
import { initSearchSearchableResourceResult, getSearchableProperties, getTableConfig, getSearchResultTableId } from './SearchSearchableResourceResult.funcs.js';
import { Table } from '../../../meta/table/Table.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function SearchSearchableResourceResult(t0) {
  const $ = c(9);
  const {
    resourceName,
    items,
    parentContextName
  } = t0;
  const [uiResourceMeta, setUiResourceMeta] = useState();
  const [iconResource, setIconResource] = useState("");
  let t1;
  if ($[0] !== resourceName) {
    t1 = async () => {
      await initSearchSearchableResourceResult(resourceName, setUiResourceMeta, 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] !== parentContextName || $[6] !== resourceName || $[7] !== uiResourceMeta) {
    const searchableProperties = getSearchableProperties(uiResourceMeta);
    t3 = jsxs("div", {
      children: [jsxs("div", {
        className: "mb-4 ml-4 flex items-center space-x-2",
        children: [jsx(Icon, {
          name: iconResource,
          size: iconSizes.medium
        }), jsx("h2", {
          className: "text-fd-tertiary-900 text-base font-medium",
          children: uiResourceMeta?.resourceMeta.display.pluralName ?? resourceName
        })]
      }), jsx("div", {
        children: jsx(Table, {
          id: getSearchResultTableId(parentContextName ?? "", resourceName),
          items,
          uiResourceMeta,
          tableConfig: {
            ...getTableConfig(searchableProperties),
            displayMode: tableDisplayModes.minimal
          }
        })
      })]
    });
    $[3] = iconResource;
    $[4] = items;
    $[5] = parentContextName;
    $[6] = resourceName;
    $[7] = uiResourceMeta;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  return t3;
}
__name(SearchSearchableResourceResult, "SearchSearchableResourceResult");

export { SearchSearchableResourceResult };
