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/pro/comprehensiveSearch/index.tsx
var comprehensiveSearch_exports = {};
__export(comprehensiveSearch_exports, {
  default: () => comprehensiveSearch_default
});
module.exports = __toCommonJS(comprehensiveSearch_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_icon = require("@pisell/icon");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_index = require("./index.less");
var import_deviceIconGroup = __toESM(require("./components/deviceIconGroup"));
var import_searchSection = __toESM(require("./components/searchSection"));
var ComprehensiveSearch = (0, import_react.forwardRef)(
  ({
    dataSource = [],
    isShowScanner = true,
    isShowCamera = true,
    isShowNFC = true,
    isShowNewButton = true,
    newButtonAlign = "left",
    newButtonText,
    renderType,
    containerProps = {},
    isShowSearch = true,
    isShowSearchCamera = true,
    searchIcon = "pisell2-search-lg",
    placeholder,
    isShowSearchButton = true,
    resultDisplay = "list",
    resultSort = "asc",
    style,
    loading,
    keyword,
    onKeywordChange,
    onSearch,
    onAdd,
    onRowClick,
    ...props
  }, ref) => {
    var _a, _b, _c;
    const context = (0, import_useEngineContext.default)();
    import_utils.locales.init(
      import_locales.default,
      ((_c = (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.storage) == null ? void 0 : _c.get("umi_locale")) || "en"
    );
    const handleAdd = () => {
      onAdd == null ? void 0 : onAdd();
    };
    const renderSearchSection = () => {
      if (!isShowSearch) return null;
      return /* @__PURE__ */ import_react.default.createElement(
        import_searchSection.default,
        {
          value: keyword,
          onChange: onKeywordChange,
          onSearch,
          loading,
          placeholder
        }
      );
    };
    (0, import_react.useImperativeHandle)(ref, () => ({}));
    const renderResults = () => {
      if (import_react.default.isValidElement(resultDisplay)) {
        return resultDisplay;
      }
      if (typeof resultDisplay === "function") {
        const result = resultDisplay(dataSource);
        if (import_react.default.isValidElement(result)) {
          return result;
        }
        return null;
      }
      if (loading) {
        return /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__loading" }));
      }
      if (dataSource.length === 0 && props.__designMode !== "design") {
        return /* @__PURE__ */ import_react.default.createElement(
          import_antd.Empty,
          {
            description: import_utils.locales.getText("pisell2.comprehensive-search.empty"),
            className: "comprehensive-search__empty"
          }
        );
      }
      const resultClass = resultDisplay === "list" ? "comprehensive-search__results--list" : "comprehensive-search__results--grid";
      const renderAllFields = (result) => {
        return Object.entries(result).map(([key, value]) => {
          if (value == null) return null;
          let displayValue;
          if (Array.isArray(value)) {
            displayValue = value.join(", ");
          } else if (typeof value === "object") {
            displayValue = JSON.stringify(value);
          } else {
            displayValue = String(value);
          }
          return /* @__PURE__ */ import_react.default.createElement("div", { key, className: "comprehensive-search__result-field" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "comprehensive-search__result-field-value" }, displayValue));
        });
      };
      return /* @__PURE__ */ import_react.default.createElement("div", { className: `comprehensive-search__results ${resultClass}` }, dataSource.map((result, index) => /* @__PURE__ */ import_react.default.createElement("div", { key: result.id, className: "comprehensive-search__result-item" }, /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "comprehensive-search__result-fields",
          onClick: () => onRowClick == null ? void 0 : onRowClick(result, index)
        },
        renderAllFields(result)
      ))));
    };
    const getTopRowLayout = () => {
      const newButton = /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          className: "comprehensive-search__new-button",
          onClick: handleAdd,
          type: "primary"
        },
        newButtonText || import_utils.locales.getText("pisell2.text.new-client"),
        /* @__PURE__ */ import_react.default.createElement(import_icon.PlusCircle, { style: { fontSize: 20 } })
      );
      const innerProps = {
        isShowCamera,
        isShowNFC,
        isShowScanner
      };
      return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__third" }, newButtonAlign === "left" ? newButton : newButtonAlign === "right" ? /* @__PURE__ */ import_react.default.createElement(import_deviceIconGroup.default, { ...innerProps }) : null), /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__third" }, newButtonAlign === "center" ? newButton : null), /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__third" }, newButtonAlign === "left" ? /* @__PURE__ */ import_react.default.createElement(import_deviceIconGroup.default, { ...innerProps }) : newButtonAlign === "right" ? newButton : /* @__PURE__ */ import_react.default.createElement(import_deviceIconGroup.default, { ...innerProps })));
    };
    const renderContent = () => /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search", style, ...props }, /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__top-section" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__top-row" }, getTopRowLayout())), renderSearchSection(), /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__results-container" }, renderResults()));
    return /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellContainer,
      {
        renderType,
        props: {
          open: true,
          cancelVisible: false,
          bodyStyle: {
            padding: "0px 24px 24px",
            overflow: "hidden",
            display: "flex",
            flexDirection: "column"
          },
          width: 680,
          onCancel: () => {
          },
          okButtonProps: {},
          onOk: () => {
          },
          footer: null,
          headerDivider: false,
          className: "comprehensive-search-modal",
          ...containerProps
        }
      },
      renderContent()
    );
  }
);
var comprehensiveSearch_default = ComprehensiveSearch;
