'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { Dialog, DialogTrigger, DialogContent, DialogTitle } from '../../../fd-component-toolbox/dialog/Dialog.js';
import { onInitEditResource } from './EditResourceDialog.funcs.js';
import { emptyUuid } from '../../../../fd-toolbox/constants/constants.js';
import { EditResource } from '../EditResource.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 EditResourceDialog(t0) {
  const $ = c(10);
  const {
    trigger,
    dialogConfig
  } = t0;
  const [isDialogOpen, setIsDialogOpen] = useState(false);
  const [resourceId, setResourceId] = useState(emptyUuid);
  const [resourceName, setResourceName] = useState("");
  const [isNew, setIsNew] = useState(true);
  const [uiResourceMeta, setUiResourceMeta] = useState();
  let t1;
  let t2;
  if ($[0] !== dialogConfig) {
    t1 = async () => {
      await onInitEditResource(setResourceName, setResourceId, setIsNew, dialogConfig, setUiResourceMeta);
    };
    t2 = [dialogConfig];
    $[0] = dialogConfig;
    $[1] = t1;
    $[2] = t2;
  } else {
    t1 = $[1];
    t2 = $[2];
  }
  useAsyncEffect(t1, t2);
  let t3;
  if ($[3] !== isDialogOpen || $[4] !== isNew || $[5] !== resourceId || $[6] !== resourceName || $[7] !== trigger || $[8] !== uiResourceMeta) {
    t3 = jsxs(Dialog, {
      open: isDialogOpen,
      onOpenChange: setIsDialogOpen,
      children: [jsx(DialogTrigger, {
        children: trigger
      }), jsxs(DialogContent, {
        children: [jsx(DialogTitle, {
          className: "absolute -m-px size-px overflow-hidden border-0 p-0 whitespace-nowrap",
          children: resourceName
        }), jsx("div", {
          children: uiResourceMeta && jsx(EditResource, {
            uiResourceMeta,
            resourceId,
            onCancelClick: () => setIsDialogOpen(false),
            onDeleteComplete: () => setIsDialogOpen(false),
            onSaveComplete: () => setIsDialogOpen(false),
            isNew
          })
        })]
      })]
    });
    $[3] = isDialogOpen;
    $[4] = isNew;
    $[5] = resourceId;
    $[6] = resourceName;
    $[7] = trigger;
    $[8] = uiResourceMeta;
    $[9] = t3;
  } else {
    t3 = $[9];
  }
  return t3;
}
__name(EditResourceDialog, "EditResourceDialog");

export { EditResourceDialog };
