require("../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_usePisellReservationBookingData = require("./usePisellReservationBookingData.js");
const require_formResourcePage = require("../serve/formResourcePage.js");
let react = require("react");
let ahooks = require("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 = (0, ahooks.useRequest)((0, ahooks.useMemoizedFn)(require_asyncToGenerator._asyncToGenerator(function* () {
		return require_formResourcePage.getFormResourcePage({ num: RESOURCE_PAGE_NUM });
	})), { manual: true });
	(0, react.useEffect)(() => {
		if (!enabled) return;
		req.run();
	}, [enabled, req.run]);
	const onPageChange = (0, react.useCallback)((pageNumber, pageSize) => {
		/** 当前固定单页大页；翻页如需可在 getFormResourcePage 中传 skip */
	}, []);
	const onSearch = (0, react.useCallback)((_params) => {
		req.refresh();
	}, [req]);
	const onReset = (0, react.useCallback)(() => {
		req.refresh();
	}, [req]);
	const patchSearchParams = (0, react.useCallback)((updater) => {
		req.refresh();
	}, [req]);
	const searchParams = (0, react.useMemo)(() => ({}), []);
	const rawList = (_req$data = req.data) === null || _req$data === void 0 ? void 0 : _req$data.list;
	const data = (0, react.useMemo)(() => {
		if (!Array.isArray(rawList) || rawList.length === 0) return require_usePisellReservationBookingData.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 = (0, react.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
exports.usePisellReservationResourceTableData = usePisellReservationResourceTableData;
