<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { getToolsCount } from '@/api/home/main'

const emit = defineEmits<{
  (e: 'reject', params: any)
  (e: 'viewrepeat')
}>()

const show = ref(false)
const toolsData = ref({} as any)

async function getData() {
  const res = await getToolsCount()
  toolsData.value = res.data || {}
  if (res.code == 'OK')
    showModal()
}
onMounted(() => {
  getData()
})

function showModal() {
  show.value = true
}

function closeModal() {
  show.value = false
}

async function reject() {
  emit('reject', { a: 'todo' })
  closeModal()
}

async function viewRepeat(e: MouseEvent) {
  emit('viewrepeat')
  e.preventDefault()
  closeModal()
}

defineExpose({
  showModal,
  closeModal,
})
</script>

<template>
  <n-modal v-model:show="show" transform-origin="center" class="modal_wrap">
    <div class="wrapper">
      <div class="wrapper-hearder">
        <div class="wrapper-title">
          欢迎登录智能AI审批工具
        </div>
        <div class="wrapper-mark">
          某某有限公司-某某事业部-张小凡
        </div>
      </div>
      <div class="wrapper-content">
        <div class="flex_box">
          <div class="item">
            <SvgIcon name="task_count" width="48" height="48" />
            <div class="num_box">
              {{ toolsData?.total || 0 }}
            </div>
            <div class="title_box">
              任务总数
            </div>
          </div>
          <div class="item">
            <SvgIcon name="task_wait" width="48" height="48" />
            <div class="num_box">
              {{ toolsData?.treat || 0 }}
            </div>
            <div class="title_box">
              待审批
            </div>
          </div>
          <div class="item">
            <SvgIcon name="task_over" width="48" height="48" />
            <div class="num_box">
              {{ toolsData?.approvedCount || 0 }}
            </div>
            <div class="title_box">
              已审批
            </div>
          </div>
          <div class="item">
            <SvgIcon name="modal_reImg" width="48" height="48" />
            <div class="num_box">
              {{ toolsData?.repeat }}
            </div>
            <div class="title_box">
              重复图片
            </div>
          </div>
        </div>
        <div class="footer" @click="viewRepeat">
          我知道了
        </div>
        <!-- <div class="footer">
          <SvgIcon
            @click="viewRepeat"
            style="cursor: pointer"
            name="login_r"
            width="167"
            height="60"
          />
        </div> -->
      </div>
    </div>
  </n-modal>
</template>

<style lang="less" scoped>
.modal_wrap {
  background-image: url(../../../../assets/images/approval_modal_bg.png);
  background-repeat: no-repeat;
  background-size: 100%;
  width: 510px;
  height: 361px;
  box-shadow: none !important;
  margin-left: 30px !important;
}
.wrapper {
  position: absolute;
  left: calc(50% - 286px);
  .wrapper-hearder {
    margin-top: 80px;
    margin-left: 18px;
    .wrapper-title {
      text-align: center;
      font-size: 16px;
      font-family: PingFang SC, PingFang SC-Semibold;
      font-weight: 850;
      text-align: center;
      color: #333333;
      line-height: 22px;
    }
    .wrapper-mark {
      font-size: 13px;
      font-family: HarmonyOS Sans SC, HarmonyOS Sans SC-Regular;
      font-weight: 550;
      text-align: center;
      color: #666666;
      line-height: 18px;
      margin-top: 8px;
    }
  }
  .wrapper-content {
    flex: 1;
    border-radius: 8px;
    margin: 24px 50px 16px 48px;
    .flex_box {
      display: flex;
      flex-flow: row nowrap;
      align-items: center;
      justify-content: space-between;
      margin: 58.5px 0 0 20px;
      .item {
        .num_box {
          font-size: 20px;
          font-family: HarmonyOS Sans SC, HarmonyOS Sans SC-Bold;
          font-weight: bold;
          text-align: center;
          color: #202020;
          line-height: 23px;
        }
        .title_box {
          opacity: 0.6;
          font-size: 12px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: Regular;
          text-align: center;
          color: #202020;
          line-height: 16px;
          margin-top: 6px;
        }
      }
    }

    .imgwrapper {
      width: 200px;
      height: 120px;
      margin-right: 20px;
      border-radius: 8px;
      background-image: url("../../../assets/images/test.png");
      background-repeat: no-repeat;
      background-size: cover;
    }
    .content {
      .task_id {
        font-size: 14px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: Regular;
        text-align: left;
        color: #333333;
        line-height: 20px;
      }
      .tag_box {
        display: flex;
        flex-flow: row nowrap;
        margin: 8px 0;
        .tag_item {
          background: rgba(80, 122, 253, 0.1);
          border-radius: 2px;
          font-size: 12px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: Regular;
          text-align: left;
          color: #507afd;
          line-height: 16px;
          margin-right: 10px;
        }
      }
      .time_box {
        font-size: 14px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: Regular;
        text-align: left;
        color: #333333;
        line-height: 20px;
      }
    }
    .footer {
      width: 153px;
      height: 46px;
      background: linear-gradient(135deg, #3258e8, #786efc);
      border: 1px solid;
      border-image: linear-gradient(123deg, #d7dffe 2%, #d7d5ff 88%) 1 1;
      border-radius: 24px;
      box-shadow: 0px 2px 6px 0px rgba(116, 153, 253, 0.3);
      cursor: pointer;

      margin: 20px auto 0;
      position: relative;
      bottom: -35px;
      left: 20px;

      font-size: 22px;
      font-weight: 550;
      font-family: YouSheBiaoTiHei, YouSheBiaoTiHei-Regular;
      text-align: center;
      color: #ffffff;
      line-height: 46px;

      border: none;
      font-style: italic;
    }
    // .footer {
    //   display: flex;
    //   flex-flow: row nowrap;
    //   align-items: center;
    //   justify-content: center;
    //   margin: 20px 30px 0 0;
    //   position: relative;
    //   bottom: -30px;
    //   left: 20px;
    // }
  }
}
</style>
