import useXComponentConfig from "../_utils/hooks/use-x-component-config.js";
import { matchExt } from "./utils.js";
import File from "./components/File.js";
import ImageLoading from "./components/ImageLoading.js";
import AudioIcon from "./icons/audio.js";
import VideoIcon from "./icons/video.js";
import style_default from "./style/index.js";
import { computed, createVNode, defineComponent, mergeProps, useAttrs } from "vue";
import { useConfig } from "antdv-next/config-provider/context";
import { Image } from "antdv-next";
import { FileExcelFilled, FileImageFilled, FileMarkdownFilled, FilePdfFilled, FilePptFilled, FileTextFilled, FileWordFilled, FileZipFilled, JavaOutlined, JavaScriptOutlined, PythonOutlined } from "@antdv-next/icons";
//#region components/file-card/FileCard.tsx
var IMAGE_EXT = [
	"png",
	"jpg",
	"jpeg",
	"gif",
	"bmp",
	"webp",
	"svg",
	"jfif"
];
var AUDIO_EXT = [
	"mp3",
	"wav",
	"flac",
	"ape",
	"aac",
	"ogg"
];
var VIDEO_EXT = [
	"mp4",
	"avi",
	"mov",
	"wmv",
	"flv",
	"mkv"
];
var PRESET_FILE_ICONS = [
	{
		icon: createVNode(FileExcelFilled, null, null),
		color: "#22b35e",
		ext: ["xlsx", "xls"],
		key: "excel"
	},
	{
		icon: createVNode(FileImageFilled, null, null),
		color: "#8c8c8c",
		ext: IMAGE_EXT,
		key: "image"
	},
	{
		icon: createVNode(FileMarkdownFilled, null, null),
		color: "#8c8c8c",
		ext: ["md", "mdx"],
		key: "markdown"
	},
	{
		icon: createVNode(FilePdfFilled, null, null),
		color: "#ff4d4f",
		ext: ["pdf"],
		key: "pdf"
	},
	{
		icon: createVNode(FilePptFilled, null, null),
		color: "#ff6e31",
		ext: ["ppt", "pptx"],
		key: "ppt"
	},
	{
		icon: createVNode(FileWordFilled, null, null),
		color: "#1677ff",
		ext: ["doc", "docx"],
		key: "word"
	},
	{
		icon: createVNode(FileZipFilled, null, null),
		color: "#fab714",
		ext: [
			"zip",
			"rar",
			"7z",
			"tar",
			"gz"
		],
		key: "zip"
	},
	{
		icon: createVNode(VideoIcon, null, null),
		color: "#ff4d4f",
		ext: VIDEO_EXT,
		key: "video"
	},
	{
		icon: createVNode(AudioIcon, null, null),
		color: "#ff6e31",
		ext: AUDIO_EXT,
		key: "audio"
	},
	{
		icon: createVNode(JavaOutlined, null, null),
		color: "#1677ff",
		ext: ["java"],
		key: "java"
	},
	{
		icon: createVNode(JavaScriptOutlined, null, null),
		color: "#fab714",
		ext: ["js"],
		key: "javascript"
	},
	{
		icon: createVNode(PythonOutlined, null, null),
		color: "#fab714",
		ext: ["py"],
		key: "python"
	}
];
var DEFAULT_ICON = {
	icon: createVNode(FileTextFilled, null, null),
	color: "#8c8c8c",
	ext: ["default"],
	key: "default"
};
var XFileCard = /* @__PURE__ */ defineComponent({
	name: "AxFileCard",
	inheritAttrs: false,
	props: {
		prefixCls: {
			type: String,
			default: "antd-file-card"
		},
		style: {
			type: [
				String,
				Object,
				Array
			],
			default: void 0
		},
		styles: {
			type: Object,
			default: () => ({})
		},
		class: {
			type: [
				String,
				Array,
				Object
			],
			default: void 0
		},
		classes: {
			type: Object,
			default: () => ({})
		},
		rootClass: {
			type: String,
			default: ""
		},
		name: {
			type: String,
			required: true
		},
		byte: {
			type: Number,
			default: void 0
		},
		size: {
			type: String,
			default: "default"
		},
		description: {
			type: [
				String,
				Number,
				Object,
				Array,
				Function,
				Boolean
			],
			default: void 0
		},
		loading: {
			type: Boolean,
			default: false
		},
		src: {
			type: String,
			default: void 0
		},
		mask: {
			type: [
				String,
				Number,
				Object,
				Array,
				Function,
				Boolean
			],
			default: void 0
		},
		icon: {
			type: [
				String,
				Number,
				Object,
				Array,
				Function
			],
			default: void 0
		},
		type: {
			type: String,
			default: void 0
		},
		imageProps: {
			type: Object,
			default: void 0
		},
		spinProps: {
			type: Object,
			default: void 0
		},
		videoProps: {
			type: Object,
			default: void 0
		},
		audioProps: {
			type: Object,
			default: void 0
		},
		onClick: {
			type: Function,
			default: void 0
		}
	},
	setup(props, { slots }) {
		const attrs = useAttrs();
		const configCtx = useConfig();
		const contextConfig = useXComponentConfig("fileCard");
		const [hashId, cssVarCls] = style_default(computed(() => props.prefixCls));
		const domAttrs = computed(() => {
			const { class: _class, style: _style, ...rest } = attrs;
			return rest;
		});
		const namePair = computed(() => {
			const nameString = props.name || "";
			const match = nameString.match(/^(.*)\.[^.]+$/);
			if (!match) return [nameString, ""];
			return [match[1] ?? "", nameString.slice((match[1] ?? "").length)];
		});
		const iconInfo = computed(() => {
			if (typeof props.icon === "string") {
				const preset = PRESET_FILE_ICONS.find((item) => item.key === props.icon);
				if (preset) return {
					icon: preset.icon,
					color: preset.color
				};
			}
			for (const item of PRESET_FILE_ICONS) if (matchExt(namePair.value[1], item.ext)) return {
				icon: item.icon,
				color: item.color
			};
			return {
				icon: DEFAULT_ICON.icon,
				color: DEFAULT_ICON.color
			};
		});
		const fileType = computed(() => {
			if (props.type) return props.type;
			if (matchExt(namePair.value[1], IMAGE_EXT)) return "image";
			if (matchExt(namePair.value[1], AUDIO_EXT)) return "audio";
			if (matchExt(namePair.value[1], VIDEO_EXT)) return "video";
			return "file";
		});
		const mergedClasses = computed(() => ({
			...contextConfig.value.classes,
			...props.classes
		}));
		const mergedStyles = computed(() => ({
			...contextConfig.value.styles,
			...props.styles
		}));
		const renderContent = () => {
			if (fileType.value === "image") return createVNode("div", {
				"class": [
					`${props.prefixCls}-image`,
					mergedClasses.value.file,
					{ [`${props.prefixCls}-loading`]: props.loading }
				],
				"style": mergedStyles.value.file
			}, [createVNode(Image, mergeProps({
				"rootClass": `${props.prefixCls}-image-img`,
				"width": mergedStyles.value.file?.width,
				"height": mergedStyles.value.file?.height,
				"alt": props.name,
				"src": props.src
			}, props.imageProps), null), props.loading ? createVNode(ImageLoading, {
				"spinProps": props.spinProps,
				"prefixCls": props.prefixCls,
				"style": mergedStyles.value.file
			}, null) : null]);
			if (fileType.value === "video") return createVNode("video", mergeProps({
				"src": props.src,
				"controls": true,
				"style": mergedStyles.value.file,
				"class": [`${props.prefixCls}-video`, mergedClasses.value.file]
			}, props.videoProps), null);
			if (fileType.value === "audio") return createVNode("audio", mergeProps({
				"src": props.src,
				"controls": true,
				"style": mergedStyles.value.file,
				"class": [`${props.prefixCls}-audio`, mergedClasses.value.file]
			}, props.audioProps), null);
			return createVNode(File, {
				"prefixCls": props.prefixCls,
				"namePrefix": namePair.value[0],
				"name": props.name,
				"type": fileType.value,
				"src": props.src,
				"ext": namePair.value[1],
				"size": props.size,
				"byte": props.byte,
				"description": props.description,
				"icon": props.icon && typeof props.icon !== "string" ? props.icon : iconInfo.value.icon,
				"iconColor": iconInfo.value.color,
				"onClick": props.onClick,
				"mask": props.mask,
				"descriptionRenderSlot": slots.description,
				"maskRenderSlot": slots.mask,
				"iconSlot": slots.icon,
				"classes": mergedClasses.value,
				"styles": mergedStyles.value
			}, null);
		};
		return () => createVNode("div", mergeProps(domAttrs.value, {
			"class": [
				props.prefixCls,
				contextConfig.value.classes?.root,
				props.rootClass,
				props.classes?.root,
				hashId.value,
				cssVarCls.value,
				attrs.class,
				props.class,
				{ [`${props.prefixCls}-rtl`]: configCtx.value.direction === "rtl" }
			],
			"style": [
				contextConfig.value.style,
				contextConfig.value.styles?.root,
				props.styles.root,
				attrs.style,
				props.style
			]
		}), [renderContent()]);
	}
});
//#endregion
export { XFileCard, XFileCard as default };
