<template>
  <div class="imagebox" :style="styleColor"  @click="handleClick" >
    <img
      :class="transStyle.startRotate ? 'startImg' : ''"
      :style="imgStyle"
      :src="imgStyle.imageAdress"
      alt=""
    />
  </div>
</template>
<script>
export default {
  name: "WidgetImage",
  components: {},
  props: {
    value: Object,
    ispreview: Boolean
  },
  data() {
    return {
      options: {},
      optionsSetup:{}
    };
  },
  computed: {
    transStyle() {
      return this.objToOne(this.options);
    },
    styleColor() {
      return {
        position: this.ispreview ? "absolute" : "static",
        background: this.transStyle.background,
        "text-align": this.transStyle.textAlign,
        width: this.transStyle.width + "px",
        height: this.transStyle.height + "px",
        left: this.transStyle.left + "px",
        top: this.transStyle.top + "px",
        right: this.transStyle.right + "px"
      };
    },
    imgStyle() {
      return {
        imageAdress: this.transStyle.imageAdress,
        "border-radius": this.transStyle.borderRadius + "px",
        opacity: this.transStyle.transparency / 100,
        animation: this.transStyle.startRotate? "turn "+(101-this.transStyle.rotationSpeed)/10+"s linear infinite":"none"
      };
    }
  },
  watch: {
    value: {
      handler(val) {
        this.options = val;
        this.optionsSetup = val.setup;
      },
      deep: true
    }
  },
  created() {
    this.options = this.value;
     this.optionsSetup = this.value.setup;
  },
  mounted() {

  },
  methods: {
    handleClick(){
      console.log(this.optionsSetup)
      if(!!this.optionsSetup.is_drill_drown){
        this.$emit('oepnTheDrillView',this.optionsSetup.drill_drown_setting)
      }
    },
  }
};
</script>

<style scoped lang="scss">
.imagebox {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.imagebox img {
  width: 100%;
  height: 100%;
}
.startImg {
  animation: turn 1s linear infinite;
}

</style>
