var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/workSpaceList/components/Card/index.tsx
var Card_exports = {};
__export(Card_exports, {
  default: () => Card_default
});
module.exports = __toCommonJS(Card_exports);
var import_AppearanceEdit = __toESM(require("./../AppearanceEdit"));
var import_AppearanceShow = __toESM(require("./../AppearanceShow"));
var import_Modal = __toESM(require("./../Modal"));
var import_antdConfirmPromise = require("./../Modal/antdConfirmPromise");
var import_constants = require("./../Card/constants");
var import_EditableString = __toESM(require("./../EditableString"));
var import_icons = require("@ant-design/icons");
var import_useEngineContext = __toESM(require("./../../../../hooks/useEngineContext"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_react = __toESM(require("react"));
var import_index = require("./index.less");
var stopPropagation = (e) => {
  e.stopPropagation();
};
var titleMap = {
  duplicate: () => `Duplicate "Untitled Base"`,
  move: "Move Untitled Base to another workspace"
};
var DuplicateContent = () => {
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "duplicate-content-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "appearance-wrap" }, /* @__PURE__ */ import_react.default.createElement(import_AppearanceShow.default, { icon: "Un", color: "#7F56D9", size: 72, fontSize: 30 })), /* @__PURE__ */ import_react.default.createElement(import_materials.Input, null), /* @__PURE__ */ import_react.default.createElement(import_materials.Space, { className: "duplicate-records" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Switch, { defaultChecked: true }), /* @__PURE__ */ import_react.default.createElement("span", null, "Duplicate records")));
};
var MoveContent = () => {
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "move-content-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", null, "Choose workspace"), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Select,
    {
      className: "select",
      options: [
        {
          label: "Workspace 1",
          value: 1
        },
        {
          label: "Workspace 2",
          value: 2
        }
      ]
    }
  ));
};
var Card = (props) => {
  const {
    name,
    describe,
    created_at,
    icon,
    color,
    id,
    onDeleteBase,
    onUpdateBase
  } = props;
  const context = (0, import_useEngineContext.default)();
  const { pushV2AdminPage } = context.appHelper.utils.getApp().history;
  const [editing, setEditing] = (0, import_react.useState)(false);
  const [open, setOpen] = (0, import_react.useState)(false);
  const [popoverOpen, setPopoverOpen] = (0, import_react.useState)(false);
  const [currentType, setCurrentType] = (0, import_react.useState)("");
  const cardRef = (0, import_react.useRef)(null);
  const appearanceEditRef = (0, import_react.useRef)(null);
  const onClick = async ({ key, domEvent }) => {
    domEvent.stopPropagation();
    if (key === "rename") {
      setEditing(true);
    } else if (key === "share") {
    } else if (key === "duplicate") {
      setOpen(true);
      setCurrentType("duplicate");
    } else if (key === "move") {
      setOpen(true);
      setCurrentType("move");
    } else if (key === "customize") {
      setPopoverOpen(true);
    } else if (key === "settings") {
    } else if (key === "delete") {
      await (0, import_antdConfirmPromise.antdConfirmPromise)({
        type: "confirm",
        title: "Are you sure you want to delete Untitled Base?",
        content: "This operation can cause all data in the Base to be deleted.",
        okText: "Delete base"
      });
      onDeleteBase == null ? void 0 : onDeleteBase(id);
    }
  };
  const handleNameChange = (val) => {
    setEditing(false);
    if (name === val) return;
    onUpdateBase == null ? void 0 : onUpdateBase({
      id,
      name: val
    });
  };
  const handleOk = () => {
  };
  const title = (0, import_react.useMemo)(() => {
    const result = titleMap[currentType];
    return (0, import_utils.isFunction)(result) ? result() : result;
  }, [currentType]);
  const content = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_AppearanceEdit.default,
      {
        name,
        color,
        icon,
        isShowName: false,
        colorTitle: "Edit icon appearance",
        ref: appearanceEditRef
      }
    );
  }, [name, color, icon]);
  const handleOpenChange = async (o) => {
    var _a;
    if (!o) {
      setPopoverOpen(o);
      const detail = (_a = appearanceEditRef.current) == null ? void 0 : _a.getDetail();
      const newBase = {
        id,
        color: detail == null ? void 0 : detail.color,
        icon: (detail == null ? void 0 : detail.icon) || "",
        name: detail == null ? void 0 : detail.name
      };
      if (JSON.stringify(newBase) === JSON.stringify({
        id,
        color,
        icon: icon || "",
        name
      }))
        return;
      onUpdateBase == null ? void 0 : onUpdateBase({
        id,
        color: detail == null ? void 0 : detail.color,
        icon: detail == null ? void 0 : detail.icon,
        name: detail == null ? void 0 : detail.name
      });
    }
  };
  const handleCardClick = () => {
    pushV2AdminPage(`/lowcode/${id}`);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.Popover,
    {
      placement: "bottomLeft",
      content,
      open: popoverOpen,
      arrow: false,
      onOpenChange: handleOpenChange,
      destroyTooltipOnHide: true,
      trigger: "click"
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "card-wrap", ref: cardRef, onClick: handleCardClick }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
      import_AppearanceShow.default,
      {
        icon,
        color,
        name,
        size: 72,
        fontSize: 30
      }
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "right" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "line-1" }, /* @__PURE__ */ import_react.default.createElement("span", { onClick: editing && stopPropagation }, /* @__PURE__ */ import_react.default.createElement(
      import_EditableString.default,
      {
        editing,
        editable: false,
        text: name || "",
        onChange: handleNameChange
      }
    )), /* @__PURE__ */ import_react.default.createElement(
      import_materials.Dropdown,
      {
        menu: { items: import_constants.items, onClick },
        placement: "bottomRight"
      },
      /* @__PURE__ */ import_react.default.createElement("span", { className: "operate-wrap", onClick: stopPropagation }, /* @__PURE__ */ import_react.default.createElement(import_icons.EllipsisOutlined, null))
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "line-2" }, created_at)), /* @__PURE__ */ import_react.default.createElement(
      import_Modal.default,
      {
        open,
        title,
        width: 400,
        evenlyButton: true,
        onCancel: () => setOpen(false),
        onOk: handleOk
      },
      currentType === "duplicate" && /* @__PURE__ */ import_react.default.createElement(DuplicateContent, null),
      currentType === "move" && /* @__PURE__ */ import_react.default.createElement(MoveContent, null)
    ))
  );
};
var Card_default = Card;
