import useLocale from "../../locale/useLocale.js";
import { createVNode, defineComponent } from "vue";
import { PlusOutlined } from "@antdv-next/icons";
//#region components/conversations/hooks/useCreation.tsx
var PrefixKeys = {
	Alt: [
		"altKey",
		"Alt",
		"Alt"
	],
	Ctrl: [
		"ctrlKey",
		"Ctrl",
		"Ctrl"
	],
	Meta: [
		"metaKey",
		"Cmd",
		"Win"
	],
	Shift: [
		"shiftKey",
		"Shift",
		"Shift"
	]
};
var isAppleDevice = /(mac|iphone|ipod|ipad)/i.test(typeof navigator !== "undefined" ? navigator?.platform : "");
var KeyCodeMap = {
	8: "Backspace",
	9: "Tab",
	13: "Enter",
	27: "Esc",
	32: "Space",
	46: "Delete"
};
function getShortcutKeysIcon(key) {
	if (key === "number") return key;
	if (typeof key === "string" && PrefixKeys[key]) return PrefixKeys[key][isAppleDevice ? 1 : 2];
	if (typeof key === "number") {
		if (key >= 65 && key <= 90) return String.fromCharCode(key);
		if (key >= 48 && key <= 57) return String.fromCharCode(key);
		if (KeyCodeMap[key]) return KeyCodeMap[key];
	}
	return "";
}
var CreationLabel = /* @__PURE__ */ defineComponent({
	name: "XConversationsCreationLabel",
	props: {
		shortcutKeysIcon: {
			type: Array,
			default: void 0
		},
		prefixCls: {
			type: String,
			required: true
		}
	},
	setup(props) {
		const [locale] = useLocale("Conversations");
		return () => {
			const showShortcutKeys = !!props.shortcutKeysIcon?.length;
			return createVNode("div", { "class": [props.prefixCls, { [`${props.prefixCls}-shortcut-keys-show`]: showShortcutKeys }] }, [createVNode("span", null, [locale.value.create]), showShortcutKeys && createVNode("span", { "class": `${props.prefixCls}-shortcut-keys` }, [props.shortcutKeysIcon?.map((keyIcon) => createVNode("span", {
				"class": `${props.prefixCls}-shortcut-key`,
				"key": keyIcon
			}, [keyIcon]))])]);
		};
	}
});
function useCreation({ icon, label, align, shortcutKeyInfo, prefixCls }) {
	const shortcutKeysIcon = shortcutKeyInfo?.shortcutKeysIcon;
	const creationConfig = {
		label: createVNode(CreationLabel, {
			"prefixCls": `${prefixCls}-label`,
			"shortcutKeysIcon": shortcutKeysIcon
		}, null),
		icon: createVNode(PlusOutlined, { "class": `${prefixCls}-icon` }, null),
		align: "center"
	};
	if (label) creationConfig.label = typeof label === "function" ? label({
		shortcutKeyInfo,
		components: { CreationLabel: (props) => createVNode(CreationLabel, props, null) }
	}) : label;
	if (icon) creationConfig.icon = typeof icon === "function" ? icon() : icon;
	return [
		creationConfig.icon,
		creationConfig.label,
		align || creationConfig.align
	];
}
//#endregion
export { CreationLabel, useCreation as default, getShortcutKeysIcon };
