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/SearchWorkspaceAndBase/index.tsx
var SearchWorkspaceAndBase_exports = {};
__export(SearchWorkspaceAndBase_exports, {
  default: () => SearchWorkspaceAndBase_default
});
module.exports = __toCommonJS(SearchWorkspaceAndBase_exports);
var import_react = __toESM(require("react"));
var import_AppearanceShow = __toESM(require("./../AppearanceShow"));
var import__ = require("./../../index.less");
var import_icon = require("@pisell/icon");
var import_materials = require("@pisell/materials");
var import_ahooks = require("ahooks");
var import_react2 = require("react");
var import_server = require("./../../server");
var import_utils = require("./../../../../utils/index");
var import_useEngineContext = __toESM(require("./../../../../hooks/useEngineContext"));
var renderWorkspaceItem = (value, label) => ({
  value: label,
  id: value,
  type: "workspace",
  label: /* @__PURE__ */ import_react.default.createElement("div", null, label)
});
var renderBaseItem = (detail) => ({
  value: detail.name,
  id: detail.id,
  type: "base",
  label: /* @__PURE__ */ import_react.default.createElement("div", { className: "render-base-item-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
    import_AppearanceShow.default,
    {
      icon: detail.icon,
      color: detail.color,
      name: detail.name,
      size: 40,
      fontSize: 16
    }
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "right-detail" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "line-1" }, detail.name), /* @__PURE__ */ import_react.default.createElement("div", { className: "line-2" }, detail.created_at)))
});
var Search = () => {
  const context = (0, import_useEngineContext.default)();
  import_utils.request.setRequest(context.appHelper.utils.request);
  const [options, setOptions] = (0, import_react2.useState)([]);
  const searchParams = new URLSearchParams(window.location.search);
  const { runAsync, data = {} } = (0, import_ahooks.useRequest)(import_server.searchWorkspace, {
    manual: true,
    debounceWait: 300
  });
  const handleSearch = async (searchText) => {
    if (!searchText) return;
    await runAsync({
      tenant_id: "0",
      search: searchText
    });
  };
  (0, import_react2.useEffect)(() => {
    const { workspace, base } = (data == null ? void 0 : data.data) || {};
    if ((workspace == null ? void 0 : workspace.length) || (base == null ? void 0 : base.length)) {
      const newOptions = [
        {
          label: "Workspace",
          options: (workspace == null ? void 0 : workspace.map((item) => {
            return renderWorkspaceItem(item.id, item.name);
          })) || []
        },
        {
          label: "Base",
          options: (base == null ? void 0 : base.map((item) => {
            return renderBaseItem(item);
          })) || []
        }
      ];
      setOptions(newOptions);
    }
  }, [data]);
  const handleSelect = (value, option) => {
    if (option.type === "workspace") {
    } else if (option.type === "base") {
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.AutoComplete,
    {
      popupMatchSelectWidth: 400,
      style: { width: 240 },
      options,
      onSearch: handleSearch,
      onSelect: handleSelect
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.Input,
      {
        prefix: /* @__PURE__ */ import_react.default.createElement(import_icon.SearchLg, { className: "search-icon" }),
        placeholder: "Search",
        size: "large"
      }
    )
  );
};
var SearchWorkspaceAndBase_default = Search;
