import CommandPaletteExample_default from "../components/CommandPaletteExample.vue.js";
import CommandPaletteImport_default from "../components/CommandPaletteImport.vue.js";
import CommandPaletteImportCurl_default from "../components/CommandPaletteImportCurl.vue.js";
import CommandPaletteImportPostman_default from "../components/CommandPaletteImportPostman.vue.js";
import CommandPaletteOpenApiDocument_default from "../components/CommandPaletteOpenApiDocument.vue.js";
import CommandPaletteRequest_default from "../components/CommandPaletteRequest.vue.js";
import CommandPaletteTag_default from "../components/CommandPaletteTag.vue.js";
import { computed, ref, shallowRef, toValue } from "vue";
import { useModal } from "@scalar/components";
import { ScalarIconArrowSquareIn, ScalarIconArrowUpRight, ScalarIconBracketsCurly, ScalarIconCookie, ScalarIconFolder, ScalarIconPackage, ScalarIconPuzzlePiece, ScalarIconSlidersHorizontal } from "@scalar/icons";
import Fuse from "fuse.js";
//#region src/v2/features/command-palette/hooks/use-command-palette-state.ts
/**
* Composable for managing command palette state.
*
* Centralizes all state management for the command palette including:
* - Open/closed state
* - Filter/search query
* - Command filtering logic
*
* @example
* const palette = useCommandPaletteState()
*
* // Open the palette
* palette.open()
*
* // Open with a specific command
* palette.open('create-openapi-document')
*
* // Open with command props
* palette.open('import-curl-command', { inputValue: 'curl https://api.example.com' })
*
* // Update filter query (automatically filters commands)
* palette.setFilterQuery('import')
*
* // Access filtered results
* console.log(palette.filteredCommands.value)
*
* // Close and reset
* palette.close()
*/
var useCommandPaletteState = (actions = baseClientActions, routes = baseRoutes) => {
	const modalState = useModal();
	const filterQuery = ref("");
	const activeCommand = shallowRef(null);
	const activeCommandProps = ref(null);
	/** Whether the command palette is currently open */
	const isOpen = computed(() => modalState.open);
	const fuseActions = computed(() => new Fuse(toValue(actions), {
		keys: ["name"],
		threshold: .2
	}));
	const fuseRoutes = computed(() => new Fuse(toValue(routes), {
		keys: ["name"],
		threshold: .2
	}));
	/**
	* Filtered commands based on the current search query.
	* When no query is present, returns all visible commands (excluding hidden-folder).
	* When a query exists, filters commands by name (case-insensitive) and excludes hidden-folder.
	* Empty groups are excluded from the results.
	*/
	const filteredActions = computed(() => {
		const query = filterQuery.value.toLowerCase().trim();
		return (query ? fuseActions.value.search(query).map((a) => a.item) : toValue(actions)).filter((a) => !a.hidden);
	});
	const filteredRoutes = computed(() => {
		const query = filterQuery.value.toLowerCase().trim();
		return query ? fuseRoutes.value.search(query).map((a) => a.item) : toValue(routes);
	});
	/**
	* Opens the command palette, optionally with a specific command active.
	* If a commandId is provided, that command will be opened immediately.
	* Props are type-safe and checked against the command's expected props.
	*/
	const open = (commandId, ...args) => {
		if (commandId) {
			activeCommand.value = toValue(actions).find((a) => a.id === commandId) ?? null;
			activeCommandProps.value = args[0] ?? null;
		}
		modalState.show();
	};
	/** Closes the command palette and resets all state */
	const close = () => {
		modalState.hide();
		reset();
	};
	/** Updates the filter query for searching commands */
	const setFilterQuery = (query) => {
		filterQuery.value = query;
	};
	/** Resets all internal state to initial values */
	const reset = () => {
		filterQuery.value = "";
		activeCommand.value = null;
		activeCommandProps.value = null;
	};
	return {
		isOpen,
		activeCommand,
		activeCommandProps,
		filterQuery,
		filteredCommands: computed(() => [{
			label: "",
			commands: filteredActions.value
		}, {
			label: "Pages",
			commands: filteredRoutes.value
		}]),
		open,
		close,
		setFilterQuery,
		reset
	};
};
/**
* The base naviation routes used in the command palette.
* This object can be extended and passed to the useCommandPaletteState hook to add custom routes
*/
var baseRoutes = [
	{
		type: "route",
		id: "environment",
		name: "Environment",
		icon: ScalarIconBracketsCurly,
		to: { name: "workspace.environment" }
	},
	{
		type: "route",
		id: "cookies",
		name: "Cookies",
		icon: ScalarIconCookie,
		to: { name: "workspace.cookies" }
	},
	{
		type: "route",
		id: "settings",
		name: "Settings",
		icon: ScalarIconSlidersHorizontal,
		to: { name: "workspace.settings" }
	}
];
/**
* The internal client command palette actions
* This object can be extended and passed to the useCommandPaletteState hook to add custom actions
*/
var baseClientActions = [
	{
		id: "import-from-openapi-swagger-postman-curl",
		name: "Import from OpenAPI/Swagger/cURL",
		component: CommandPaletteImport_default,
		icon: ScalarIconArrowSquareIn
	},
	{
		id: "import-postman-collection",
		name: "Import Postman Collection",
		component: CommandPaletteImportPostman_default,
		icon: ScalarIconArrowSquareIn,
		hidden: true
	},
	{
		id: "create-openapi-document",
		name: "Create OpenAPI Document",
		component: CommandPaletteOpenApiDocument_default,
		icon: ScalarIconPackage
	},
	{
		id: "add-tag",
		name: "Add Tag",
		component: CommandPaletteTag_default,
		icon: ScalarIconFolder
	},
	{
		id: "create-request",
		name: "Create Request",
		component: CommandPaletteRequest_default,
		icon: ScalarIconArrowUpRight
	},
	{
		id: "add-example",
		name: "Add Example",
		component: CommandPaletteExample_default,
		icon: ScalarIconPuzzlePiece
	},
	{
		id: "import-curl-command",
		name: "Import cURL Command",
		hidden: true,
		component: CommandPaletteImportCurl_default
	},
	{
		id: "edit-tag",
		name: "Edit Tag",
		hidden: true,
		component: CommandPaletteTag_default
	},
	{
		id: "edit-example",
		name: "Edit Example",
		hidden: true,
		component: CommandPaletteExample_default
	}
];
//#endregion
export { baseClientActions, baseRoutes, useCommandPaletteState };

//# sourceMappingURL=use-command-palette-state.js.map