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/WorkspaceItem/index.tsx
var WorkspaceItem_exports = {};
__export(WorkspaceItem_exports, {
  default: () => WorkspaceItem_default
});
module.exports = __toCommonJS(WorkspaceItem_exports);
var import_CardList = __toESM(require("./../CardList"));
var import_SearchBar = __toESM(require("./../SearchBar"));
var import_icon = require("@pisell/icon");
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_index = require("./index.less");
var import_utils = require("./../../../../utils/index");
var import_useEngineContext = __toESM(require("./../../../../hooks/useEngineContext"));
var import_server = require("./../../server");
var detailWrapStyle = {
  border: "none",
  padding: 0
};
var WorkspaceItem = (props) => {
  const {
    title,
    data,
    describe,
    isDetail,
    id = 0,
    onSort,
    onAddBase,
    loading,
    onRefresh,
    onDelete,
    onDeleteBase,
    onUpdateBase,
    scrollRef,
    baseCount
  } = props;
  const context = (0, import_useEngineContext.default)();
  import_utils.request.setRequest(context.appHelper.utils.request);
  const searchParams = new URLSearchParams(window.location.search);
  const [editingTitle, setEditingTitle] = (0, import_react.useState)(false);
  const tenant_id = "0";
  (0, import_react.useEffect)(() => {
    if (searchParams.get("create") === "true") {
      setEditingTitle(true);
    }
  }, [searchParams]);
  const handleDetailClick = () => {
    context.appHelper.utils.getApp().history.push(`/workspaces/${id}`);
  };
  const handleDelete = async () => {
    await (0, import_server.deleteWorkspace)(id);
    onDelete == null ? void 0 : onDelete();
  };
  const handleTitleChange = async (name) => {
    setEditingTitle(false);
    await (0, import_server.updateWorkspace)({
      id,
      name
    });
  };
  const handleDescribeChange = async (description) => {
    await (0, import_server.updateWorkspace)({
      id,
      description
    });
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "workspace-item-wrap",
      style: isDetail ? detailWrapStyle : {}
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_SearchBar.default,
      {
        title,
        describe,
        isDetail,
        onDelete: handleDelete,
        onTitleChange: handleTitleChange,
        onDescribeChange: handleDescribeChange,
        onSort,
        onAddBase,
        editingTitle
      }
    ),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { spinning: loading, wrapperClassName: "loading" }, /* @__PURE__ */ import_react.default.createElement(
      import_CardList.default,
      {
        isDetail: isDetail || false,
        data,
        onAddBase,
        onRefresh,
        onDeleteBase,
        onUpdateBase,
        scrollRef
      }
    )),
    !isDetail && /* @__PURE__ */ import_react.default.createElement("div", { className: "view-workspace-wrap" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "view-go-detail", onClick: handleDetailClick }, /* @__PURE__ */ import_react.default.createElement("span", { className: "view-workspace-text" }, "View workspace"), /* @__PURE__ */ import_react.default.createElement(import_icon.ArrowRight, null)), !!baseCount && /* @__PURE__ */ import_react.default.createElement("span", { className: "count", onClick: handleDetailClick }, baseCount, " bases in total"))
  );
};
var WorkspaceItem_default = WorkspaceItem;
