const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_index = require("../SearchWorkspaceAndBase/index.js");
const require_index$1 = require("../Sort/index.js");
const require_antdConfirmPromise = require("../Modal/antdConfirmPromise.js");
const require_index$2 = require("../EditableString/index.js");
const require_index$3 = require("../CreateBaseModal/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_materials = require("@pisell/materials");
let _pisell_icon_es_ArrowLeft = require("@pisell/icon/es/ArrowLeft");
_pisell_icon_es_ArrowLeft = require_runtime.__toESM(_pisell_icon_es_ArrowLeft);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _ant_design_icons = require("@ant-design/icons");
let _pisell_icon_es_Edit03 = require("@pisell/icon/es/Edit03");
_pisell_icon_es_Edit03 = require_runtime.__toESM(_pisell_icon_es_Edit03);
let _pisell_icon_es_InfoCircle = require("@pisell/icon/es/InfoCircle");
_pisell_icon_es_InfoCircle = require_runtime.__toESM(_pisell_icon_es_InfoCircle);
let _pisell_icon_es_Trash01 = require("@pisell/icon/es/Trash01");
_pisell_icon_es_Trash01 = require_runtime.__toESM(_pisell_icon_es_Trash01);
require("./index.less");
//#region src/components/workSpaceList/components/SearchBar/index.tsx
const operateItems = [
	{
		key: "rename",
		label: "Rename workspace",
		icon: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Edit03.default, null)
	},
	{
		key: "editDescription",
		label: "Edit description",
		icon: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_InfoCircle.default, null)
	},
	{ type: "divider" },
	{
		key: "delete",
		label: "Delete workspace",
		icon: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Trash01.default, null)
	}
];
const SearchBar = (props) => {
	const { title, onTitleChange, onDescribeChange, describe, isDetail, onDelete, onSort, onAddBase, editingTitle: editingTitleProps } = props;
	const [editingTitle, setEditingTitle] = (0, react.useState)(editingTitleProps);
	const [editingDescribe, setEditingDescribe] = (0, react.useState)(false);
	const [open, setOpen] = (0, react.useState)(false);
	const handleTitleChange = (val) => {
		if (!val) return;
		setEditingTitle(false);
		if (title === val) return;
		onTitleChange === null || onTitleChange === void 0 || onTitleChange(val);
	};
	const handleDescribeChange = (val) => {
		setEditingDescribe(false);
		if (val === describe) return;
		onDescribeChange === null || onDescribeChange === void 0 || onDescribeChange(val);
	};
	const handleGoBack = () => {
		window.history.back();
	};
	const onDropdownClick = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* ({ key }) {
			if (key === "rename") setEditingTitle(true);
			else if (key === "editDescription") setEditingDescribe(true);
			else if (key === "delete") {
				yield require_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 || onDelete === void 0 || onDelete();
			}
		});
		return function onDropdownClick(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("search-bar-wrap", { ["detail-wrap"]: isDetail }) }, /* @__PURE__ */ react.default.createElement("div", { className: "line-1" }, /* @__PURE__ */ react.default.createElement("div", {
		className: "left",
		classNames: { item: "left-item" }
	}, isDetail && /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ArrowLeft.default, {
		onClick: handleGoBack,
		className: "back-icon"
	}), /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		editing: editingTitle || editingTitleProps,
		editable: isDetail,
		text: title,
		onChange: handleTitleChange,
		maxLength: 200,
		ellipsis: { row: 1 },
		className: "title"
	})), /* @__PURE__ */ react.default.createElement(_pisell_materials.Space, {
		className: "right",
		size: isDetail ? 24 : 16
	}, isDetail && /* @__PURE__ */ react.default.createElement(require_index.default, null), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: isDetail ? "primary" : void 0,
		onClick: () => setOpen(true)
	}, "Create a base"), /* @__PURE__ */ react.default.createElement(_pisell_materials.Dropdown, { menu: {
		items: operateItems,
		onClick: onDropdownClick
	} }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, { icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.EllipsisOutlined, null) })))), /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		editing: editingDescribe,
		editable: false,
		text: describe || "",
		onChange: handleDescribeChange,
		className: "describe",
		ellipsis: { row: 3 },
		maxLength: 500
	}), isDetail && /* @__PURE__ */ react.default.createElement("div", { className: "line-2" }, /* @__PURE__ */ react.default.createElement(require_index$1.default, { onChange: onSort })), /* @__PURE__ */ react.default.createElement(require_index$3.default, {
		open,
		onCancel: () => setOpen(false),
		onAddBase
	}));
};
//#endregion
exports.default = SearchBar;
