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_useLocale = require("../../../../hooks/useLocale.js");
const require_useNativeScanner = require("../../hooks/useNativeScanner.js");
const require_locales = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
require("./index.less");
//#region src/pro/comprehensiveSearch/components/searchSection/index.tsx
const SearchSection = (props) => {
	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 } = require_useNativeScanner.default();
	require_useEngineContext.default();
	const locale = require_useLocale.default();
	_pisell_utils.locales.init(require_locales.default, locale || "en");
	const [searchValue, setSearchValue] = (0, ahooks.useControllableValue)(props);
	const handleSearch = (0, ahooks.useMemoizedFn)(require_asyncToGenerator._asyncToGenerator(function* () {
		try {
			yield onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchValue);
		} catch (e) {
			console.error("Search failed:", e);
		}
	}));
	const handleInputChange = (e) => {
		const value = e.target.value;
		setSearchValue(value);
	};
	const handleCameraClick = () => {
		if (isTerminal) activeNativeScanner();
	};
	const searchButton = (0, react.useMemo)(() => {
		if (!isShowSearchButton) return null;
		return /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "comprehensive-search__search-button",
			type: "primary",
			onClick: handleSearch,
			loading,
			style: (searchButtonProps === null || searchButtonProps === void 0 ? void 0 : searchButtonProps.style) || {}
		}, _pisell_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__ */ react.default.createElement("span", { className: "comprehensive-search__camera-activator-icons-divider" });
			return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, divider, /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
				type: item,
				className: "comprehensive-search__camera-activator-icon"
			}));
		});
		return /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
			type: "pisell2-camera-01",
			className: "comprehensive-search__camera-activator-icon"
		});
	};
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `comprehensive-search__search-section ${className || ""}`,
		style
	}, /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__search-input-wrapper" }, isShowSearchCamera && /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("comprehensive-search__camera-activator", { disabled: !isTerminal }),
		onClick: handleCameraClick
	}, renderCameraIcons()), /* @__PURE__ */ react.default.createElement(antd.Input, {
		value: searchValue,
		onChange: handleInputChange,
		placeholder: placeholder || _pisell_utils.locales.getText("pisell2.comprehensive-search.placeholder"),
		prefix: /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
			className: "comprehensive-search__prefix-icon",
			type: searchIcon
		}),
		onPressEnter: handleSearch,
		className: "comprehensive-search__search-input",
		allowClear: true
	}), (searchButtonProps === null || searchButtonProps === void 0 ? void 0 : searchButtonProps.placement) === "inside" ? searchButton : null), (searchButtonProps === null || searchButtonProps === void 0 ? void 0 : searchButtonProps.placement) === "outside" || !(searchButtonProps === null || searchButtonProps === void 0 ? void 0 : searchButtonProps.placement) ? searchButton : null);
};
//#endregion
exports.default = SearchSection;
