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/plus/clinetSearch/index.tsx
var clinetSearch_exports = {};
__export(clinetSearch_exports, {
  default: () => clinetSearch_default
});
module.exports = __toCommonJS(clinetSearch_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_comprehensiveSearch = __toESM(require("../../pro/comprehensiveSearch"));
var import_Add = __toESM(require("./Add"));
var import_ResultList = __toESM(require("./ResultList"));
var import_locales = __toESM(require("./locales"));
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_useTranslationOriginal = __toESM(require("../../hooks/useTranslationOriginal"));
var import_index = require("./index.less");
var ClientSearch = (0, import_react.forwardRef)(
  ({
    onRowClick,
    resultProps,
    onAddClient,
    hasMore,
    onLoadMore,
    state,
    resultLoading,
    ...props
  }, ref) => {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    const [modalVisible, setModalVisible] = (0, import_react.useState)(false);
    const comprehensiveSearchRef = (0, import_react.useRef)(null);
    const addClientRef = (0, import_react.useRef)(null);
    const resultListRef = (0, import_react.useRef)(null);
    const translationOriginal = (0, import_useTranslationOriginal.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 appointmentSubject = ((_f = (_e = (_d = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _d.config) == null ? void 0 : _e.basic) == null ? void 0 : _f.appointment_subject) || {};
    const translation = (_h = (_g = context == null ? void 0 : context.appHelper) == null ? void 0 : _g.utils) == null ? void 0 : _h.translationShop;
    const handleAdd = () => {
      setModalVisible(true);
    };
    const handleModalCancel = () => {
      var _a2;
      setModalVisible(false);
      (_a2 = addClientRef.current) == null ? void 0 : _a2.reset();
    };
    const renderResults = (searchResults) => {
      return /* @__PURE__ */ import_react.default.createElement(
        import_ResultList.default,
        {
          ref: resultListRef,
          dataSource: searchResults,
          hasMore,
          loading: resultLoading,
          holderTitle: (translation == null ? void 0 : translation(appointmentSubject == null ? void 0 : appointmentSubject.form_name)) || import_utils.locales.getText("pisell2.text.client-search.holder"),
          onLoadMore,
          onRowClick,
          translateText: translationOriginal
        }
      );
    };
    const handleAddClient = (record, isChecked) => {
      onAddClient == null ? void 0 : onAddClient(record, isChecked);
      handleModalCancel();
    };
    (0, import_react.useImperativeHandle)(ref, () => ({
      resetScrollPosition: () => {
        var _a2;
        (_a2 = resultListRef.current) == null ? void 0 : _a2.resetScrollPosition();
      }
    }));
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      import_comprehensiveSearch.default,
      {
        ...props,
        ref: comprehensiveSearchRef,
        renderType: "modal",
        onAdd: handleAdd,
        resultDisplay: renderResults
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_Add.default,
      {
        containerProps: {
          className: "pisell-client-search__new-client-modal",
          title: import_utils.locales.getText("pisell2.text.create-new-client"),
          open: modalVisible,
          onCancel: handleModalCancel,
          width: 680
        },
        onChange: handleAddClient,
        ref: addClientRef
      }
    ));
  }
);
var clinetSearch_default = ClientSearch;
