<template>
  <div class="step2">
    <AResult v-if="props.pushEnterprise?.status == PushAuditStatus.REJECTED"
             status="error"
             title="审核位通过"
             sub-title="请检查并修改以下信息，然后再重新提交。"
    >
      <template #extra>
        <a-button type="primary"
                  @click="handleSubmit"
        >返回到填写企业信息</a-button>
      </template>
    </AResult>
    <AResult v-else
             title="等待审核"
             sub-title="预计客服在一个小时内完成"
    >
      <template #icon>
        <SmileOutlined/>
      </template>
      <template #extra>
        <a-button type="primary"
                  @click="handleSubmit"
        >撤回审核</a-button>
      </template>
    </AResult>
  </div>
</template>
<script lang="ts" setup>
  import { Result } from 'ant-design-vue';
  import { updatePushEnterpriseAuditStatus } from '/@/api/platform/common/controller/pushEnterprise';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { SmileOutlined } from '@ant-design/icons-vue';
  import type { PushEnterprise } from '/@/api/platform/common/entity/pushEnterprise';
  import { PushAuditStatus } from '/@/enums/pushEnum';

  const AResult = Result;
  const { createConfirm } = useMessage();
  const emit = defineEmits(['previous']);
  const props = defineProps({
    pushEnterprise: {
      type: Object as PropType<PushEnterprise>,
      default: () => ({})
    }
  });

  async function handleSubmit() {
    const contentText = props.pushEnterprise?.status == PushAuditStatus.UNDER_REVIEW
        ? '是否确认撤销审核?'
        : '是否确认返回到填写企业信息?';
    createConfirm({
      iconType: 'warning',
      title: '温馨提醒',
      content: contentText,
      onOk: async () => {
        await updatePushEnterpriseAuditStatus(PushAuditStatus.NOT_APPLIED);
        emit('previous');
      }
    });
  }
</script>
<style lang="less" scoped>
  .step2 {
    width: 450px;
    margin: 0 auto;
  }
</style>
