<!-- 页面  -->
<template>
  <su-popup
    :show="state.show"
    type="center"
    round="10"
    @close="state.show = false"
    :isMaskClick="false"
    maskBackgroundColor="rgba(0, 0, 0, 0.7)"
  >
    <view class="notice-box">
      <view class="img-wrap">
        <image
          class="notice-img"
          :src="sheep.$url.static(state.event.image)"
          mode="aspectFill"
        ></image>
      </view>
      <view class="notice-title">{{ state.event.title }}</view>
      <view class="notice-detail">{{ state.event.subtitle }}</view>
      <button
        class="ss-reset-button notice-btn ui-Shadow-Main ui-BG-Main-Gradient"
        @tap="onTap(state.event.action)"
      >
        {{ state.event.button }}
      </button>
      <button class="ss-reset-button back-btn" @tap="sheep.$router.back()"> {{$t('common.back')}}</button>
    </view>
  </su-popup>
</template>

<script setup>
  import sheep from '@/sheep';
  import { reactive, watch } from 'vue';

  const props = defineProps({
    error: {
      type: Number,
      default: 0,
    },
  });
  const emits = defineEmits(['getAgentInfo']);
  const state = reactive({
    event: {},
    show: false,
  });

  watch(
    () => props.error,
    (error) => {
      if (error !== 0 && error !== 100) {
        state.event = eventMap[error];
        state.show = true;
      }
    },
  );

  async function onTap(eventName) {
    switch (eventName) {
      case 'back': // 返回
        sheep.$router.back();
        break;
      case 'apply': // 需提交资料
        sheep.$router.go('/pages/commission/apply');
        break;
      case 'reApply': // 直接重新申请
        let { error } = await sheep.$api.commission.apply();
        if (code === 1) {
          emits('getAgentInfo');
        }
        break;
    }
  }
  const eventMap = {
    // 关闭
    101: {
      image: '/assets/addons/shopro/uniapp/commission/close.png',
      title: uni.getLocale() == 'en' ? 'The distribution center is closed' : '分销中心已关闭',
      subtitle: uni.getLocale() == 'en' ? 'This function is temporarily unavailable' : '该功能暂不可用',
      button: uni.getLocale() == 'en' ? 'OK' : '知道了',
      action: 'back',
    },
    // 禁用
    102: {
      image: '/assets/addons/shopro/uniapp/commission/forbidden.png',
      title: uni.getLocale() == 'en' ? 'This function is temporarily unavailable' : '账户已被禁用',
      subtitle: uni.getLocale() == 'en' ? 'OK' : '该功能暂不可用',
      button: uni.getLocale() == 'en' ? 'OK' : '知道了',
      action: 'back',
    },
    // 补充信息
    103: {
      image: '/assets/addons/shopro/uniapp/commission/apply.png',
      title: uni.getLocale() == 'en' ? 'Information to be completed' : '待完善信息',
      subtitle: uni.getLocale() == 'en' ? 'Please add your information and submit it for review' : '请补充您的信息后提交审核',
      button: uni.getLocale() == 'en' ? 'OK' : '知道了',
      action: 'apply',
    },
    // 审核中
    104: {
      image: '/assets/addons/shopro/uniapp/commission/pending.png',
      title: uni.getLocale() == 'en' ? 'Under review' : '正在审核中',
      subtitle: uni.getLocale() == 'en' ? 'Please wait patiently for the result' : '请耐心等候结果',
      button: uni.getLocale() == 'en' ? 'OK' : '知道了',
      action: 'back',
    },
    // 重新提交
    105: {
      image: '/assets/addons/shopro/uniapp/commission/reject.png',
      title: uni.getLocale() == 'en' ? 'Sorry! Your application information did not pass' : '抱歉!您的申请信息未通过',
      subtitle: uni.getLocale() == 'en' ? 'Please try to modify and resubmit' : '请尝试修改后重新提交',
      button: uni.getLocale() == 'en' ? 'resubmit' : '重新提交',
      action: 'apply',
    },
    // 直接重新申请
    106: {
      image: '/assets/addons/shopro/uniapp/commission/reject.png',
      title: uni.getLocale() == 'en' ? 'Sorry! Your application information did not pass' : '抱歉!您的申请信息未通过',
      subtitle: uni.getLocale() == 'en' ? 'Please try to apply again' : '请尝试重新申请',
      button: uni.getLocale() == 'en' ? 'Reapply' : '重新申请',
      action: 'reApply',
    },
    // 冻结
    107: {
      image: '/assets/addons/shopro/uniapp/commission/freeze.png',
      title: uni.getLocale() == 'en' ? 'Sorry! Your account has been frozen' : '抱歉!您的账户已被冻结',
      subtitle: uni.getLocale() == 'en' ? 'If you have any questions, please contact customer service' : '如有疑问请联系客服',
      button: uni.getLocale() == 'en' ? 'contact service' : '联系客服',
      action: 'chat',
    },
  };
</script>

<style lang="scss" scoped>
  .notice-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    width: 612rpx;
    min-height: 658rpx;
    background: #ffffff;
    padding: 30rpx;
    border-radius: 20rpx;
    .img-wrap {
      margin-bottom: 50rpx;
      .notice-img {
        width: 180rpx;
        height: 170rpx;
      }
    }
    .notice-title {
      font-size: 35rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 28rpx;
    }
    .notice-detail {
      font-size: 28rpx;
      font-weight: 400;
      color: #999999;
      line-height: 36rpx;
      margin-bottom: 50rpx;
    }
    .notice-btn {
      width: 492rpx;
      line-height: 70rpx;
      border-radius: 35rpx;
      font-size: 28rpx;
      font-weight: 500;
      color: #ffffff;
      margin-bottom: 10rpx;
    }
    .back-btn {
      width: 492rpx;
      line-height: 70rpx;
      font-size: 28rpx;
      font-weight: 500;
      color: var(--ui-BG-Main-gradient);
      background: none;
    }
  }
</style>
