<template>
  <div class="verify-content" v-loading="loading">
    <slide-verify
      ref="block"
      v-bind="props.slideVerifyOptions"
      slider-text="拖动滑块来填充拼图"
      @again="onAgain"
      @imageLoad="imageLoad"
      @success="onSuccess"
      @fail="onFail"
    ></slide-verify>
    <div class="verify-content-action">
      <span class="verify-content-action__refresh" @click="refresh">
        <img :src="Refresh" />
        <span>{{ '刷新' }}</span>
      </span>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue';
import SlideVerify from './vue3-slide-verify';
import Refresh from '@/assets/images/refresh.png';
import './vue3-slide-verify/style.css';

const props = defineProps({
  slideVerifyOptions: {
    type: Object,
    default: () => {}
  }
});

const emits = defineEmits(['onSuccess', 'onFail']);
const loading = ref(true);

const block = ref();

const onSuccess = () => {
  emits('onSuccess');
};

const refresh = () => {
  loading.value = true;
  block.value?.refresh();
};

const imageLoad = () => {
  loading.value = false;
};

const onFail = () => {
  loading.value = true;
  block.value?.refresh();
  emits('onFail');
};

const onAgain = () => {
  // 刷新
  loading.value = true;
  block.value?.refresh();
};
</script>
<style lang="scss" scoped>
.verify-content {
  position: relative;
  height: 100%;

  :deep(.slide-verify) {
    canvas {
      border-radius: 20px;
    }

    .slide-verify-slider {
      border-radius: 25px;
      height: 50px;
      line-height: 50px;
      box-sizing: content-box;
    }

    .slide-verify-slider-mask {
      width: 50px;
      height: 50px;
      border-radius: 25px;
      background-color: var(--promotion--color-primary);
      border-color: transparent;
    }

    .slide-verify-slider-mask-item {
      width: 50px;
      height: 50px;
      border-radius: 100%;

      &:hover {
        background: #fff;

        .iconfont {
          color: #303030;
        }
      }
    }

    .slide-verify-slider-text {
      color: #666;
    }

    .container-success {
      .slide-verify-slider-mask-item {
        background-color: var(--promotion--color-primary) !important;

        .iconfont {
          color: #fff;
        }
      }
    }
  }

  &-action {
    height: 30px;
    margin-top: 20px;
    &__refresh {
      display: flex;
      // justify-content: center;
      align-items: center;
      cursor: pointer;
      img {
        width: 20px;
        margin-right: 5px;
      }

      span {
        font-weight: bold;
      }
    }
  }
}
</style>
