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_index$1 = require("../AppearanceShow/index.js");
const require_server = require("../../server.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_materials = require("@pisell/materials");
let _pisell_icon_es_SearchLg = require("@pisell/icon/es/SearchLg");
_pisell_icon_es_SearchLg = require_runtime.__toESM(_pisell_icon_es_SearchLg);
let ahooks = require("ahooks");
require("../../index.less");
//#region src/components/workSpaceList/components/SearchWorkspaceAndBase/index.tsx
const renderWorkspaceItem = (value, label) => ({
	value: label,
	id: value,
	type: "workspace",
	label: /* @__PURE__ */ react.default.createElement("div", null, label)
});
const renderBaseItem = (detail) => ({
	value: detail.name,
	id: detail.id,
	type: "base",
	label: /* @__PURE__ */ react.default.createElement("div", { className: "render-base-item-wrap" }, /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		icon: detail.icon,
		color: detail.color,
		name: detail.name,
		size: 40,
		fontSize: 16
	})), /* @__PURE__ */ react.default.createElement("div", { className: "right-detail" }, /* @__PURE__ */ react.default.createElement("div", { className: "line-1" }, detail.name), /* @__PURE__ */ react.default.createElement("div", { className: "line-2" }, detail.created_at)))
});
const Search = () => {
	const context = require_useEngineContext.default();
	require_index.request.setRequest(context.appHelper.utils.request);
	const [options, setOptions] = (0, react.useState)([]);
	new URLSearchParams(window.location.search);
	const { runAsync, data = {} } = (0, ahooks.useRequest)(require_server.searchWorkspace, {
		manual: true,
		debounceWait: 300
	});
	const handleSearch = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (searchText) {
			if (!searchText) return;
			yield runAsync({
				tenant_id: "0",
				search: searchText
			});
		});
		return function handleSearch(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	(0, react.useEffect)(() => {
		const { workspace, base } = (data === null || data === void 0 ? void 0 : data.data) || {};
		if ((workspace === null || workspace === void 0 ? void 0 : workspace.length) || (base === null || base === void 0 ? void 0 : base.length)) setOptions([{
			label: "Workspace",
			options: (workspace === null || workspace === void 0 ? void 0 : workspace.map((item) => {
				return renderWorkspaceItem(item.id, item.name);
			})) || []
		}, {
			label: "Base",
			options: (base === null || base === void 0 ? void 0 : base.map((item) => {
				return renderBaseItem(item);
			})) || []
		}]);
	}, [data]);
	const handleSelect = (value, option) => {
		if (option.type === "workspace") {} else if (option.type === "base") {}
	};
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.AutoComplete, {
		popupMatchSelectWidth: 400,
		style: { width: 240 },
		options,
		onSearch: handleSearch,
		onSelect: handleSelect
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
		prefix: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_SearchLg.default, { className: "search-icon" }),
		placeholder: "Search",
		size: "large"
	}));
};
//#endregion
exports.default = Search;
