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/saleDetail/components/Client/index.tsx
var Client_exports = {};
__export(Client_exports, {
  Client: () => Client
});
module.exports = __toCommonJS(Client_exports);
var import_ahooks = require("ahooks");
var import_react = __toESM(require("react"));
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_responsive = require("../../../../responsive");
var import_ClientSelector = require("./ClientSelector");
var import_index = require("./index.less");
function ClientBase({
  context: clientContext,
  className,
  isShowAvatar,
  readOnly = false,
  variant
}) {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  const customerState = clientContext.customer;
  const selectedCustomer = customerState.selected;
  const translationOriginal = (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.translationOriginal;
  const clientCardProps = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    const walletName = (_b2 = (_a2 = selectedCustomer == null ? void 0 : selectedCustomer.latest_wallet_detail) == null ? void 0 : _a2.wallet) == null ? void 0 : _b2.name;
    if (!walletName) return void 0;
    return {
      tags: [
        {
          children: (translationOriginal == null ? void 0 : translationOriginal(walletName)) || walletName,
          color: "gold"
        }
      ],
      tag: {
        placement: "inline"
      }
    };
  }, [selectedCustomer, translationOriginal]);
  const handleSelectClient = (0, import_ahooks.useMemoizedFn)(
    (record) => {
      customerState.select(record);
    }
  );
  const handleContactsInfoChange = (0, import_ahooks.useMemoizedFn)(
    (contactsInfo) => {
      clientContext.sales.setContactsInfo(contactsInfo);
    }
  );
  const handleOpenCustomerDetail = (0, import_ahooks.useMemoizedFn)(
    (record, onSuccess) => {
      var _a2, _b2;
      const action = (_b2 = (_a2 = context.appHelper) == null ? void 0 : _a2.utils) == null ? void 0 : _b2.action;
      if (!action || !(record == null ? void 0 : record.id)) return;
      action({
        type: "pisell1.handleOpenCustomerModal",
        data: { id: record.id },
        callback: onSuccess
      });
    }
  );
  return /* @__PURE__ */ import_react.default.createElement(
    import_ClientSelector.ClientSelector,
    {
      className,
      value: selectedCustomer,
      list: customerState.list,
      loading: customerState.loading,
      loadingMore: customerState.loadingMore,
      hasMore: customerState.hasMore,
      pagination: customerState.pagination,
      isShowAvatar,
      variant,
      readOnly,
      clientCardProps,
      onSearch: customerState.search,
      onLoadMore: customerState.loadMore,
      onChangePage: customerState.changePage,
      onSelect: handleSelectClient,
      onAddToFirst: (record) => {
        customerState.addToFirst(record);
      },
      resolveContactsInfo: (record) => {
        var _a2;
        return ((_a2 = record == null ? void 0 : record.contacts_info) == null ? void 0 : _a2.value) || null;
      },
      onContactsInfoChange: handleContactsInfoChange,
      onOpenCustomerDetail: handleOpenCustomerDetail
    }
  );
}
ClientBase.displayName = "Client";
var Client = (0, import_responsive.withResponsive)(ClientBase);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Client
});
