import { Node } from "@topology/core";
//node动态
export const animateType = [
    { name: "无", type: 0 },
    { name: "上下跳动", type: "upDown" },
    { name: "左右跳动", type: "leftRight" },
    { name: "心跳", type: "heart" },
    { name: "成功", type: "success" },
    { name: "警告", type: "warning" },
    { name: "错误", type: "error" },
    { name: "炫耀", type: "show" }
]
export const iconAlineType=[
    { name: "居中", type: "center" },
    { name: "上", type: "top" },
    { name: "下", type: "bottom" },
    { name: "左", type: "left" },
    { name: "右", type: "right" },
    { name: "左上", type: "left-top" },
    { name: "右上", type: "right-top" },
    { name: "左下", type: "left-bottom" },
    { name: "右下", type: "right-bottom" },
]
export function setAnimate(node) {
    if (node.animateType === '') {
        return;
    }
    
    const state = Node.cloneState(node);
    switch (node.animateType) {
        case 'upDown':
            state.rect.y -= 10;
            state.rect.ey -= 10;
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(node)

            });
            node.animateFrames.push({
                duration: 200,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            break;
        case 'leftRight':
            state.rect.x -= 10;
            state.rect.ex -= 10;
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            state.rect.x += 20;
            state.rect.ex += 20;
            node.animateFrames.push({
                duration: 80,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            state.rect.x -= 20;
            state.rect.ex -= 20;
            node.animateFrames.push({
                duration: 50,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)

            });
            state.rect.x += 20;
            state.rect.ex += 20;
            node.animateFrames.push({
                duration: 30,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            node.animateFrames.push({
                duration: 300,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(node)
            });
            break;
        case 'heart':
            state.rect.x -= 5;
            state.rect.ex += 5;
            state.rect.y -= 5;
            state.rect.ey += 5;
            state.rect.width += 5;
            state.rect.height += 10;
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            node.animateFrames.push({
                duration: 400,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(node)
            });
            break;
        case 'success':
            state.strokeStyle = '#237804';
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(node)
            });
            state.strokeStyle = '#237804';
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(node)
            });
            state.strokeStyle = '#237804';
            state.fillStyle = '#389e0d22';
            node.animateFrames.push({
                duration: 3000,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            break;
        case 'warning':
            state.strokeStyle = '#fa8c16';
            state.dash = 2;
            node.animateFrames.push({
                duration: 300,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            state.strokeStyle = '#fa8c16';
            state.dash = 0;
            node.animateFrames.push({
                duration: 500,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            state.strokeStyle = '#fa8c16';
            state.dash = 2;
            node.animateFrames.push({
                duration: 300,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            break;
        case 'error':
            state.strokeStyle = '#cf1322';
            state.fillStyle = '#cf132222';
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state
            });
            break;
        case 'show':
            state.strokeStyle = '#fa541c';
            state.rotate = -10;
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            state.rotate = 10;
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            state.rotate = 0;
            node.animateFrames.push({
                duration: 100,
                linear: true,
                initState: Node.cloneState(node),
                state: Node.cloneState(state)
            });
            break;
    }
}