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/ecocup/customerList/index.tsx
var customerList_exports = {};
__export(customerList_exports, {
  default: () => CustomerList
});
module.exports = __toCommonJS(customerList_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_hooks = require("../hooks");
var import_locales = __toESM(require("../locales"));
var import_PageHeader = __toESM(require("../components/PageHeader"));
var import_useColumns = require("./hooks/useColumns");
var import_const = require("./const");
var import_CustomerAndCupModal = __toESM(require("../components/CustomerAndCupModal"));
var import_useCustomerApi = require("./hooks/useCustomerApi");
var import_index = require("./index.less");
var prefixCls = "ecocup-customer-list";
var PAGE_SIZE = 20;
function CustomerList(props) {
  const language = (0, import_hooks.useLanguage)();
  const [listParams, setListParams] = (0, import_react.useState)({
    skip: 1,
    num: PAGE_SIZE
  });
  import_utils.locales.init(import_locales.default, language);
  const customerListModal = (0, import_hooks.useModal)("ecocup-customer-list-modal");
  const { loading, data, run } = (0, import_useCustomerApi.useCustomerListsApi)();
  const getLists = (0, import_react.useCallback)((params) => {
    run({
      ...listParams,
      ...params
    });
  }, [listParams]);
  (0, import_react.useEffect)(() => {
    getLists();
  }, [getLists]);
  console.log(data, "whasdf");
  const columns = (0, import_useColumns.useColumns)(import_utils.locales);
  const handleValuesChange = (changedValues, values) => {
    var _a, _b, _c;
    console.log(changedValues, values, "changedValues234");
    const orderByTypes = (_a = values == null ? void 0 : values.order_by) == null ? void 0 : _a.split(":");
    const params = {
      ...(values == null ? void 0 : values.filters) || {},
      order_by: orderByTypes == null ? void 0 : orderByTypes[0],
      sort: orderByTypes == null ? void 0 : orderByTypes[1],
      skip: ((_b = values == null ? void 0 : values.pagination) == null ? void 0 : _b.page) || 1,
      num: ((_c = values == null ? void 0 : values.pagination) == null ? void 0 : _c.size) || PAGE_SIZE
    };
    setListParams((prev) => ({ ...prev, ...params }));
  };
  const { run: handleValuesChangeDebounce } = (0, import_ahooks.useDebounceFn)(
    handleValuesChange,
    {
      wait: 200
    }
  );
  const handleClickRow = (record) => {
    customerListModal.open({
      title: import_utils.locales.getText(
        "pisell2.text.ecocup.customer.list.customer.profile"
      ),
      data: {
        customerData: record,
        firstType: "customer"
      }
    });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-container` }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Table,
    {
      dataSource: (data == null ? void 0 : data.list) || [],
      columns,
      align: "center",
      title: /* @__PURE__ */ import_react.default.createElement(
        import_PageHeader.default,
        {
          title: import_utils.locales.getText("pisell2.text.ecocup.customer.list.title")
        }
      ),
      pagination: {
        pageSize: PAGE_SIZE,
        total: (data == null ? void 0 : data.count) || 0,
        size: "large"
      },
      columnSetting: import_const.COLUMN_SETTING,
      sort: import_const.SORT_SETTINGS,
      filter: (0, import_const.FILTER)(import_utils.locales),
      loading,
      onValuesChange: handleValuesChangeDebounce,
      rowKey: "id",
      virtual: false,
      tableLayout: "",
      scroll: {
        scrollToFirstRowOnChange: true,
        autoCalc: true
      },
      onRow: (record) => {
        return {
          style: {
            cursor: "pointer"
          },
          onClick: () => handleClickRow(record)
        };
      }
    }
  ), customerListModal.visible && /* @__PURE__ */ import_react.default.createElement(import_CustomerAndCupModal.default, { ...customerListModal.modalProps }));
}
