import { jsxs as d, Fragment as u, jsx as n } from "react/jsx-runtime";
import { useState as c } from "react";
import { IconButton as g } from "@mui/material";
import { DeleteOutline as x } from "@mui/icons-material";
import C from "@arcblock/ux/lib/Dialog/confirm";
import { useLocaleContext as h } from "@arcblock/ux/lib/Locale/context";
import y from "@arcblock/ux/lib/Toast";
function P({
  spaceGateway: r,
  onDeleteSpace: l
}) {
  const { t: e } = h(), [m, a] = c(!1), [p, i] = c(!1), s = (o, t) => {
    o?.stopPropagation(), a(t);
  }, f = async (o) => {
    try {
      o?.stopPropagation(), i(!0), await l(r), a(!1);
    } catch (t) {
      console.error(t), y.error(`${e("storage.spaces.gateway.delete.failed")}: ${t.message}`);
    } finally {
      i(!1);
    }
  };
  return /* @__PURE__ */ d(u, { children: [
    /* @__PURE__ */ n(g, { size: "small", onClick: (o) => s(o, !0), children: /* @__PURE__ */ n(x, {}) }),
    /* @__PURE__ */ n(
      C,
      {
        title: e("common.delConfirmDescription", {
          data: `${r?.name}`
        }),
        open: m,
        confirmButton: {
          text: e("common.confirm"),
          props: {
            variant: "contained",
            color: "error",
            loading: p
          }
        },
        cancelButton: {
          text: e("common.cancel"),
          props: {
            variant: "contained",
            color: "primary"
          }
        },
        onConfirm: f,
        onCancel: (o) => s(o, !1)
      }
    )
  ] });
}
export {
  P as default
};
