import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { useLanguage, useModal } from "../hooks.js";
import locales_default from "../locales.js";
import CustomerAndCupModal from "../components/CustomerAndCupModal/index.js";
import CustomPageHeader from "../components/PageHeader/index.js";
import { useColumns } from "./hooks/useColumns.js";
import { COLUMN_SETTING, FILTER, SORT_SETTINGS } from "./const.js";
import { useCustomerListsApi } from "./hooks/useCustomerApi.js";
import React, { useCallback, useEffect, useState } from "react";
import { locales } from "@pisell/utils";
import { Table } from "@pisell/materials";
import { useDebounceFn } from "ahooks";
import "./index.less";
//#region src/components/ecocup/customerList/index.tsx
const prefixCls = "ecocup-customer-list";
const PAGE_SIZE = 20;
function CustomerList(props) {
	const language = useLanguage();
	const [listParams, setListParams] = useState({
		skip: 1,
		num: PAGE_SIZE
	});
	locales.init(locales_default, language);
	const customerListModal = useModal("ecocup-customer-list-modal");
	const { loading, data, run } = useCustomerListsApi();
	const getLists = useCallback((params) => {
		run(_objectSpread2(_objectSpread2({}, listParams), params));
	}, [listParams]);
	useEffect(() => {
		getLists();
	}, [getLists]);
	console.log(data, "whasdf");
	const columns = useColumns(locales);
	/**
	* @description: 值变化回调处理函数
	* @param {any} changedValues
	* @param {any} values
	* @return {*}
	*/
	const handleValuesChange = (changedValues, values) => {
		var _values$order_by, _values$pagination, _values$pagination2;
		console.log(changedValues, values, "changedValues234");
		const orderByTypes = values === null || values === void 0 || (_values$order_by = values.order_by) === null || _values$order_by === void 0 ? void 0 : _values$order_by.split(":");
		const params = _objectSpread2(_objectSpread2({}, (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((prev) => _objectSpread2(_objectSpread2({}, prev), params));
	};
	/**
	* @description: 值变化回调防抖处理函数
	* @return {*}
	*/
	const { run: handleValuesChangeDebounce } = useDebounceFn(handleValuesChange, { wait: 200 });
	const 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: `${prefixCls}-container` }, /* @__PURE__ */ React.createElement(Table, {
		dataSource: (data === null || data === void 0 ? void 0 : data.list) || [],
		columns,
		align: "center",
		title: /* @__PURE__ */ React.createElement(CustomPageHeader, { 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,
		onValuesChange: handleValuesChangeDebounce,
		rowKey: "id",
		virtual: false,
		tableLayout: "",
		scroll: {
			scrollToFirstRowOnChange: true,
			autoCalc: true
		},
		onRow: (record) => {
			return {
				style: { cursor: "pointer" },
				onClick: () => handleClickRow(record)
			};
		}
	}), customerListModal.visible && /* @__PURE__ */ React.createElement(CustomerAndCupModal, customerListModal.modalProps));
}
//#endregion
export { CustomerList as default };
