const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_index = require("./components/deviceIconGroup/index.js");
const require_index$1 = require("./components/searchSection/index.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 _pisell_icon = require("@pisell/icon");
require("./index.less");
//#region src/pro/comprehensiveSearch/index.tsx
const _excluded = [
	"dataSource",
	"isShowScanner",
	"isShowCamera",
	"isShowNFC",
	"isShowNewButton",
	"newButtonAlign",
	"newButtonText",
	"renderType",
	"containerProps",
	"isShowSearch",
	"isShowSearchCamera",
	"searchIcon",
	"placeholder",
	"isShowSearchButton",
	"resultDisplay",
	"resultSort",
	"style",
	"loading",
	"keyword",
	"onKeywordChange",
	"onSearch",
	"onAdd",
	"onRowClick"
];
const ComprehensiveSearch = (0, react.forwardRef)((_ref, ref) => {
	var _context$appHelper;
	let { 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 } = _ref, props = require_objectWithoutProperties._objectWithoutProperties(_ref, _excluded);
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_locales.default, ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.storage) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.get("umi_locale")) || "en");
	const handleAdd = () => {
		onAdd === null || onAdd === void 0 || onAdd();
	};
	const renderSearchSection = () => {
		if (!isShowSearch) return null;
		return /* @__PURE__ */ react.default.createElement(require_index$1.default, {
			value: keyword,
			onChange: onKeywordChange,
			onSearch,
			loading,
			placeholder
		});
	};
	(0, react.useImperativeHandle)(ref, () => ({}));
	const renderResults = () => {
		if (react.default.isValidElement(resultDisplay)) return resultDisplay;
		if (typeof resultDisplay === "function") {
			const result = resultDisplay(dataSource);
			if (react.default.isValidElement(result)) return result;
			return null;
		}
		if (loading) return /* @__PURE__ */ react.default.createElement(antd.Spin, null, /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__loading" }));
		if (dataSource.length === 0 && props.__designMode !== "design") return /* @__PURE__ */ react.default.createElement(antd.Empty, {
			description: _pisell_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__ */ react.default.createElement("div", {
					key,
					className: "comprehensive-search__result-field"
				}, /* @__PURE__ */ react.default.createElement("span", { className: "comprehensive-search__result-field-value" }, displayValue));
			});
		};
		return /* @__PURE__ */ react.default.createElement("div", { className: `comprehensive-search__results ${resultClass}` }, dataSource.map((result, index) => /* @__PURE__ */ react.default.createElement("div", {
			key: result.id,
			className: "comprehensive-search__result-item"
		}, /* @__PURE__ */ react.default.createElement("div", {
			className: "comprehensive-search__result-fields",
			onClick: () => onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(result, index)
		}, renderAllFields(result)))));
	};
	const getTopRowLayout = () => {
		const newButton = /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "comprehensive-search__new-button",
			onClick: handleAdd,
			type: "primary"
		}, newButtonText || _pisell_utils.locales.getText("pisell2.text.new-client"), /* @__PURE__ */ react.default.createElement(_pisell_icon.PlusCircle, { style: { fontSize: 20 } }));
		const innerProps = {
			isShowCamera,
			isShowNFC,
			isShowScanner
		};
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__third" }, newButtonAlign === "left" ? newButton : newButtonAlign === "right" ? /* @__PURE__ */ react.default.createElement(require_index.default, innerProps) : null), /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__third" }, newButtonAlign === "center" ? newButton : null), /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__third" }, newButtonAlign === "left" ? /* @__PURE__ */ react.default.createElement(require_index.default, innerProps) : newButtonAlign === "right" ? newButton : /* @__PURE__ */ react.default.createElement(require_index.default, innerProps)));
	};
	const renderContent = () => /* @__PURE__ */ react.default.createElement("div", require_objectSpread2._objectSpread2({
		className: "comprehensive-search",
		style
	}, props), /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__top-section" }, /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__top-row" }, getTopRowLayout())), renderSearchSection(), /* @__PURE__ */ react.default.createElement("div", { className: "comprehensive-search__results-container" }, renderResults()));
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellContainer, {
		renderType,
		props: require_objectSpread2._objectSpread2({
			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());
});
//#endregion
exports.default = ComprehensiveSearch;
