import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { Dropdown, IconButton } from "@choiceform/design-system";
import { PromptToolbarAdd, PromptToolbarAttach, CloudUpload } from "@choiceform/icons-react";
import { observer } from "../../../../_vendor/@legendapp/state/react.js";
import { useState } from "react";
import { useEventCallback } from "../../../../_vendor/usehooks-ts/dist-index.js";
import { t } from "../../../../i18n/index.js";
import { PasteFileUrlDialog } from "./paste-file-url-dialog.js";
import { usePromptInputContext } from "../../context/prompt-input-context.js";
const PromptContextMenu = observer(function PromptContextMenu2() {
  const {
    attachmentEnabled,
    handleFileButtonClick,
    allowUploadByUrl,
    allowUploadLocalFiles,
    attachmentMaxCount,
    dragCtx
  } = usePromptInputContext();
  const [isDialogOpen, setIsDialogOpen] = useState(false);
  const handlePasteFileUrl = useEventCallback(() => {
    setIsDialogOpen(true);
  });
  const addContext = t("prompt-input", "add-context");
  const attachFiles = t("prompt-input", "attach-files");
  const pasteFileUrl = t("prompt-input", "paste-file-url");
  const isAttachmentLimitReached = attachmentMaxCount !== void 0 && dragCtx?.attachments.length !== void 0 && dragCtx.attachments.length >= attachmentMaxCount;
  const isUploadEnabled = allowUploadLocalFiles && !isAttachmentLimitReached;
  const isPasteUrlEnabled = allowUploadByUrl && !isAttachmentLimitReached;
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsxs(Dropdown, { children: [
      /* @__PURE__ */ jsx(Dropdown.Trigger, { asChild: true, children: (active) => /* @__PURE__ */ jsx(
        IconButton,
        {
          tooltip: {
            disabled: active,
            content: addContext
          },
          children: /* @__PURE__ */ jsx(PromptToolbarAdd, {})
        }
      ) }),
      /* @__PURE__ */ jsxs(Dropdown.Content, { children: [
        /* @__PURE__ */ jsx(
          Dropdown.Item,
          {
            prefixElement: /* @__PURE__ */ jsx(PromptToolbarAttach, {}),
            onClick: handleFileButtonClick,
            disabled: !isUploadEnabled,
            children: /* @__PURE__ */ jsx(Dropdown.Value, { children: attachFiles })
          }
        ),
        allowUploadByUrl !== void 0 && /* @__PURE__ */ jsx(
          Dropdown.Item,
          {
            prefixElement: /* @__PURE__ */ jsx(CloudUpload, {}),
            onClick: handlePasteFileUrl,
            disabled: !isPasteUrlEnabled,
            children: /* @__PURE__ */ jsx(Dropdown.Value, { children: pasteFileUrl })
          }
        )
      ] })
    ] }),
    allowUploadByUrl !== void 0 && /* @__PURE__ */ jsx(
      PasteFileUrlDialog,
      {
        isOpen: isDialogOpen,
        onClose: () => setIsDialogOpen(false)
      }
    )
  ] });
});
export {
  PromptContextMenu
};
//# sourceMappingURL=prompt-context-menu.js.map
