function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useState, useEffect, useCallback } from 'react';
import { useDebounceFn } from 'ahooks';
import { Table } from '@pisell/materials';
import { locales } from '@pisell/utils';
import { useLanguage, useModal } from "../hooks";
import localeTexts from "../locales";
import PageHeader from "../components/PageHeader";
import { useColumns } from "./hooks/useColumns";
import { SORT_SETTINGS, FILTER, COLUMN_SETTING } from "./const";
import CustomerAndCupModal from "../components/CustomerAndCupModal";
import { useCustomerListsApi } from "./hooks/useCustomerApi";
import "./index.less";
var prefixCls = 'ecocup-customer-list';
var PAGE_SIZE = 20;
export default function CustomerList(props) {
  var language = useLanguage();
  var _useState = useState({
      skip: 1,
      num: PAGE_SIZE
    }),
    _useState2 = _slicedToArray(_useState, 2),
    listParams = _useState2[0],
    setListParams = _useState2[1];
  locales.init(localeTexts, language);
  var customerListModal = useModal('ecocup-customer-list-modal');
  var _useCustomerListsApi = useCustomerListsApi(),
    loading = _useCustomerListsApi.loading,
    data = _useCustomerListsApi.data,
    run = _useCustomerListsApi.run;
  var getLists = useCallback(function (params) {
    run(_objectSpread(_objectSpread({}, listParams), params));
  }, [listParams]);
  useEffect(function () {
    getLists();
  }, [getLists]);
  console.log(data, 'whasdf');
  var columns = useColumns(locales);

  /**
   * @description: 值变化回调处理函数
   * @param {any} changedValues
   * @param {any} values
   * @return {*}
   */
  var handleValuesChange = function handleValuesChange(changedValues, values) {
    var _values$order_by, _values$pagination, _values$pagination2;
    console.log(changedValues, values, 'changedValues234');
    // 分割排序字段
    var orderByTypes = values === null || values === void 0 || (_values$order_by = values.order_by) === null || _values$order_by === void 0 ? void 0 : _values$order_by.split(':');
    var params = _objectSpread(_objectSpread({}, (values === null || values === void 0 ? void 0 : values.filters) || {}), {}, {
      order_by: orderByTypes === null || orderByTypes === void 0 ? void 0 : orderByTypes[0],
      sort: orderByTypes === null || orderByTypes === void 0 ? void 0 : orderByTypes[1],
      skip: (values === null || values === void 0 || (_values$pagination = values.pagination) === null || _values$pagination === void 0 ? void 0 : _values$pagination.page) || 1,
      num: (values === null || values === void 0 || (_values$pagination2 = values.pagination) === null || _values$pagination2 === void 0 ? void 0 : _values$pagination2.size) || PAGE_SIZE
    });
    setListParams(function (prev) {
      return _objectSpread(_objectSpread({}, prev), params);
    });
  };

  /**
   * @description: 值变化回调防抖处理函数
   * @return {*}
   */
  var _useDebounceFn = useDebounceFn(handleValuesChange, {
      wait: 200
    }),
    handleValuesChangeDebounce = _useDebounceFn.run;
  var handleClickRow = function handleClickRow(record) {
    customerListModal.open({
      title: locales.getText('pisell2.text.ecocup.customer.list.customer.profile'),
      data: {
        customerData: record,
        firstType: 'customer'
      }
    });
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-container")
  }, /*#__PURE__*/React.createElement(Table, {
    dataSource: (data === null || data === void 0 ? void 0 : data.list) || [],
    columns: columns,
    align: "center",
    title: /*#__PURE__*/React.createElement(PageHeader, {
      title: locales.getText('pisell2.text.ecocup.customer.list.title')
    }),
    pagination: {
      pageSize: PAGE_SIZE,
      total: (data === null || data === void 0 ? void 0 : data.count) || 0,
      size: 'large'
    },
    columnSetting: COLUMN_SETTING,
    sort: SORT_SETTINGS,
    filter: FILTER(locales),
    loading: loading,
    onValuesChange: handleValuesChangeDebounce,
    rowKey: "id",
    virtual: false,
    tableLayout: "",
    scroll: {
      scrollToFirstRowOnChange: true,
      autoCalc: true
    },
    onRow: function onRow(record) {
      return {
        style: {
          cursor: 'pointer'
        },
        onClick: function onClick() {
          return handleClickRow(record);
        }
      };
    }
  }), customerListModal.visible && /*#__PURE__*/React.createElement(CustomerAndCupModal, customerListModal.modalProps));
}