<!--
 * @Author: ChenChanghua
 * @Date: 2023-03-08 14:52:17
 * @Description: file content
-->
<script setup>
import { ref } from "vue";
import { EdgeDirection } from "jsview";

const props = defineProps({
  data: Object,
  onAction: Object,
  anim: Object,
});
const bgImage = "https://cdn.release.qcast.cn/JsViewFrameworkTester/JsViewVueSampleResources/DemoForOperator/PosterAnim/Shake/Item/background.png";

const focused = ref(false);
const animation = ref(null);

// 注册回调
const onFocus = () => {
  focused.value = true;
};
const onBlur = () => {
  focused.value = false;
};
const onClick = () => {};

const onAnimEnd = () => {
  animation.value = null;
};

const onWidgetEdge = (info) => {
  switch (info.direction) {
    case EdgeDirection.left:
      animation.value = `${props.anim.left.name} 0.15s`;
      break;
    case EdgeDirection.top:
      animation.value = `${props.anim.top.name} 0.15s`;
      break;
    case EdgeDirection.right:
      animation.value = `${props.anim.right.name} 0.15s`;
      break;
  }
};

props.onAction.register("onFocus", onFocus);
props.onAction.register("onBlur", onBlur);
props.onAction.register("onClick", onClick);
props.onAction.register("onWidgetEdge", onWidgetEdge);
</script>

<template>
  <div
    :style="{
      width: data.width,
      height: data.height,
      transition: 'transform 0.2s',
      transform: focused ? 'scale3d(1.05, 1.05, 1)' : null,
    }"
  >
    <div
      :style="{
        width: data.width,
        height: data.height,
        animation: animation,
      }"
      @animationend="onAnimEnd"
    >
      <div
        :style="{
          width: data.width,
          height: data.height,
          fontSize: 30,
          color: focused ? '#FF0000' : '#FFFFFF',
          backgroundImage: bgImage,
          lineHeight: data.height,
          textAlign: 'center',
        }"
      >
        边缘晃动
      </div>
    </div>
  </div>
</template>
