//#region src/plus/pisellSalesProductCard/utils.ts
/**
* @title: 贝塞尔曲线
* @description:
* @param {CardAnimaProps} param1
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2023-04-03 15:25
*/
const cubicBezier = ({ position, cartElementId }) => {
	const left = position.x;
	const top = position.y;
	const collect = cartElementId.startsWith("#") ? document.querySelector(cartElementId) : document.getElementById(cartElementId) || document.querySelector(cartElementId);
	const duration = top > 400 ? ".4s" : ".6s";
	const ball = document.createElement("div");
	ball.style.position = "fixed";
	ball.style.left = left - 10 + "px";
	ball.style.top = top - 10 + "px";
	ball.style.width = "20px";
	ball.style.height = "20px";
	ball.style.borderRadius = "50%";
	ball.style.backgroundColor = "var(--theme-color)";
	ball.style.zIndex = "9999";
	ball.style.transition = `left ${duration} linear, top ${duration} cubic-bezier(0.5, -0.5, 1, 1)`;
	ball.innerHTML = "+";
	ball.style.color = "#ffffff";
	ball.style.textAlign = "center";
	ball.style.lineHeight = "20px";
	if (collect) {
		document.body.appendChild(ball);
		setTimeout(() => {
			ball.style.left = collect.offsetLeft + collect.offsetWidth / 2 + "px";
			ball.style.top = getOffsetTop(collect) + "px";
		}, 0);
		const endTimeout = setTimeout(() => {
			ball.remove();
		}, top > 400 ? 400 : 600);
		ball.ontransitionend = function() {
			ball.remove();
			clearTimeout(endTimeout);
		};
	}
};
/**
* @title: 递归获取元素距离窗口的位置
* @description:
* @param {any} element
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2023-04-03 15:46
*/
const getOffsetTop = (element) => {
	let offsetTop = element.offsetTop;
	if (element.offsetParent) offsetTop += getOffsetTop(element.offsetParent);
	return offsetTop;
};
//#endregion
export { cubicBezier };
