import { useCallbackRef, useControlled } from "../utils/react.js";

//#region src/table/useTable.ts
const sortOrders = [
	"asc",
	"desc",
	null
];
const defaultSortOrder = sortOrders[0];
function getNextOrder(order) {
	const next = sortOrders.indexOf(order) + 1;
	return sortOrders[next] !== void 0 ? sortOrders[next] : defaultSortOrder;
}
/** Handles controlled/uncontrolled sort of the Table rows. */
function useTable(props) {
	const { defaultSort = {
		key: "",
		order: defaultSortOrder
	}, onSortChange: onSortChangeProp, sort: value } = props;
	const [sort, onChange, { isControlled }] = useControlled({
		defaultValue: defaultSort,
		onChange: onSortChangeProp,
		value
	});
	return {
		isControlled,
		onSortChange: useCallbackRef((key) => {
			onChange({
				key,
				order: sort.key === key ? getNextOrder(sort.order) : defaultSortOrder
			});
		}),
		sort
	};
}

//#endregion
export { useTable as default };
globalThis.__vuiVersion__ = "4.0.0"
//# sourceMappingURL=useTable.js.map