"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const WxTable_1 = tslib_1.__importDefault(require("../WxTable"));
const requestWxApi_1 = tslib_1.__importDefault(require("../utils/requestWxApi"));
function WxTableWithApi({ onWxApi, options, deps, enableDateFilter, enableDateRangeFilter, additionalFilter, ...restProps }) {
    const ref = react_1.useRef(null);
    const [from, setFrom] = react_1.useState(null);
    const [until, setUntil] = react_1.useState(null);
    const [date, setDate] = react_1.useState(null);
    react_1.useEffect(() => {
        var _a;
        (_a = ref.current) === null || _a === void 0 ? void 0 : _a.refresh();
    }, [from, until].concat(deps));
    return (react_1.default.createElement(WxTable_1.default, Object.assign({ externalRef: ref }, restProps, { options: options, fetchData: async ({ page, pageSize }) => {
            var _a;
            const data = await requestWxApi_1.default(onWxApi({ page: page + 1, pageSize, from, until, date }));
            return {
                data: data.list,
                totalCount: (_a = data.total) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER,
                page: data.currentPage - 1,
            };
        }, dateFilter: enableDateFilter ? { onChange: setDate } : null, dateRangeFilter: enableDateRangeFilter
            ? {
                onChange: (value) => {
                    setFrom(value[0]);
                    setUntil(value[1]);
                },
            }
            : null, additionalFilter: additionalFilter })));
}
exports.default = WxTableWithApi;
