'use strict';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { Button } from '../../../fd-component-toolbox/button/Button.js';
import { Icon, iconNames } from '../../../fd-component-toolbox/icon/Icon.js';
import { EditResource } from '../EditResource.js';
import { useState } from 'react';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { fetchUiResourceMeta } from '../../ui-meta-providers.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function EditLinkResource(t0) {
  const $ = c(10);
  const {
    id,
    relatedResourceName,
    isNew,
    onDelete
  } = t0;
  const [uiResourceMeta, setUiResourceMeta] = useState();
  let t1;
  if ($[0] !== relatedResourceName) {
    t1 = async () => {
      setUiResourceMeta(await fetchUiResourceMeta(relatedResourceName));
    };
    $[0] = relatedResourceName;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  useAsyncEffect(t1);
  let t2;
  if ($[2] !== id || $[3] !== isNew || $[4] !== onDelete || $[5] !== uiResourceMeta) {
    let t3;
    if ($[7] !== id || $[8] !== onDelete) {
      t3 = () => onDelete(id);
      $[7] = id;
      $[8] = onDelete;
      $[9] = t3;
    } else {
      t3 = $[9];
    }
    t2 = jsxs("div", {
      className: "border-muted-foreground mb-4 border-b pb-4",
      children: [uiResourceMeta && jsx(EditResource, {
        uiResourceMeta,
        resourceId: id,
        isNew
      }), jsx(Button, {
        size: "icon",
        variant: "icon",
        onClick: t3,
        children: jsx(Icon, {
          name: iconNames.trash
        })
      })]
    }, id);
    $[2] = id;
    $[3] = isNew;
    $[4] = onDelete;
    $[5] = uiResourceMeta;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  return t2;
}
__name(EditLinkResource, "EditLinkResource");

export { EditLinkResource };
