const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../../../utils/index.js");
const require_server = require("../../server.js");
const require_index$1 = require("../CardList/index.js");
const require_index$2 = require("../SearchBar/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_icon_es_ArrowRight = require("@pisell/icon/es/ArrowRight");
_pisell_icon_es_ArrowRight = require_runtime.__toESM(_pisell_icon_es_ArrowRight);
require("./index.less");
//#region src/components/workSpaceList/components/WorkspaceItem/index.tsx
const detailWrapStyle = {
	border: "none",
	padding: 0
};
const WorkspaceItem = (props) => {
	const { title, data, describe, isDetail, id = 0, onSort, onAddBase, loading, onRefresh, onDelete, onDeleteBase, onUpdateBase, scrollRef, baseCount } = props;
	const context = require_useEngineContext.default();
	require_index.request.setRequest(context.appHelper.utils.request);
	const searchParams = new URLSearchParams(window.location.search);
	const [editingTitle, setEditingTitle] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		if (searchParams.get("create") === "true") setEditingTitle(true);
	}, [searchParams]);
	const handleDetailClick = () => {
		context.appHelper.utils.getApp().history.push(`/workspaces/${id}`);
	};
	const handleDelete = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			yield require_server.deleteWorkspace(id);
			onDelete === null || onDelete === void 0 || onDelete();
		});
		return function handleDelete() {
			return _ref.apply(this, arguments);
		};
	}();
	const handleTitleChange = function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (name) {
			setEditingTitle(false);
			yield require_server.updateWorkspace({
				id,
				name
			});
		});
		return function handleTitleChange(_x) {
			return _ref2.apply(this, arguments);
		};
	}();
	const handleDescribeChange = function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* (description) {
			yield require_server.updateWorkspace({
				id,
				description
			});
		});
		return function handleDescribeChange(_x2) {
			return _ref3.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ react.default.createElement("div", {
		className: "workspace-item-wrap",
		style: isDetail ? detailWrapStyle : {}
	}, /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		title,
		describe,
		isDetail,
		onDelete: handleDelete,
		onTitleChange: handleTitleChange,
		onDescribeChange: handleDescribeChange,
		onSort,
		onAddBase,
		editingTitle
	}), /* @__PURE__ */ react.default.createElement(antd.Spin, {
		spinning: loading,
		wrapperClassName: "loading"
	}, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		isDetail: isDetail || false,
		data,
		onAddBase,
		onRefresh,
		onDeleteBase,
		onUpdateBase,
		scrollRef
	})), !isDetail && /* @__PURE__ */ react.default.createElement("div", { className: "view-workspace-wrap" }, /* @__PURE__ */ react.default.createElement("span", {
		className: "view-go-detail",
		onClick: handleDetailClick
	}, /* @__PURE__ */ react.default.createElement("span", { className: "view-workspace-text" }, "View workspace"), /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ArrowRight.default, null)), !!baseCount && /* @__PURE__ */ react.default.createElement("span", {
		className: "count",
		onClick: handleDetailClick
	}, baseCount, " bases in total")));
};
//#endregion
exports.default = WorkspaceItem;
