<!--
 * @Author: ChenChanghua
 * @Date: 2023-03-09 16:28:25
 * @Description: file content
-->
<script setup>
import { ref, shallowRef } from "vue";

const props = defineProps({
  data: Object,
  query: Object,
  onAction: Object,
});

const divRef = shallowRef(null);
const focused = ref(false);

// 自身的焦点状态自己记录, 通过回调来改变
const onFocus = () => {
  focused.value = true;
};
const onBlur = () => {
  focused.value = false;
};
const onClick = () => {
  console.log("item onclick ", props.data);
};

// 一般在create的时候进行回调的注册, 使用 option api的可以在created时进行注册
props.onAction.register("onFocus", onFocus);
props.onAction.register("onBlur", onBlur);
props.onAction.register("onClick", onClick);
</script>

<template>
  <div
    :style="{
      width: data.width,
      height: data.height,
      transform: focused ? 'scale3d(1.2, 1.2, 1.2)' : '',
      transition: 'transform 0.2s linear',
    }"
  >
    <div
      v-if="focused"
      :style="{
        left: -2,
        top: -2,
        width: data.width + 4,
        height: data.height + 4,
        backgroundColor: '#FF0000',
      }"
    ></div>
    <div
      ref="divRef"
      :style="{
        width: data.width,
        height: data.height,
        fontSize: 30,
        color: '#FFFFFF',
        backgroundColor: data.color,
      }"
    >
      {{ data.content }}
    </div>
  </div>
</template>