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/SearchBar/index.tsx
var SearchBar_exports = {};
__export(SearchBar_exports, {
  default: () => SearchBar_default
});
module.exports = __toCommonJS(SearchBar_exports);
var import_antdConfirmPromise = require("./../Modal/antdConfirmPromise");
var import_CreateBaseModal = __toESM(require("./../CreateBaseModal"));
var import_EditableString = __toESM(require("./../EditableString"));
var import_SearchWorkspaceAndBase = __toESM(require("./../SearchWorkspaceAndBase"));
var import_Sort = __toESM(require("./../../../workSpaceList/components/Sort"));
var import_icons = require("@ant-design/icons");
var import_icon = require("@pisell/icon");
var import_materials = require("@pisell/materials");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_index = require("./index.less");
var operateItems = [
  {
    key: "rename",
    label: "Rename workspace",
    icon: /* @__PURE__ */ import_react.default.createElement(import_icon.Edit03, null)
  },
  {
    key: "editDescription",
    label: "Edit description",
    icon: /* @__PURE__ */ import_react.default.createElement(import_icon.InfoCircle, null)
  },
  {
    type: "divider"
  },
  {
    key: "delete",
    label: "Delete workspace",
    icon: /* @__PURE__ */ import_react.default.createElement(import_icon.Trash01, null)
  }
];
var SearchBar = (props) => {
  const {
    title,
    onTitleChange,
    onDescribeChange,
    describe,
    isDetail,
    onDelete,
    onSort,
    onAddBase,
    editingTitle: editingTitleProps
  } = props;
  const [editingTitle, setEditingTitle] = (0, import_react.useState)(editingTitleProps);
  const [editingDescribe, setEditingDescribe] = (0, import_react.useState)(false);
  const [open, setOpen] = (0, import_react.useState)(false);
  const handleTitleChange = (val) => {
    if (!val) return;
    setEditingTitle(false);
    if (title === val) return;
    onTitleChange == null ? void 0 : onTitleChange(val);
  };
  const handleDescribeChange = (val) => {
    setEditingDescribe(false);
    if (val === describe) return;
    onDescribeChange == null ? void 0 : onDescribeChange(val);
  };
  const handleGoBack = () => {
    window.history.back();
  };
  const onDropdownClick = async ({ key }) => {
    if (key === "rename") {
      setEditingTitle(true);
    } else if (key === "editDescription") {
      setEditingDescribe(true);
    } else if (key === "delete") {
      await (0, import_antdConfirmPromise.antdConfirmPromise)({
        type: "confirm",
        title: "Are you sure you want to delete this workspace?",
        content: "There is base in this Workspace, and deletion can cause all of the data in base and base to be deleted.",
        okText: "Delete workspace"
      });
      onDelete == null ? void 0 : onDelete();
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("search-bar-wrap", {
        ["detail-wrap"]: isDetail
      })
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "line-1" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "left", classNames: { item: "left-item" } }, isDetail && /* @__PURE__ */ import_react.default.createElement(import_icon.ArrowLeft, { onClick: handleGoBack, className: "back-icon" }), /* @__PURE__ */ import_react.default.createElement(
      import_EditableString.default,
      {
        editing: editingTitle || editingTitleProps,
        editable: isDetail,
        text: title,
        onChange: handleTitleChange,
        maxLength: 200,
        ellipsis: {
          row: 1
        },
        className: "title"
      }
    )), /* @__PURE__ */ import_react.default.createElement(import_materials.Space, { className: "right", size: isDetail ? 24 : 16 }, isDetail && /* @__PURE__ */ import_react.default.createElement(import_SearchWorkspaceAndBase.default, null), /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        type: isDetail ? "primary" : void 0,
        onClick: () => setOpen(true)
      },
      "Create a base"
    ), /* @__PURE__ */ import_react.default.createElement(import_materials.Dropdown, { menu: { items: operateItems, onClick: onDropdownClick } }, /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.EllipsisOutlined, null) })))),
    /* @__PURE__ */ import_react.default.createElement(
      import_EditableString.default,
      {
        editing: editingDescribe,
        editable: false,
        text: describe || "",
        onChange: handleDescribeChange,
        className: "describe",
        ellipsis: {
          row: 3
        },
        maxLength: 500
      }
    ),
    isDetail && /* @__PURE__ */ import_react.default.createElement("div", { className: "line-2" }, /* @__PURE__ */ import_react.default.createElement(import_Sort.default, { onChange: onSort })),
    /* @__PURE__ */ import_react.default.createElement(
      import_CreateBaseModal.default,
      {
        open,
        onCancel: () => setOpen(false),
        onAddBase
      }
    )
  );
};
var SearchBar_default = SearchBar;
