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_useTranslationOriginal = require("../../hooks/useTranslationOriginal.js");
const require_index = require("../../pro/comprehensiveSearch/index.js");
const require_index$1 = require("./Add/index.js");
const require_index$2 = require("./ResultList/index.js");
const require_locales = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/plus/clinetSearch/index.tsx
const _excluded = [
	"onRowClick",
	"resultProps",
	"onAddClient",
	"hasMore",
	"onLoadMore",
	"state",
	"resultLoading"
];
const ClientSearch = (0, react.forwardRef)((_ref, ref) => {
	var _context$appHelper, _state$bookingConfig, _context$appHelper2;
	let { onRowClick, resultProps, onAddClient, hasMore, onLoadMore, state, resultLoading } = _ref, props = require_objectWithoutProperties._objectWithoutProperties(_ref, _excluded);
	const [modalVisible, setModalVisible] = (0, react.useState)(false);
	const comprehensiveSearchRef = (0, react.useRef)(null);
	const addClientRef = (0, react.useRef)(null);
	const resultListRef = (0, react.useRef)(null);
	const translationOriginal = require_useTranslationOriginal.default();
	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 appointmentSubject = (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.basic) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_subject) || {};
	const translation = context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.translationShop;
	const handleAdd = () => {
		setModalVisible(true);
	};
	const handleModalCancel = () => {
		var _addClientRef$current;
		setModalVisible(false);
		(_addClientRef$current = addClientRef.current) === null || _addClientRef$current === void 0 || _addClientRef$current.reset();
	};
	const renderResults = (searchResults) => {
		return /* @__PURE__ */ react.default.createElement(require_index$2.default, {
			ref: resultListRef,
			dataSource: searchResults,
			hasMore,
			loading: resultLoading,
			holderTitle: (translation === null || translation === void 0 ? void 0 : translation(appointmentSubject === null || appointmentSubject === void 0 ? void 0 : appointmentSubject.form_name)) || _pisell_utils.locales.getText("pisell2.text.client-search.holder"),
			onLoadMore,
			onRowClick,
			translateText: translationOriginal
		});
	};
	const handleAddClient = (record, isChecked) => {
		onAddClient === null || onAddClient === void 0 || onAddClient(record, isChecked);
		handleModalCancel();
	};
	(0, react.useImperativeHandle)(ref, () => ({ resetScrollPosition: () => {
		var _resultListRef$curren;
		(_resultListRef$curren = resultListRef.current) === null || _resultListRef$curren === void 0 || _resultListRef$curren.resetScrollPosition();
	} }));
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
		ref: comprehensiveSearchRef,
		renderType: "modal",
		onAdd: handleAdd,
		resultDisplay: renderResults
	})), /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		containerProps: {
			className: "pisell-client-search__new-client-modal",
			title: _pisell_utils.locales.getText("pisell2.text.create-new-client"),
			open: modalVisible,
			onCancel: handleModalCancel,
			width: 680
		},
		onChange: handleAddClient,
		ref: addClientRef
	}));
});
//#endregion
exports.default = ClientSearch;
