//#region src/components/pisellTags/utils.ts
const hexToRgb = (hex) => {
	hex = hex.replace(/^#/, "");
	if (hex.length === 3) hex = hex.split("").map((h) => h + h).join("");
	const intVal = parseInt(hex, 16);
	return {
		r: intVal >> 16 & 255,
		g: intVal >> 8 & 255,
		b: intVal & 255
	};
};
const rgbToHex = (r, g, b) => {
	return "#" + [
		r,
		g,
		b
	].map((x) => {
		const hex = x.toString(16);
		return hex.length === 1 ? "0" + hex : hex;
	}).join("");
};
const parseColor = (color) => {
	if (color.startsWith("#")) return hexToRgb(color);
	else if (color.startsWith("rgb")) {
		const rgba = color.replace(/rgba?\(|\s+|\)/g, "").split(",").map(Number);
		return {
			r: rgba[0],
			g: rgba[1],
			b: rgba[2],
			a: rgba[3] !== void 0 ? rgba[3] : 1
		};
	} else throw new Error("无效的颜色格式");
};
const generateColorShades = (color) => {
	const { r, g, b, a } = parseColor(color);
	const gap = 1 / 700;
	const ratios = {
		50: gap * 50,
		200: gap * 200,
		500: gap * 500,
		600: gap * 600,
		700: gap * 700
	};
	const adjustColorComponent = (component, ratio) => Math.round(component * ratio + 255 * (1 - ratio));
	const shades = {
		"color_50": rgbToHex(adjustColorComponent(r, ratios[50]), adjustColorComponent(g, ratios[50]), adjustColorComponent(b, ratios[50])),
		"color_200": rgbToHex(adjustColorComponent(r, ratios[200]), adjustColorComponent(g, ratios[200]), adjustColorComponent(b, ratios[200])),
		"color_500": rgbToHex(adjustColorComponent(r, ratios[500]), adjustColorComponent(g, ratios[500]), adjustColorComponent(b, ratios[500])),
		"color_600": rgbToHex(adjustColorComponent(r, ratios[600]), adjustColorComponent(g, ratios[600]), adjustColorComponent(b, ratios[600])),
		"color_700": color
	};
	if (a !== void 0) {
		shades["color_50"] = `rgba(${adjustColorComponent(r, ratios[50])}, ${adjustColorComponent(g, ratios[50])}, ${adjustColorComponent(b, ratios[50])}, ${a})`;
		shades["color_200"] = `rgba(${adjustColorComponent(r, ratios[200])}, ${adjustColorComponent(g, ratios[200])}, ${adjustColorComponent(b, ratios[200])}, ${a})`;
		shades["color_500"] = `rgba(${adjustColorComponent(r, ratios[500])}, ${adjustColorComponent(g, ratios[500])}, ${adjustColorComponent(b, ratios[500])}, ${a})`;
		shades["color_600"] = `rgba(${adjustColorComponent(r, ratios[600])}, ${adjustColorComponent(g, ratios[600])}, ${adjustColorComponent(b, ratios[600])}, ${a})`;
	}
	return shades;
};
//#endregion
export { generateColorShades };
