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/components/searchSection/index.tsx
var searchSection_exports = {};
__export(searchSection_exports, {
  default: () => searchSection_default
});
module.exports = __toCommonJS(searchSection_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_ahooks = require("ahooks");
var import_classnames = __toESM(require("classnames"));
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_useNativeScanner = __toESM(require("../../hooks/useNativeScanner"));
var import_locales = __toESM(require("./locales"));
var import_index = require("./index.less");
var SearchSection = (props) => {
  var _a, _b, _c;
  const {
    isShowSearchCamera = true,
    searchIcon = "pisell2-search-lg",
    placeholder,
    isShowSearchButton = true,
    loading = false,
    defaultValue,
    value,
    onChange,
    onSearch,
    style,
    className,
    searchButtonProps = {},
    cameraButtonProps = {
      icons: ["pisell2-camera-01"]
    }
  } = props;
  const { activeNativeScanner, isTerminal } = (0, import_useNativeScanner.default)();
  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 [searchValue, setSearchValue] = (0, import_ahooks.useControllableValue)(props);
  const handleSearch = (0, import_ahooks.useMemoizedFn)(async () => {
    try {
      await (onSearch == null ? void 0 : onSearch(searchValue));
    } catch (e) {
      console.error("Search failed:", e);
    }
  });
  const handleInputChange = (e) => {
    const value2 = e.target.value;
    setSearchValue(value2);
  };
  const handleCameraClick = () => {
    if (isTerminal) {
      activeNativeScanner();
    }
  };
  const searchButton = (0, import_react.useMemo)(() => {
    if (!isShowSearchButton) return null;
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        className: "comprehensive-search__search-button",
        type: "primary",
        onClick: handleSearch,
        loading,
        style: (searchButtonProps == null ? void 0 : searchButtonProps.style) || {}
      },
      import_utils.locales.getText("pisell2.text.search")
    );
  }, [isShowSearchButton, loading]);
  const renderCameraIcons = () => {
    const { icon } = cameraButtonProps;
    if (Array.isArray(icon) && icon.length) {
      return icon.map((item, idx) => {
        let divider = null;
        if (idx > 0) {
          divider = /* @__PURE__ */ import_react.default.createElement("span", { className: "comprehensive-search__camera-activator-icons-divider" });
        }
        return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, divider, /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: item, className: "comprehensive-search__camera-activator-icon" }));
      });
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_materials.Icon,
      {
        type: "pisell2-camera-01",
        className: "comprehensive-search__camera-activator-icon"
      }
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `comprehensive-search__search-section ${className || ""}`,
      style
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "comprehensive-search__search-input-wrapper" }, isShowSearchCamera && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(
          "comprehensive-search__camera-activator",
          {
            disabled: !isTerminal
          }
        ),
        onClick: handleCameraClick
      },
      renderCameraIcons()
    ), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Input,
      {
        value: searchValue,
        onChange: handleInputChange,
        placeholder: placeholder || import_utils.locales.getText("pisell2.comprehensive-search.placeholder"),
        prefix: /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { className: "comprehensive-search__prefix-icon", type: searchIcon }),
        onPressEnter: handleSearch,
        className: "comprehensive-search__search-input",
        allowClear: true
      }
    ), (searchButtonProps == null ? void 0 : searchButtonProps.placement) === "inside" ? searchButton : null),
    (searchButtonProps == null ? void 0 : searchButtonProps.placement) === "outside" || !(searchButtonProps == null ? void 0 : searchButtonProps.placement) ? searchButton : null
  );
};
var searchSection_default = SearchSection;
