import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { EMPTY_RESERVATION_LIST } from "./usePisellReservationBookingData.js";
import { getFormResourcePage } from "../serve/formResourcePage.js";
import { useCallback, useEffect, useMemo } from "react";
import { useMemoizedFn, useRequest } from "ahooks";
//#region src/plus/pisellReservation/hooks/usePisellReservationResourceTableData.ts
/**
* 预约看板内置表格：GET /shop/form/resource/page，单页 num=999
*/
const RESOURCE_PAGE_NUM = 999;
/** 与 {@link usePisellReservationBookingData} 同形，便于 PisellRecordBoard 无感切换数据源 */
function usePisellReservationResourceTableData(enabled) {
	var _req$data, _req$data$count, _req$data2;
	const req = useRequest(useMemoizedFn(_asyncToGenerator(function* () {
		return getFormResourcePage({ num: RESOURCE_PAGE_NUM });
	})), { manual: true });
	useEffect(() => {
		if (!enabled) return;
		req.run();
	}, [enabled, req.run]);
	const onPageChange = useCallback((pageNumber, pageSize) => {
		/** 当前固定单页大页；翻页如需可在 getFormResourcePage 中传 skip */
	}, []);
	const onSearch = useCallback((_params) => {
		req.refresh();
	}, [req]);
	const onReset = useCallback(() => {
		req.refresh();
	}, [req]);
	const patchSearchParams = useCallback((updater) => {
		req.refresh();
	}, [req]);
	const searchParams = useMemo(() => ({}), []);
	const rawList = (_req$data = req.data) === null || _req$data === void 0 ? void 0 : _req$data.list;
	const data = useMemo(() => {
		if (!Array.isArray(rawList) || rawList.length === 0) return EMPTY_RESERVATION_LIST;
		return rawList;
	}, [rawList]);
	const total = (_req$data$count = (_req$data2 = req.data) === null || _req$data2 === void 0 ? void 0 : _req$data2.count) !== null && _req$data$count !== void 0 ? _req$data$count : 0;
	const pagination = useMemo(() => ({
		pageNumber: 1,
		pageSize: RESOURCE_PAGE_NUM
	}), []);
	return {
		data,
		loading: req.loading,
		total,
		pagination,
		onPageChange,
		searchParams,
		onSearch,
		onReset,
		refresh: req.refresh,
		refreshAsync: req.refreshAsync,
		patchSearchParams
	};
}
//#endregion
export { usePisellReservationResourceTableData };
