/** @license MIT | @cube-dev/ui-kit v0.142.7 | Cube Dev Team */
import { useCallback, useState } from "react";

//#region src/components/navigation/Tabs/use-tab-editing.ts
/**
* Hook to manage tab title editing state.
*
* Provides state and callbacks for inline title editing with support for:
* - Starting edit mode (selecting the tab)
* - Submitting changes (with tab-level or parent-level callback)
* - Canceling edits
*
* The draft value is managed inside `InlineInput`; this hook only tracks
* which tab (if any) is currently editing.
*/
function useTabEditing({ onChange, onTitleChange } = {}) {
	const [editingKey, setEditingKey] = useState(null);
	return {
		editingKey,
		startEditing: useCallback((key) => {
			onChange?.(key);
			setEditingKey(key);
		}, [onChange]),
		cancelEditing: useCallback(() => {
			setEditingKey(null);
		}, []),
		submitEditing: useCallback((key, newTitle, tabOnTitleChange) => {
			const trimmed = newTitle.trim();
			if (trimmed) {
				if (tabOnTitleChange) tabOnTitleChange(trimmed);
				else if (onTitleChange) onTitleChange(key, trimmed);
			}
			setEditingKey(null);
		}, [onTitleChange])
	};
}

//#endregion
export { useTabEditing };
//# sourceMappingURL=use-tab-editing.js.map