/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-a795c5b | Cube Dev Team */
import { useImperativeHandle, useRef } from "react";
import { createDOMRef } from "@react-spectrum/utils";
import { createFocusManager } from "@react-aria/focus";

//#region src/components/fields/DatePicker/utils.ts
function useFocusManagerRef(ref) {
	let domRef = useRef(null);
	useImperativeHandle(ref, () => ({
		...createDOMRef(domRef),
		focus() {
			createFocusManager(domRef).focusFirst({ tabbable: true });
		}
	}));
	return domRef;
}
function formatSegments(segments) {
	segments = JSON.parse(JSON.stringify(segments));
	segments.forEach((segment) => {
		if (segment.type === "literal") {
			if (segment.text === "/") segment.text = "-";
			if (segment.text === ", ") segment.text = " ";
		}
	});
	const year = segments.find((s) => s.type === "year");
	if (year) {
		segments.splice(segments.indexOf(year), 1);
		segments.unshift(year);
	}
	const month = segments.find((s) => s.type === "month");
	if (month) {
		segments.splice(segments.indexOf(month), 1);
		segments.splice(2, 0, month);
	}
	const day = segments.find((s) => s.type === "day");
	if (day) {
		segments.splice(segments.indexOf(day), 1);
		segments.splice(4, 0, day);
	}
	return segments;
}

//#endregion
export { formatSegments, useFocusManagerRef };
//# sourceMappingURL=utils.js.map