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/components/pisellSelectCustomerModal/RightPanel/index.tsx
var RightPanel_exports = {};
__export(RightPanel_exports, {
  default: () => RightPanel_default
});
module.exports = __toCommonJS(RightPanel_exports);
var import_react = __toESM(require("react"));
var import_index = require("./index.less");
var import_classnames = __toESM(require("classnames"));
var import_ahooks = require("ahooks");
var import_serve = require("./serve");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_utils = require("../../../utils");
var import_PlusCircle = __toESM(require("@pisell/icon/es/PlusCircle"));
var import_List = __toESM(require("./List"));
var import_Add = __toESM(require("./Add"));
var import_ChevronLeft = __toESM(require("@pisell/icon/es/ChevronLeft"));
var import_utils2 = require("@pisell/utils");
var defaultParams = {
  skip: 1,
  num: 10,
  sort_by: "id",
  search: ""
};
var RightPanel = (props) => {
  const { value, onChange, phone } = props;
  const [page, setPage] = (0, import_react.useState)("list");
  const context = (0, import_useEngineContext.default)();
  import_utils.request.setRequest(context.appHelper.utils.request);
  const [customerOrigin, setCustomerOrigin] = (0, import_react.useState)({
    skip: 1,
    count: 0,
    list: []
  });
  const [params, setParams] = (0, import_react.useState)(defaultParams);
  const _getCustomerList = (0, import_ahooks.useRequest)(import_serve.getCustomerList, {
    manual: true,
    onSuccess: (res, param) => {
      const _params = param[0];
      setParams(_params);
      let list = [];
      if (_params.skip === 1) {
        list = res.list;
      } else {
        list = customerOrigin.list.concat(res.list);
      }
      setCustomerOrigin({ ...res, list });
    }
  });
  (0, import_react.useEffect)(() => {
    if (page !== "list") {
      return;
    }
    _getCustomerList.run({
      ...defaultParams,
      search: phone
    });
  }, [phone, page]);
  const header = (0, import_react.useMemo)(() => {
    if (page === "list") {
      return /* @__PURE__ */ import_react.default.createElement("div", { className: "select-customer-right-panel-header" }, /* @__PURE__ */ import_react.default.createElement("span", null, phone ? import_utils2.locales.getText("pisell2.text.result-found") : import_utils2.locales.getText("pisell2.text.personnel-list")), /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: "select-customer-right-panel-header-create-btn",
          onClick: () => {
            setPage("create");
          }
        },
        /* @__PURE__ */ import_react.default.createElement(import_PlusCircle.default, { className: "select-customer-right-panel-header-icon" }),
        import_utils2.locales.getText("pisell2.text.create")
      ));
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)("select-customer-right-panel-header", {
          "select-customer-right-panel-header-create": page === "create"
        })
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_ChevronLeft.default,
        {
          className: "select-customer-right-panel-header-icon select-customer-right-panel-header-icon-back",
          onClick: () => {
            setPage("list");
          }
        }
      ),
      import_utils2.locales.getText("pisell2.text.create-new-client")
    );
  }, [phone, page]);
  const addChange = (values) => {
    setPage("list");
    if (values == null ? void 0 : values.is_checked) {
      onChange == null ? void 0 : onChange(values);
    }
    setCustomerOrigin({
      ...customerOrigin,
      count: customerOrigin.count + 1,
      list: [values].concat(customerOrigin.list)
    });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "select-customer-right-panel" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "select-customer-right-panel-header" }, header), page === "list" ? /* @__PURE__ */ import_react.default.createElement(
    import_List.default,
    {
      loading: _getCustomerList.loading,
      phone,
      customerOrigin,
      value,
      onChange,
      onLoadMore: () => {
        if (customerOrigin.list.length >= customerOrigin.count) {
          return;
        }
        _getCustomerList.run({
          ...params,
          skip: params.skip + 1
        });
      },
      setPage
    }
  ) : null, page === "create" ? /* @__PURE__ */ import_react.default.createElement(import_Add.default, { phone, onChange: addChange }) : null);
};
var RightPanel_default = RightPanel;
