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/ResultList/index.tsx
var ResultList_exports = {};
__export(ResultList_exports, {
  default: () => ResultList_default
});
module.exports = __toCommonJS(ResultList_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_dayjs = __toESM(require("dayjs"));
var import_InfiniteScroll = __toESM(require("../InfiniteScroll"));
var import_clientName = __toESM(require("../../clientName"));
var import_index = require("./index.less");
var ResultListTag = import_antd.Tag;
var ResultList = (0, import_react.forwardRef)(
  ({
    dataSource,
    hasMore,
    loading,
    holderTitle,
    onLoadMore,
    onRowClick,
    translateText
  }, ref) => {
    const scrollContainerRef = (0, import_react.useRef)(null);
    const scrollContainerIdRef = (0, import_react.useRef)(
      `client-search-result-list-scroll-${Math.random().toString(36).slice(2)}`
    );
    (0, import_react.useImperativeHandle)(ref, () => ({
      resetScrollPosition: () => {
        if (scrollContainerRef.current) {
          scrollContainerRef.current.scrollTop = 0;
          scrollContainerRef.current.scrollLeft = 0;
        }
      }
    }));
    const renderHeader = () => {
      if (!(dataSource == null ? void 0 : dataSource.length)) return null;
      return /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__header" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--name" }, import_utils.locales.getText("pisell2.text.client-search.name")), /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--register-time" }, import_utils.locales.getText("pisell2.text.client-search.register-time")), /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--membership" }, import_utils.locales.getText("pisell2.text.client-search.membership")), /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--contact-info" }, import_utils.locales.getText("pisell2.text.client-search.contact-info")), /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--holder" }, holderTitle || import_utils.locales.getText("pisell2.text.client-search.holder")));
    };
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        ref: scrollContainerRef,
        id: scrollContainerIdRef.current,
        className: "client-search-result-list"
      },
      loading && /* @__PURE__ */ import_react.default.createElement(
        import_antd.Spin,
        {
          spinning: loading || false,
          className: "pisell-client-search-result-loading",
          size: "large"
        }
      ),
      renderHeader(),
      /* @__PURE__ */ import_react.default.createElement(
        import_InfiniteScroll.default,
        {
          dataLength: dataSource.length,
          next: () => onLoadMore == null ? void 0 : onLoadMore(),
          hasMore: hasMore || false,
          className: "client-search-result-list__infinite",
          loader: /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__message" }, import_utils.locales.getText("pisell2.text.loading")),
          endMessage: /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__message" }, (dataSource == null ? void 0 : dataSource.length) ? import_utils.locales.getText("pisell2.text.no-more-data") : null),
          scrollableTarget: scrollContainerIdRef.current,
          scrollThreshold: "180px"
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.List,
          {
            className: "client-search-result-list__list",
            dataSource,
            renderItem: (item, index) => {
              var _a, _b, _c, _d, _e, _f, _g, _h, _i;
              const membershipText = (_b = (_a = item.latest_wallet_detail) == null ? void 0 : _a.wallet) == null ? void 0 : _b.name;
              const translatedMembershipText = translateText == null ? void 0 : translateText(membershipText);
              return /* @__PURE__ */ import_react.default.createElement(
                import_antd.List.Item,
                {
                  key: item.id,
                  className: "client-search-result-list__item"
                },
                /* @__PURE__ */ import_react.default.createElement(
                  "div",
                  {
                    className: "client-search-result-list__item-content",
                    onClick: () => onRowClick == null ? void 0 : onRowClick(item, index || 0)
                  },
                  /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--name" }, /* @__PURE__ */ import_react.default.createElement(import_clientName.default, { dataSource: item }), /* @__PURE__ */ import_react.default.createElement("div", null, item.phone || "-"), /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__ellipsis" }, item.email || "-")),
                  /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--register-time" }, (0, import_dayjs.default)(item.created_at).format("YYYY-MM-DD") || "-"),
                  /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--membership" }, membershipText && translatedMembershipText ? /* @__PURE__ */ import_react.default.createElement(
                    ResultListTag,
                    {
                      color: "gold",
                      className: "client-search-result-list__membership-tag"
                    },
                    translatedMembershipText
                  ) : "-"),
                  /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--contact-info" }, /* @__PURE__ */ import_react.default.createElement(import_clientName.default, { dataSource: (_c = item == null ? void 0 : item.contacts_info) == null ? void 0 : _c.value }), /* @__PURE__ */ import_react.default.createElement("div", null, ((_f = (_e = (_d = item == null ? void 0 : item.contacts_info) == null ? void 0 : _d.value) == null ? void 0 : _e.phone) == null ? void 0 : _f.phone) || "-"), /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__ellipsis" }, ((_h = (_g = item == null ? void 0 : item.contacts_info) == null ? void 0 : _g.value) == null ? void 0 : _h.email) || "-")),
                  /* @__PURE__ */ import_react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--holder" }, ((_i = item == null ? void 0 : item.form_record) == null ? void 0 : _i.length) > 0 ? item.form_record.map((itemForm) => {
                    return /* @__PURE__ */ import_react.default.createElement(
                      "div",
                      {
                        key: itemForm == null ? void 0 : itemForm.id,
                        className: "client-search-result-list__ellipsis"
                      },
                      (itemForm == null ? void 0 : itemForm.main_field) || "-"
                    );
                  }) : "-")
                )
              );
            }
          }
        )
      )
    );
  }
);
var ResultList_default = ResultList;
