import { j as jsxRuntimeExports, e as usePHModal, p as useTranslation, X as useNodeById, Y as useSelectedDriveId, Z as useNodeParentFolderById, i as closePHModal, _ as deleteNode, x as setSelectedNode, m as toast } from "./index-DEuI3Aoa.js";
import { C as ConnectConfirmationModal } from "./confirmation-modal-JaOmXglG.js";
function ConnectDeleteItemModal(props) {
  const { onDelete, deleteLabel, ...restProps } = props;
  return jsxRuntimeExports.jsx(ConnectConfirmationModal, { ...restProps, containerProps: { className: "w-[450px]" }, continueButtonProps: {
    className: "bg-red-900"
  }, continueLabel: deleteLabel, onContinue: onDelete });
}
const DeleteItemModal = () => {
  const phModal = usePHModal();
  const open = phModal?.type === "deleteItem";
  const id = open ? phModal.id : void 0;
  const { t } = useTranslation();
  const node = useNodeById(id);
  const name = node?.name;
  const kind = node?.kind;
  const selectedDriveId = useSelectedDriveId();
  const nodeParentFolder = useNodeParentFolderById(node?.parentFolder);
  async function onDelete() {
    if (!selectedDriveId || !id) {
      return;
    }
    closePHModal();
    const i18nKey = kind === "FOLDER" ? "notifications.deleteFolderSuccess" : "notifications.fileDeleteSuccess";
    await deleteNode(selectedDriveId, id);
    setSelectedNode(nodeParentFolder);
    toast(t(i18nKey), { type: "connect-deleted" });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    ConnectDeleteItemModal,
    {
      open,
      onDelete: () => onDelete(),
      onCancel: () => closePHModal(),
      header: t(`modals.deleteItem.${kind?.toLowerCase()}.header`, {
        item: name
      }),
      body: t(`modals.deleteItem.${kind?.toLowerCase()}.body`),
      cancelLabel: t("common.cancel"),
      deleteLabel: t("common.delete")
    }
  );
};
export {
  DeleteItemModal
};
//# sourceMappingURL=DeleteItemModal-DG5gEziG.js.map
